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

trying to read variables through keepers ends up in "does not have attribute ..." #21

Closed
hargut opened this issue Mar 13, 2018 · 8 comments

Comments

@hargut
Copy link

hargut commented Mar 13, 2018

Hello together,

Documentation example states that one can read a variable through the random provider:
https://www.terraform.io/docs/providers/random/r/id.html

  # Read the AMI id "through" the random_id resource to ensure that
  # both will change together.
  ami = "${random_id.server.keepers.ami_id}"

  # ... (other aws_instance arguments) ...

I tried to use keepers reading it with ${random_integer.priority.keepers.target_group_arn}, but ended up with seeing the following error:

* module.httpd.aws_alb_listener_rule.http: Resource 'random_integer.priority' does not have attribute 'keepers.target_group_arn' for variable random_integer.priority.keepers.target_group_arn'

Terraform Version

v0.11.3

Affected Resource(s)

Please list the resources as a list, for example:

  • random_integer
    Only tried with random_integer, might also effect other random_* resources.

Terraform Configuration Files

resource "random_integer" "priority" {
  min = 1
  max = 50000
  keepers = {
    target_group_arn = "${aws_alb_target_group.target_group.arn}"
    route53_record_name = "${aws_route53_record.service.name}"
  }
  lifecycle {
    create_before_destroy = true
  }
}
resource "aws_alb_listener_rule" "http" {
  listener_arn = "${var.aws_services["alb_extern_http"]}"
  priority = "${random_integer.priority.result}"
  action {
    type = "forward"
    target_group_arn = "${random_integer.priority.keepers.target_group_arn}"
  }
  condition {
    field = "host-header"
    values = ["${aws_route53_record.service.name}"]
  }
}

Expected Behavior

Terraform planning & applying as expected.

Actual Behavior

Error presented as quoted above.

Many thanks in advance for your consideration. 👍

Best regards,
Harald

@negz
Copy link

negz commented Apr 12, 2018

I'm currently seeing the same behaviour with random_id.

Terraform v0.11.6
+ provider.aws v1.7.0
+ provider.google v1.9.0
+ provider.ignition v1.0.0
+ provider.local v1.1.0
+ provider.random v1.2.0
+ provider.template v1.0.0
+ provider.tls v1.0.0

@hargut
Copy link
Author

hargut commented Apr 17, 2018

As I was lately comming across another issue, I was wondering if this could be related to hashicorp/terraform#17641

@adback03
Copy link

I'm experiencing the same problem with random_pet. This is with Terraform v0.11.8 and provider.random v2.0.

@af6140
Copy link

af6140 commented Nov 29, 2018

Similar issue when using module output as random_id keepers var.

@0mnius
Copy link

0mnius commented Mar 27, 2019

I found this working this way (tf v0.11.13):
with count
ami = "${lookup(random_id.server.*.keepers[count.index], "ami_id")}"
without
ami = "${lookup(random_id.server.*.keepers, "ami_id")}"

@mkam423
Copy link

mkam423 commented Oct 30, 2019

Still running into this issue. My theory is that the values in the keepers field is expected to be constant and does not know how to handle dynamic inputs (outputs of newly created resources). Thus, it appears as empty since the resource haven't been created yet.

@bflad
Copy link
Contributor

bflad commented May 3, 2023

Hi folks 👋 There have been a large number of changes to Terraform and this particular Terraform Provider since this issue was last discussed. If you are still running into an issue with recent versions of both, please open a new issue and we will take a fresh look. Thank you.

@bflad bflad closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2023
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants