Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build does not go through #156

Open
eliassal opened this issue Oct 9, 2022 · 17 comments
Open

Build does not go through #156

eliassal opened this issue Oct 9, 2022 · 17 comments

Comments

@eliassal
Copy link

eliassal commented Oct 9, 2022

Hi there,

I am following the "Building The Provider", tried on a win machine a swell as fedora, when I run "build make", I get

make: *** No rule to make target 'build'. Stop.

Is there any release that I can download?

Thanbks for your help

@MarkusRannare
Copy link
Contributor

MarkusRannare commented Nov 22, 2022

There is a release here:
https://github.com/taliesins/terraform-provider-hyperv/releases/tag/v1.0.3

If you want to build the provider, you can just do a
go build && go install .

I have generally used the provider by just adding:

terraform {
  required_providers {
    hyperv = {
      source  = "taliesins/hyperv"
      version = "1.0.3"
    }
  }
}

to my .tf-file

@eliassal
Copy link
Author

Thanks Markus, sorry for my late response. If I understand well, I don't need to download anything to my dev box, just add the snippet in the tf file? am I correct?

@MarkusRannare
Copy link
Contributor

No problem!

You don't need to download the source on your dev box unless you want to run the latest version. You just need to stick the snippet I pasted at top of your terraform file and it will download the provider from the terraform registry

Tutorials for terraform is available here:
https://developer.hashicorp.com/terraform/tutorials/aws-get-started/aws-build

@eliassal
Copy link
Author

So many thanks Markus for your prompt response. I work in an environment where cloud is not an option, I need to use terraform against local Hyper-V or maybe VMware VMs. Is there any tutorial around this?

@MarkusRannare
Copy link
Contributor

I would recommend checking out the documentation in the terraform registry:
https://registry.terraform.io/providers/taliesins/hyperv/latest/docs
or if you want to go with WMware vSphere, check out: https://registry.terraform.io/modules/Terraform-VMWare-Modules/vm/vsphere/latest

The tutorials I posted was just general Terraform tutorials that can help you understand Terraform and then apply it to use it with any provider. I learned from tutorials targetting AWS as that's what's Terraform is generally used for and then started using this provider

@eliassal
Copy link
Author

Again thanks, I will do but try to play with azure as I have a personal subscription. Then I will try to apply it to Hyper-V environment as it is 90% of the env, only 10% VMware is used

@eliassal
Copy link
Author

Hi Markus, I started playing with the provider, followed all instructions regarding Requirements at the main page, created a main.tf, I run
terraform plan -out=tfplan -var="imagebuild=test"
everything works like a charm and I get tfplan correctly created, I start the command to apply

terraform apply "tfplan"

It starts by indicating

[salam7]: PS C:\Projects\AzureDevOpsProjects\terraform\Test-HyperV> terraform apply "tfplan"
hyperv_vhd.web_server_g2_vhd: Creating...
hyperv_network_switch.dmz_network_switch: Creating...
hyperv_vhd.web_server_g1_vhd: Creating...
hyperv_network_switch.dmz_network_switch: Still creating... [10s elapsed]
hyperv_vhd.web_server_g1_vhd: Still creating... [10s elapsed]
hyperv_vhd.web_server_g2_vhd: Still creating... [10s elapsed]
hyperv_network_switch.dmz_network_switch: Still creating... [20s elapsed]
hyperv_vhd.web_server_g1_vhd: Still creating... [20s elapsed]
hyperv_vhd.web_server_g2_vhd: Still creating... [20s elapsed]
hyperv_vhd.web_server_g2_vhd: Still creating... [30s elapsed]
hyperv_vhd.web_server_g1_vhd: Still creating... [30s elapsed]
hyperv_network_switch.dmz_network_switch: Still creating... [30s elapsed]

Then, it starts complaining and generating errors

