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 destroy error when referencing a random_id resource in a module's locals block #18424

Closed
metmajer opened this issue Jul 10, 2018 · 6 comments

Comments

@metmajer
Copy link

metmajer commented Jul 10, 2018

Terraform Version

Terraform v0.11.7
+ provider.aws v1.26.0
+ provider.random v1.3.1

Terraform Configuration Files

provider "aws" {}
provider "random" {}

resource "random_id" "random" {
  byte_length = 8
}

module "aws-ec2-instance" {
  source = "github.com/metmajer/terraform-aws-ec2"

  name = "${var.name}"
  uuid = "${random_id.random.hex}"
}

Debug Output

See https://gist.github.com/metmajer/11063a52fb166a1d228fe115b637da91#file-terraform-destroy-log.

Expected Behavior

terraform destroy should not complain about a nil reference in random_id.

Actual Behavior

In a newly initialized workspace, terraform destroy issues the following error:

Error: Error applying plan:

1 error(s) occurred:

* module.aws-ec2-instance.var.uuid: variable "random" is nil, but no error was reported

Steps to Reproduce

  1. terraform init
  2. terraform destroy

Additional Context

I could only reproduce the issue if ${random_id.random.hex} is passed on to a module AND if the module references the passed-on variable in a locals block. See ${var.uuid} in https://github.com/metmajer/terraform-aws-ec2/blob/master/main.tf.

If https://github.com/metmajer/terraform-aws-ec2/blob/master/main.tf was changed to https://github.com/metmajer/terraform-aws-ec2/blob/no-locals/main.tf, the error does not occur.

It appears that I needed to rm -rf terraform.tfstate* .terraform; terraform init before validating that the error does not occur with https://github.com/metmajer/terraform-aws-ec2/blob/no-locals/main.tf. Otherwise, the error persisted.

References

Related issues are:

@metmajer metmajer changed the title terraform destroy error when using a random_id resource with a module terraform destroy error when referencing a random_id resource in a module's locals block Jul 10, 2018
@metmajer
Copy link
Author

@jbardin: is there any other information I can provide? I am wondering since this issue is currently blocking us in our project. Let me know if we can collaborate somehow!

@jbardin
Copy link
Member

jbardin commented Jul 16, 2018

Hi @metmajer,

Thanks for following up. There's nothing else we need here, this is related to some known edge cases with destroy time dependencies. It's likely to be the same root cause as #18026, but I'll leave this open until I can verify. Once we can unfreeze the master branch after the 0.12 work is complete we can work on resolving these.

@Constantin07
Copy link

Constantin07 commented Jul 9, 2019

I'm having the same issue when trying to destroy.

Error: Error applying plan:

1 error occurred:

	* local.db_password: local.db_password: Resource 'random_id.uuid' does not have attribute 'hex' for variable 'random_id.uuid.hex'

Is there any workaround for it meanwhile ?

@tbugfinder
Copy link

tbugfinder commented Aug 14, 2019

@jbardin It still is failing with 0.11.14.

@teamterraform
Copy link
Contributor

Hello,

This particular problem is no longer reproduced with Terraform 0.12. Users experiencing similar errors with 0.12 are not likely from the same root cause, and we ask that a new issue be opened in that case.

Since there is no more planned development for 0.11, we are going to close out this issue.

Thanks

@ghost
Copy link

ghost commented Sep 14, 2019

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 Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants