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

Interpolation doesn't work for derived resources #17368

Closed
hyperius opened this issue Feb 16, 2018 · 3 comments · Fixed by #17548
Closed

Interpolation doesn't work for derived resources #17368

hyperius opened this issue Feb 16, 2018 · 3 comments · Fixed by #17548

Comments

@hyperius
Copy link

It looks like there is interpolation bug introduced in v0.11.3.

I have the module with a couple EC2 instances count of which is provided to module as variable.
Also I have a bunch of EBS, EBS attachments and other stuff which relies on count of EC2 instances.

There is no errors when terraform plan -out=file executed, but terraform apply file fails with following error:

$ terraform apply file

Error: Error applying plan:

2 error(s) occurred:

* module.sentry.aws_volume_attachment.web_docker: Error reading aws_instance.web count: cannot parse "${var.instance_web_count}" as an integer
* module.sentry.aws_volume_attachment.web_data: Error reading aws_instance.web count: cannot parse "${var.instance_web_count}" as an integer

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Terraform Version

$ terraform -v
Terraform v0.11.3
+ provider.aws v1.9.0
+ provider.consul v1.0.0

Terraform Configuration Files

Module call

module "sentry" {
  source = "git::ssh://[email protected]/my/shiny-module.git?ref=master"
...

  instance_web_count      = 1
...
}

Module code

variable "instance_web_count"      { default = 2 }

resource "aws_instance" "web" {
  ...
  count                   = "${var.instance_web_count}"
  ...
}

resource "aws_ebs_volume" "web_docker" {
  count             = "${aws_instance.web.count}"
  ...
}

resource "aws_ebs_volume" "web_data" {
  count             = "${aws_instance.web.count}"
  ...
}

resource "aws_volume_attachment" "web_docker" {
  count = "${aws_instance.web.count}"

  device_name = "/dev/xvdb"

  volume_id   = "${element(aws_ebs_volume.web_docker.*.id, count.index)}"
  instance_id = "${element(aws_instance.web.*.id, count.index)}"
}

resource "aws_volume_attachment" "web_data" {
  count = "${aws_instance.web.count}"

  device_name = "/dev/xvdc"

  volume_id   = "${element(aws_ebs_volume.web_data.*.id, count.index)}"
  instance_id = "${element(aws_instance.web.*.id, count.index)}"
}

Debug Output

https://pastebin.com/EwE2eTp3

Expected Behavior

Resources created

Actual Behavior

terraform apply fails with error

Steps to Reproduce

  1. Create initial resources
  2. Add derived resources to configuration
  3. terraform plan
  4. terraform apply

References

Perhaps the same issue as #17351

@hyperius
Copy link
Author

any updates here?

@jbardin
Copy link
Member

jbardin commented Mar 9, 2018

Hi @hyperiusm,

Sorry about the lack of feedback here. There was more discussion in 17462, but I have got a working reproduction case now. It requires a saved plan, and an existing resource with an interpolated count.

A minimal test case here starts with the config:

variable "instance_web_count" {
  default = 1
}

resource "null_resource" "test" {
  count = "${var.instance_web_count}"
}

#resource "null_resource" "dependent" {
#  count = "${null_resource.test.count}"
#}
  • terraform apply
  • uncomment the "dependent" resource
  • terraform plan -out plan.out
  • terraform apply plan.out

@ghost
Copy link

ghost commented Apr 4, 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 Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants