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

Terraform Unable to use Provisioners in VM Resource when DHCP is used for IP Address #49

Closed
mc-jared opened this issue Apr 12, 2019 · 7 comments

Comments

@mc-jared
Copy link

mc-jared commented Apr 12, 2019

Describe the bug
The Nutanix Provider is not able to establish a connection to VM's it has created due to lacking the IP address of the Host it has just created if not provided, this prevents using DHCP for IP provisioning.

Expected behavior
The Nutanix Provider should allow the provisioners of remote-exe | file to establish connections on VM's it has just created using DHCP for IP provisioning
These provisioners would use a connection to connect to the VM's and then do what they should, copy a file | run a command | etc.

Logs
With the following inline code inside the: nutanix_virtual_machine object
connection {
type = "winrm"
user = "${var.admin_uid}"
password = "${var.admin_cid}"
}
provisioner "file" {
when = "create"
content = "test.txt"
destination = "C:\test.txt"
}
provisioner "remote-exec" {
when = "create"
inline = [
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Write-Host Hello"
]
}

You get the following output until a timeout is reached:
For a remote-exec provisioner:
nutanix_virtual_machine.DB (remote-exec): Connecting to remote host via WinRM...
nutanix_virtual_machine.DB (remote-exec): Host:
nutanix_virtual_machine.DB (remote-exec): Port: 5985
nutanix_virtual_machine.DB (remote-exec): User: Administrator
nutanix_virtual_machine.DB (remote-exec): Password: true
nutanix_virtual_machine.DB (remote-exec): HTTPS: false
nutanix_virtual_machine.DB (remote-exec): Insecure: false
nutanix_virtual_machine.DB (remote-exec): NTLM: false
nutanix_virtual_machine.DB (remote-exec): CACert: false

For a File Provisioner:
nutanix_virtual_machine.DB: Provisioning with 'file'...
nutanix_virtual_machine.DB: Still creating... (20s elapsed)
nutanix_virtual_machine.DB: Still creating... (30s elapsed)
nutanix_virtual_machine.DB: Still creating... (40s elapsed)
nutanix_virtual_machine.DB: Still creating... (50s elapsed)

Versions (please complete the following information):

  • OS that is executing Terraform: Windows
  • Nutanix Prism Central: 5.10.11
  • Terraform provider version v11.13

Additional context
This is most likely related to Issue #19 but is not specific to the provisioners

@cgrout
Copy link

cgrout commented Aug 9, 2019

Try passing it the proper 'host' attribute from the generated VM reference. I know this works w/ SSH, and no reason to assume winrm would be any different.

connection {
type = "winrm"
user = "${var.admin_uid}"
password = "${var.admin_cid}"
host = "${nutanix_virtual_machine.DB.nic_list_status.0.ip_endpoint_list.0.ip}"
}

@marinsalinas
Copy link
Contributor

Hello @jjamesmastercontrol did this work for you?

Try passing it the proper 'host' attribute from the generated VM reference. I know this works w/ SSH, and no reason to assume winrm would be any different.

connection {
type = "winrm"
user = "${var.admin_uid}"
password = "${var.admin_cid}"
host = "${nutanix_virtual_machine.DB.nic_list_status.0.ip_endpoint_list.0.ip}"
}

@coderGo93
Copy link
Contributor

Hello @jjamesmastercontrol , I'd like to know if still an issue or its working now on branch master?

@coderGo93
Copy link
Contributor

Hello @jjamesmastercontrol , do you have an example of config file without sensitive data so I can test it and replicate behaviour like yours, please?

@coderGo93
Copy link
Contributor

Hello @jjamesmastercontrol , I just tested and it works for me it created a file test.txt and printed the Hello with powershell, could you confirm it if it's working for you and this issue can be closed?.
This is the config I used to test

data "nutanix_clusters" "clusters" {}

locals {
  vmname_prefix = "test-issue49"
	cluster1 = [
		for cluster in data.nutanix_clusters.clusters.entities :
		cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
	][0]
  vm_username = "Administrator"
  image_name    = "windows_2016"
  image_name_virtio    = "Virt IO"
}

data "template_file" "unattend" {
  template = "${file("unattend.xml")}"
  vars = {
    vmname_prefix = local.vmname_prefix
    index         = 1
  	vm_username = local.vm_username
    vm_password   = var.vm_password
  }
}


data "nutanix_subnet" "subnet" {
  subnet_name = "Rx-Automation-Network"
}

data "nutanix_image" "windows" {
  	image_name = local.image_name
}

data "nutanix_image" "virtio" {
  	image_name = local.image_name_virtio
}


resource "nutanix_virtual_machine" "vm" {
  	name                 = "${local.vmname_prefix}-1"
	cluster_uuid         = local.cluster1
	num_vcpus_per_socket = 1
	num_sockets          = 2
	memory_size_mib      = 2048

	nic_list {
		subnet_uuid = data.nutanix_subnet.subnet.id
	}

	guest_customization_sysprep = {
		install_type = "PREPARED"
		unattend_xml = base64encode(data.template_file.unattend.rendered)
	}

	disk_list {
		data_source_reference = {
			kind = "image"
			uuid = data.nutanix_image.windows.id
		}
	}
	connection {
		type     = "winrm"
		user     = local.vm_username
		password = var.vm_password
		use_ntlm = true
		insecure = true
		host     = "${nutanix_virtual_machine.vm.nic_list_status.0.ip_endpoint_list.0.ip}"
	}

	provisioner "file" {
		when = "create"
		content = "test.txt"
		destination = "C:\\test.txt"
	}

	provisioner "remote-exec" {
		when = "create"
		inline = [
			"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe Write-Host Hello"
		]
	}
}

@coderGo93
Copy link
Contributor

The response of if its working for me

nutanix_virtual_machine.vm: Creating...
nutanix_virtual_machine.vm: Still creating... [10s elapsed]
nutanix_virtual_machine.vm: Still creating... [20s elapsed]
nutanix_virtual_machine.vm: Still creating... [30s elapsed]
nutanix_virtual_machine.vm: Still creating... [40s elapsed]
nutanix_virtual_machine.vm: Still creating... [50s elapsed]
nutanix_virtual_machine.vm: Still creating... [1m0s elapsed]
nutanix_virtual_machine.vm: Provisioning with 'file'...
nutanix_virtual_machine.vm: Still creating... [1m10s elapsed]
nutanix_virtual_machine.vm: Provisioning with 'remote-exec'...
nutanix_virtual_machine.vm (remote-exec): Connecting to remote host via WinRM...
nutanix_virtual_machine.vm (remote-exec):   Host: x.x.x.x
nutanix_virtual_machine.vm (remote-exec):   Port: 5985
nutanix_virtual_machine.vm (remote-exec):   User: Administrator
nutanix_virtual_machine.vm (remote-exec):   Password: true
nutanix_virtual_machine.vm (remote-exec):   HTTPS: false
nutanix_virtual_machine.vm (remote-exec):   Insecure: true
nutanix_virtual_machine.vm (remote-exec):   NTLM: true
nutanix_virtual_machine.vm (remote-exec):   CACert: false
nutanix_virtual_machine.vm (remote-exec): Connected!
nutanix_virtual_machine.vm: Still creating... [1m20s elapsed]

nutanix_virtual_machine.vm (remote-exec): C:\Users\Administrator>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Write-Host Hello
nutanix_virtual_machine.vm (remote-exec): Hello
nutanix_virtual_machine.vm: Still creating... [1m30s elapsed]
nutanix_virtual_machine.vm: Creation complete after 1m33s [id=e62e88f2-b993-4fdc-8120-830abbc179a5]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

@coderGo93
Copy link
Contributor

Closed for lack of the response from the issue, it's been tested with similar config I shared and not erros has been presented.

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

No branches or pull requests

4 participants