Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

resource_configuration confusion when updating to TF 0.12 #28

Closed
mcascone opened this issue Aug 26, 2019 · 6 comments
Closed

resource_configuration confusion when updating to TF 0.12 #28

mcascone opened this issue Aug 26, 2019 · 6 comments

Comments

@mcascone
Copy link

mcascone commented Aug 26, 2019

vRA 7.x version
vRA 7.0.1
Terraform version

Terraform v0.12.7
+ provider.vra7 v0.4.1

Describe the bug
after upgrade to TF v0.12, my resource_configuration block fails:

  resource_configuration = {
    vSphere_Machine_1.name        = ""
    vSphere_Machine_1.ip_address  = ""
    vSphere_Machine_1.description = "Terraform Machine ${count.index + 1}"
  }
> terraform validate
Error: Reference to undeclared resource

  on main.tf line 26, in resource "vra7_deployment" "TF-Deploy":
  26:     vSphere_Machine_1.description = "Terraform Machine ${count.index + 1}"

A managed resource "vSphere_Machine_1" "description" has not been declared in
the root module.

This happens for all three parameters in the block.

To Reproduce
Steps to reproduce the behavior:

  1. Terraform config file
  2. Terraform command
  3. Error

Expected behavior
resource_configuration should pass validation.

Screenshots
If applicable, add screenshots to help explain your problem.

Logs
Attach logs to help debug the issue

  1. Attach vra-terraform.log
  2. Attach Terraform console log (Enable terraform logs following the steps mentioned in https://www.terraform.io/docs/configuration/environment-variables.html)
  3. crash.log(if any)

Desktop (please complete the following information):

  • OS: [e.g. iOS]

Additional context
This works fine under TF v0.11. The v0.12upgrade helper script updated the resource_configuration block to add the = :

 resource_configuration = {
    vSphere_Machine_1.name        = ""
    vSphere_Machine_1.ip_address  = ""
    vSphere_Machine_1.description = "Terraform Machine ${count.index + 1}"
  }

but then gets the error shown above.
Removing the = doesn't work. I tried putting the left-side parameters in quotes, but that causes other problems, i don't think that's the issue.

@hobovirtual
Copy link

Hi @mcascone

With version 0.12 and the latest provider you need to change your declaration, have you tried the following?

resource_configuration = {
    "vSphere_Machine_1.name"        = ""
    "vSphere_Machine_1.ip_address"  = ""
    "vSphere_Machine_1.description" = "Terraform Machine ${count.index + 1}"
  }

The readme has been updated with these change, let us know if it works after the modification!
Same thing applies to all configuration section.

Thanks!

@mcascone
Copy link
Author

As I mentioned, I tried that, and it does fix that specific problem. But right below that in the config, I need to pass the ip_address to the provisioner, and it doesn't exist yet:

provisioner "chef" {
    # This is for TF to talk to the new node
    connection {
      host = "${self.resource_configuration.vSphere_Machine_1.ip_address}"
> terraform validate

on main.tf line 32, in resource "vra7_deployment" "TF-Deploy":
  32:       host = "${self.resource_configuration.vSphere_Machine_1.ip_address}"

This value does not have any attributes.

Same thing if i change to using the name:

 provisioner "chef" {
    # This is for TF to talk to the new node
    connection {
      host = "${self.resource_configuration.vSphere_Machine_1.name}"
> terraform validate

Error: Unsupported attribute

  on main.tf line 32, in resource "vra7_deployment" "TF-Deploy":
  32:       host = "${self.resource_configuration.vSphere_Machine_1.name}"

This value does not have any attributes.

@hobovirtual
Copy link

Sorry missed that part, here's something that works for me, maybe this could help, in my case a simple echo

provider "vra7" {
  username = "${var.vra_username}"
  password = "${var.vra_password}"
  tenant   = "${var.vra_tenant}"
  host     = "${var.vra_host}"
  insecure = true
}

resource "vra7_deployment" "deployment1" {
  catalog_item_name = "centOS 7"

  resource_configuration = {
    "vm1._cluster" = "1"
    "vm1.cpu" = "2"
    "vm1.memory" = "4096"
    "vm1.description" = "Component Description here"
    "vm1.VirtualMachine.Disk1.Size" = "5"
    "vm1.ip_address" = ""
    "vm1.name" = ""
  }

  //deployment section
  deployment_configuration = {
    "reasons"      = "Some Reasons"
    "description"  = "Deployment Description here"
    "_leaseDays" = "5"
    "_number_of_instances" = "1"
  }
}

output "vm1 IP" {
  value = "${vra7_deployment.deployment1.resource_configuration.vm1.ip_address}"
}

output "vm1 Name" {
  value = "${vra7_deployment.deployment1.resource_configuration.vm1.name}"
}

@mcascone
Copy link
Author

mcascone commented Aug 27, 2019

Thanks @hobovirtual, but this doesn't pass validation for me:

output "Machine_Names" {
  value = "${vra7_deployment.TF-Deploy.resource_configuration.vSphere_Machine_1.ip_address}"
}

I am trying to use the ip (or name) in a chef provisioner, and there doesn't seem to be a way to access it:

host = "${self.resource_configuration.vSphere_Machine_1.ip_address}"

gives the This value does not have any attributes. error.

@mcascone
Copy link
Author

also... I noticed that your output has a space in the name: output "vm1 IP"
When i validate using TF 0.12, it complains about the space in the name, that's why i have the underscore in mine... are you 100% sure you're not running 0.11?

@mcascone
Copy link
Author

mcascone commented Aug 27, 2019

I'm sorry... i've got it... from this very repo: https://github.com/terraform-providers/terraform-provider-vra7/blob/master/example/remote-execute/main.tf:

connection {
   host     = self.resource_configuration["Machine.ip_address"]

And this took me QUITE a few variations to land on, but this is how I can access the elements of that block:

output "Machine_IPs" {
  value = vra7_deployment.TF-Deploy[*].resource_configuration["vSphere_Machine_1.ip_address"]
}

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

No branches or pull requests

2 participants