I'm getting the following error when trying to run terraform destroy -target=module.thing1 on the config below:
Error configuring: 1 error(s) occurred:
* 1:3: unknown variable accessed: var.count in:
${var.count}
This doesn't happen without the -target, so it seems like that's the issue. It could be related to #8098 but I've only seen this error with -target when doing destroy, not apply or plan.
$ terraform -v
Terraform v0.7.0
./main.tf:
module "thing1" {
source = "./thing"
count = 3
}
./thing/null.tf:
variable "count" {}
resource "null_resource" "thing" {
count = "${var.count}"
}
Same issue here, but it got fixed when I set default value for the variable.
Setting a default for the variable doesn't fix the underlying issue, that the interpolated variable is not being respected properly in the destroy dependency graph. When the destroy executes, it uses the default, which in many cases will cause incorrect behavior.
This broke sometime between v0.7.0-rc3 and v0.7.0.
I suspect #6599 may have something to do with this.
Confirmed removing this change from #6599 fixes the issue from v0.7.0.
cc. @phinze
Thanks @vaygr for the temporary hack. After filling in several defaults (that would never be real defaults) I was able to destroy.
Scary to think that the non-default values are not being honored.
Facing the same issue on 0.7.2 and 0.7.3.
The workaround of adding default value did the trick
I put up a PR for this: #9021
Since #9021 merged the repro above no longer occurs. Thanks @kyhavlov!
Looks like the same issue exists for apply in at least 0.8.1:
$ terraform plan -target='module.ca_central_1'
Error running plan: 8 error(s) occurred:
* 1:3: unknown variable accessed: var.aws_region in:
${var.aws_region}
* 1:3: unknown variable accessed: var.aws_region in:
${var.aws_region}
* 1:3: unknown variable accessed: var.aws_region in:
${var.aws_region}
* 1:3: unknown variable accessed: var.aws_region in:
${var.aws_region}
* 1:3: unknown variable accessed: var.aws_region in:
${var.aws_region}
* 1:3: unknown variable accessed: var.aws_region in:
${var.aws_region}
* 1:3: unknown variable accessed: var.aws_region in:
${var.aws_region}
* 1:3: unknown variable accessed: var.aws_region in:
${var.aws_region}
while declaring it like this in main.tf:
module "ca_central_1" {
source = "haproxy_ec2"
aws_region = "ca-central-1"
haproxy_count = "2"
}
@mitchellh FYI: this issue is back on 0.8.1 and 0.8.2 with both, plan and apply. Haven't tried destroy, though.
Thanks @progre55 and @vaygr, do you think either of you could put together a small reproduction so we can take a closer look?
FYI, I'm seeing this issue also in 0.8.4
F.Y.I. I am facing that issue in versions 0.8.0, 0.8.4 and 0.8.5 -> 0.7.13 works perfectly
See: https://github.com/hashicorp/terraform/issues/9042
The -Xlegacy-graph option helped in 0.8.5 so i can plan again but i don't think this is an intended behaviour
It always occurs in combination with the -target option... executing a plan on the whole project does not produce that error....
Still seeing this with version 0.8.6. Also, adding -Xlegacy-graph to terraform import doesn't seem to solve it, so I'm unsure at the moment how to import resources (besides editing the state manually to change the terraform version and doing it again with version 0.7.13...)
Yeah, the bug's back.
Seeing this in v0.8.8 as well :(
The workaround is to use some dummy default variables as suggested (few posts above) by @vaygr.
Confirmed this bug in v0.8.8, dummy default values work.
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.
Most helpful comment
Same issue here, but it got fixed when I set
defaultvalue for the variable.