vmware / terraform-provider-vcd

Terraform VMware Cloud Director provider
https://www.terraform.io/docs/providers/vcd/
Mozilla Public License 2.0
149 stars 111 forks source link

problem with creating vapp_vm with official plugin #165

Closed ghost closed 5 years ago

ghost commented 5 years ago

Sorry for getting back to you that late. But I could not test earlier. Currently I am having the problem that my VM cannot be created anymore.

Terraform v0.11.10

Terraform Version

Terraform v0.11.10

Affected Resource(s)

Please list the resources as a list, for example: vcd_vapp_vm.my_vm00

Terraform Configuration Files

resource "vcd_network_routed" "net00" {
        name = "${var.vcdnet_name}"
        edge_gateway = "${var.vcdnet_edge_gateway}"
        gateway = "${var.vcdnet_gateway}"
                static_ip_pool {
                start_address = "${var.vcdnet_static_ip_pool_start}"
                end_address = "${var.vcdnet_static_ip_pool_end}"
        }
}

resource "vcd_catalog" "MMIG-Test-Catalog" {
name = "${var.mmigcatalogname}"
description = "OS Templates"
delete_force = true
delete_recursive = true
}

resource "vcd_vapp" "mmigvapp00" {
        depends_on = ["vcd_network_routed.net00"]
        name = "${var.vcd_vapp_name}"
        power_on = false
        network_name = "${var.vcdnet_name}"
}

resource "vcd_vapp_vm" "my_vm00" {
        depends_on = ["vcd_vapp.mmigvapp00"]
        vapp_name = "${var.vcd_vapp_name}"
        network_name = "${var.vcdnet_name}"
        power_on = false
        name = "${var.vmnamelinux}"
        catalog_name = "${var.catalognamelinux}"
        template_name = "${var.templatenamelinux}"
        memory = 4096
        cpus = 2
        initscript = <<EOF
#!/bin/bash
touch /root/terraformtest.txt
EOF
}

resource "vcd_catalog_media" "myNewMedia" {
  depends_on = ["vcd_catalog.MMIG-Test-Catalog"]
  catalog = "${var.mmigcatalogname}"

  name                 = "testvm iso"
  description          = "cloud init test"
  media_path           = "/root/iso/seed.iso"
  upload_piece_size    = 10
  show_upload_progress = true
}

resource "vcd_inserted_media" "myInsertedMedia" {
  depends_on  = ["vcd_vapp_vm.my_vm00"]
  catalog = "${var.mmigcatalogname}"
  name = "testvm iso"

  vapp_name = "mmig-vcloud-providers-testspace"
  #vm_name = "cust1_mgmt_vm_lx_1"
  vm_name = "${var.vmnamelinux}"
}

Debug Output

https://gist.github.com/ybaumy/a1fcab843ab3901b2fde871bc9a1a1de

Panic Output

Expected Behavior

VM should have been created but it isn't completely. Then the uploaded ISO file should be attached to the VM

Actual Behavior

That is what i want to know. Am I missing something.

Steps to Reproduce

terraform plan + apply

Important Factoids

I dont know the vCloud Version. Would have to ask.

References

lvirbalas commented 5 years ago

@ybaumy the error says that "error instantiating a new VM: API Error: 400: [ ... ] There is already a VM named \"cust1_mgmt_vm_lx_1\"."}

Are you sure your environment doesn't have any remnants from previous setup (of which the state file has been lost)? Could you try removing everything and starting from empty?

ghost commented 5 years ago

actually that is what i did. rm -f statefile + backup terraform plan terraform init

and I made sure none of the resources were still in the vOrg created.

So it should have been a clean state. That is why I am wondering why this happens.

ghost commented 5 years ago

@lvirbalas i found on the vcd gui an error that is strange.. at least for me.

Recomposed Virtual Application 'mmig-vcloud-providers-testspace' (9ee97503-6089-43a6-930c-72ba801d0ade)

[ b78c21aa-0414-473b-8206-af2e4cb724fd ] Unable to perform this action. Contact your cloud administrator.

This is the error probably why it fails. It just does not say so in the terraform trace output.

vbauzys commented 5 years ago

I think I found the issue, fix on the way.

vbauzys commented 5 years ago

Fix in https://github.com/vmware/go-vcloud-director/pull/150 . When this one will be merged, terraform can be updated too.

ghost commented 5 years ago

@vbauzysvmware Just talked to the vCloud Engineer. He provided me another error message.

`[ b78c21aa-0414-473b-8206-af2e4cb724fd ] The operation is not supported on the object.

So it seems that some API call to the VM is wrong?

vbauzys commented 5 years ago

Yes it is,constructing API call happens one issue, which is solved in PR.

vbauzys commented 5 years ago

Additional note from my investigation: with current configuration vapp creation won't use network name - it will create raw vApp with only name, all other configuration details ignored. Current implementation expects template_name and catalog_name to be provided, and then all other vApp properties will be used.

ghost commented 5 years ago

@vbauzysvmware Ok. But I am using template_name + catalog_name in the resource defintion. So sorry but I do not understand what should be wrong here.

resource "vcd_vapp_vm" "my_vm00" { depends_on = ["vcd_vapp.mmigvapp00"] vapp_name = "${var.vcd_vapp_name}" network_name = "${var.vcdnet_name}" power_on = false name = "${var.vmnamelinux}" catalog_name = "${var.catalognamelinux}" template_name = "${var.templatenamelinux}"

But I can tell you what was wrong in the code. The "ip = x.x.x.x" attribute was missing, since we have to use static_ip_pool and not dhcp.

I rerun the terraform apply and provided an IP address in the vcd_vapp_vm statement block but I am getting the same error.

vbauzys commented 5 years ago

I was talking about vcd_vapp resource. Did you use code from PR I mentioned? Binary update will happen with new release only. In reality it's just one line change in vapp.go

vbauzys commented 5 years ago

Fix come around and in terraform-providers:vmware-stash-while-master-pr-open until merged to master

vbauzys commented 5 years ago

2.1.0 version released with the fix. Let me us know it it's good now :)