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

Problem with module and splat variables #597

Closed
lamdor opened this issue Nov 24, 2014 · 0 comments · Fixed by #611
Closed

Problem with module and splat variables #597

lamdor opened this issue Nov 24, 2014 · 0 comments · Fixed by #611

Comments

@lamdor
Copy link
Contributor

lamdor commented Nov 24, 2014

As I commented on #408, however, I think the problem is more specific to using a module that refers to internal resources with a splat variable.

If I have a base/main.tf file with

variable "instance_count" {
  default = "1"
}

resource "aws_instance" "base" {
  ami = "ami-b66ed3de"
  instance_type = "m3.medium"

  count = "${var.instance_count}"

  connection {
    type = "ssh"
    host = "${aws_instance.base.private_ip}"
  }
}

resource "aws_route53_record" "base_internal_dns" {
  name = "${concat("test", count.index, ".", "test.com")}"

  count = "${var.instance_count}"

  zone_id = "test.com"
  type = "A"
  ttl = "1"
  records = ["${element(aws_instance.base.*.private_ip, count.index)}"]
}

And another configuration that uses it as a module like:

issue.tf:

module "base" {
  source = "./base"
  instance_count = "2"
}

And then run terraform plan --module-depth=1 from the issue.tf file location, I get:
Error running plan: Resource 'aws_instance.base' not found for variable 'aws_instance.base.*.private_ip'

The aws_route53_record.base_internal_dns resource refers to the aws_instance.base on the records line.

However, if I run from inside of the module at the base/ directory, I runs correctly.

If I change that line to just records = ["${aws_instance.base.*.private_ip}"], it gets the error.

If it's changed to records = ["${aws_instance.base.0.private_ip}"], it does plan, even though it's going to just use the first instance's information.

Any ideas? Thanks.

@ghost ghost locked and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant