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

Referencing count created resources from another module in map array #25243

Closed
jaekunchoi opened this issue Jun 15, 2020 · 4 comments
Closed
Labels
waiting-response An issue/pull request is waiting for a response from the community

Comments

@jaekunchoi
Copy link

Terraform Version

0.12.26

Terraform Configuration Files

Modules in path ./ecs/ecs-service/*.tf

resource "aws_lb_target_group" "app" {
  count = length(var.target_groups)
  name = "test-${var.env}"
  port = var.target_groups[count.index].app_port
  protocol = "HTTP"
  vpc_id = var.vpc_id
  ...
}

output "app_target_group_arns" {
  value = aws_lb_target_group.app.*.arn
}

parent module ./ecs

module "ecs-service" {
  source = "./ecs-service"
  ...
}

module "alb" {
  source = "./ecs/alb"
  rules = [
    {
      priority : 100,
      target_group_arn : element(module.ecs-service.app_target_group_arns, 0),
      condition_field : "host-header",
      condition_values : [element(module.alb.alb_record_fqdn, 0)]
    },
    {
      priority : 101,
      target_group_arn : element(module.ecs-service.app_target_group_arns, 1),
      condition_field : "host-header",
      condition_values : [element(module.alb.alb_record_fqdn, 1)]
    }
  ]
}

Debug Output

Call to function "element" failed: cannot use element function with an empty list

Expected Behavior

module ecs-service targetgroup should wait until alb rules are deleted first so alb module doesn't reference elements that does not exist.

Actual Behavior

errors with Call to function "element" failed: cannot use element function with an empty list

Steps to Reproduce

run terraform destroy with above config

References

#11210

@jaekunchoi jaekunchoi changed the title Referencing count created resources from another module in a map Referencing count created resources from another module in map array Jun 15, 2020
@danieldreier
Copy link
Contributor

@apparentlymart I think that this is basically an instance of #25162 ("non-obvious ordering of functions and resources") - does it look that way to you?

@danieldreier danieldreier added the waiting-response An issue/pull request is waiting for a response from the community label Jun 15, 2020
@jbardin
Copy link
Member

jbardin commented Jun 18, 2020

This looks like the result of the variable values being evaluated during destroy, which should be one of the situations fixed in 0.13.

@hybmg57 There's not enough information here for me to reproduce the issue, but if you have the ability to test with the latest 0.13 beta, we can see if my hunch is correct and this is fixed already.

@mildwonkey
Copy link
Contributor

I am going to close this issue due to inactivity.

If there is still a question, I recommend the the community forum, where there are far more people available to help. If there is a bug or you would like to make a feature request, please open a new issue and fill out the template.
Thanks!

@ghost
Copy link

ghost commented Oct 13, 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 as resolved and limited conversation to collaborators Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

No branches or pull requests

4 participants