│ Error: run command operation returned
│ stderr:
│ (12,8):UserId:
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2Im6GUha0l9fj172dKFdfLzZT81.ps1:85 char:3
│ + $folder.RegisterTaskDefinition($taskName, $task, 6, $username, $pas ...
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│ + CategoryInfo : OperationStopped: (:) [], ArgumentException
│ + FullyQualifiedErrorId : System.ArgumentException
│
│ The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2Im6GUha0l9fj172dKFdfLzZT81.ps1:86 char:3
│ + $registeredTask = $folder.GetTask("$taskName");
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│ + CategoryInfo : OperationStopped: (:) [], FileNotFoundException
│ + FullyQualifiedErrorId : System.IO.FileNotFoundException
│
│ You cannot call a method on a null-valued expression.
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2Im6GUha0l9fj172dKFdfLzZT81.ps1:87 char:3
│ + $registeredTask.Run($null) | Out-Null;
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│ + CategoryInfo : InvalidOperation: (:) [], RuntimeException
│ + FullyQualifiedErrorId : InvokeMethodOnNull
│ stdOut:
│
│
│ with hyperv_network_switch.dmz_network_switch,
│ on main.tf line 21, in resource "hyperv_network_switch" "dmz_network_switch":
│ 21: resource "hyperv_network_switch" "dmz_network_switch" {
│
╵
â•·
│ Error: run command operation returned
│ stderr:
│ (12,8):UserId:
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2Im6GWohvRcFgIUxpPcu9qUhbtM.ps1:85 char:3
│ + $folder.RegisterTaskDefinition($taskName, $task, 6, $username, $pas ...
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│ + CategoryInfo : OperationStopped: (:) [], ArgumentException
│ + FullyQualifiedErrorId : System.ArgumentException
│
│ The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2Im6GWohvRcFgIUxpPcu9qUhbtM.ps1:86 char:3
│ + $registeredTask = $folder.GetTask("$taskName");
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│ + CategoryInfo : OperationStopped: (:) [], FileNotFoundException
│ + FullyQualifiedErrorId : System.IO.FileNotFoundException
│
│ You cannot call a method on a null-valued expression.
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2Im6GWohvRcFgIUxpPcu9qUhbtM.ps1:87 char:3

In spite of the fact that the files are there (on my box longpathname is enabled in the registry to 1)

image

@taliesins
Copy link
Owner

@eliassal give the new provider https://github.com/taliesins/terraform-provider-hyperv/releases/tag/v1.0.4 a go. It has fixed a number of bugs.

@eliassal
Copy link
Author

Hi, I updated to 1.0.4 but still getting the exact same errors

Error: checking for existing H:\Hyper-V\Vistual Hard Disks\web_server_g2.vhdx: run command operation returned
│ stderr:
│ (12,8):UserId:
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2IwOx787lEl98X8ZT1VrwNaYxT6.ps1:85 char:3
│ + $folder.RegisterTaskDefinition($taskName, $task, 6, $username, $pas ...
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│ + CategoryInfo : OperationStopped: (:) [], ArgumentException
│ + FullyQualifiedErrorId : System.ArgumentException

│ The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2IwOx787lEl98X8ZT1VrwNaYxT6.ps1:86 char:3
│ + $registeredTask = $folder.GetTask("$taskName");
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│ + CategoryInfo : OperationStopped: (:) [], FileNotFoundException
│ + FullyQualifiedErrorId : System.IO.FileNotFoundException

│ You cannot call a method on a null-valued expression.
│ At C:\Users\salam.SALAM\AppData\Local\Temp\elevated-shell-terraform-2IwOx787lEl98X8ZT1VrwNaYxT6.ps1:87 char:3
│ + $registeredTask.Run($null) | Out-Null;
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│ + CategoryInfo : InvalidOperation: (:) [], RuntimeException
│ + FullyQualifiedErrorId : InvokeMethodOnNull
│ stdOut:


│ with hyperv_vhd.web_server_g2_vhd,
│ on main.tf line 63, in resource "hyperv_vhd" "web_server_g2_vhd":
│ 63: resource "hyperv_vhd" "web_server_g2_vhd" {

@eliassal
Copy link
Author

@taliesins , can you tell me please why did you close this thread?

@taliesins
Copy link
Owner

@eliassal it is still open?

Can you post the exact example you are using (delete the password of course) so that I can try to reproduce locally.
Are you running this with the Administrator user or another one?
Are you running this on a machine that is not domain joined? Thinking GPO policies might be causing some problems.

@eliassal
Copy link
Author

Enclosed is the main.tf in a zip file
I log to the machine with my user who is local admin as well as domain admin. I run other terraform files using azure or Aws providers.
It is in my domain in home-office network;
main.zip
no GPO policies

@eliassal
Copy link
Author

hi taliesinsm any feedback please

@taliesins
Copy link
Owner

@eliassal

These are the only changes I made to your file

provider "hyperv" {
  # Configuration options
}


# variable "imagebuild" {
#   type        = string
#   description = "Latest Image Build"
# }

It worked fine for me, so I assume its something to do with the setup on your machine.

image

@eliassal
Copy link
Author

Hi, your response gave me a hint. In fact, my local Hyper-V is in a machine which is part of a domain. The user I was using was missing the domain, I added

provider "hyperv" {
user = "mydomain\myuser"
password = "mypassword"
}

and it went through like a charm. Boh VMs were in running status.

Now, let me ask the following question : how can I trigger the installation of windows server / linux fedora or ubuntu in the main.tf? Do you have any template of examples for achieving this? Also, ig Hyper-V was not local, how can we tell terraform that it is a remote Hyper-V?

So many thanks for your help.

@taliesins
Copy link
Owner

If you want to create a new golden image I would recommend: https://developer.hashicorp.com/packer/plugins/builders/hyperv/iso (I contributed a lot to this one, so it works in a similar way to this Terraform provider) Packer has the functionality to emulate key presses, so if you need to setup a machine from scratch this would be my first choice.

Otherwise you would need to start the vm with a preseed (linux fedora) or unattend.xml (windows) to configure it at startup. It would be way easier to achieve this if #36 was in place.

@eliassal
Copy link
Author

Again thanks the 1st link need sometime to absorb. I visited the 2nd link I dont see any hint of making a data source file pointing to an isom it just init with users what I need is an example of unattended/data resource file with a win lest say 2019 iso image if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants