Skip to content
New issue

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

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

Already on GitHub? # to your account

Crashing for_each/self regression introduced by #22846 #23194

Closed
isometry opened this issue Oct 26, 2019 · 6 comments · Fixed by #23215
Closed

Crashing for_each/self regression introduced by #22846 #23194

isometry opened this issue Oct 26, 2019 · 6 comments · Fixed by #23215
Labels
bug config crash v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@isometry
Copy link

Terraform Version

Terraform v0.12.12
+ provider.random v2.2.1

Terraform Configuration Files

Trivial test case:

resource "random_pet" "test" {
    for_each = toset(["testcase"])

    provisioner "local-exec" {
        command = "echo pet name is ${self.id}"
    }
}

Debug Output

debug.log

Crash Output

crash.log

Expected Behavior

Terraform completes without crashing: the local-exec provisioner run successfully, printing pet name is ${self.id}.

Actual Behavior

Terraform panics whilst resolving self.id:

panic: not a list, map, or tuple type

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

The above test case is simply the most trivial I've found to reproduce the crash which is easily reproducible with multiple providers, and with increasingly complex for_each loops. Terraform will crash whenever self is referenced within a provisioner. In particular, it has introduced a blocking issue for us with the vsphere.vmware_virtual_machine provider with which we use a for_each = {…} map.

References

@ghost ghost added bug crash labels Oct 26, 2019
@vitobotta
Copy link

Hi @isometry , I'm having the same issue. Have you found a solution?

@isometry
Copy link
Author

Hi @isometry , I'm having the same issue. Have you found a solution?

Unfortunately, I've found no solution: any reference to self within a provisioner causes Terraform to panic when that provisioner is inside a resource using for_each. The only I've found workaround is to downgrade to Terraform 0.12.10.

@vitobotta
Copy link

Hi @isometry, that's what I ended up doing as well. Problem is that my state had been upgraded to a new version with 0.12.12, so 0.12.10 could not use it anymore. This forced me to recreate a cluster with 0.12.10 :( I have just started to use Terraform and this scares me. Luckily I am still setting things up for development only, but what if I had something in production and had this kind of problem? Is there a way for an older version to use the state updated with a newer version? Thanks

@isometry
Copy link
Author

Is there a way for an older version to use the state updated with a newer version?

You can do the following to recover your updated state into a new workspace compatible with the older version:

# Backup the current 0.12.12 state, transforming it to believe it's a 0.12.10 state
terraform_0.12.12 state pull | jq '.terraform_version="0.12.10"' > backup.tfstate
# Create a new workspace named "recovered" to hold the 0.12.10 state
terraform_0.12.10 workspace new recovered
# Restore the backup into the new workspace
terraform_0.12.10 state push backup.tfstate

If you don't have jq, just edit the third line of manual.tfstate manually.

I used the procedure above to successfully recover my state from 0.12.12 to 0.12.10, though other versions may require more work.

@hashibot hashibot added config v0.12 Issues (primarily bugs) reported against v0.12 releases labels Oct 28, 2019
@vitobotta
Copy link

@isometry This is great, thanks! I'll keep in mind from now on when I upgrade. I wish I had asked before :(

@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug config crash v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants