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

Value of 'count' cannot be computed #78

Closed
jdb1441 opened this issue Oct 1, 2018 · 6 comments
Closed

Value of 'count' cannot be computed #78

jdb1441 opened this issue Oct 1, 2018 · 6 comments

Comments

@jdb1441
Copy link

jdb1441 commented Oct 1, 2018

Hello,

It appears that the changes made to the output file from commit "Make use of name_prefix optional (#74)" is causing errors when we try to run a plan with security groups referencing an ingress with source security group id. We receive the following error for each security group:

  • module.subnet_name.aws_security_group_rule.ingress_with_source_security_group_id: aws_security_group_rule.ingress_with_source_security_group_id: value of 'count' cannot be computed

I have traced this back to the following change in the output file:
Original working code:

output "this_security_group_id" {
  description = "The ID of the security group"
  value       = "${element(concat(aws_security_group.this.*.id, list("")), 0)}"
}

Updated broken code:

output "this_security_group_id" {
  description = "The ID of the security group"
  value       = "${element(concat(coalescelist(aws_security_group.this.*.id, aws_security_group.this_name_prefix.*.id), list("")), 0)}"
}

We are running on tf version v0.11.2, but coalescelist was introduced in v0.9.4 so that shouldn't be a problem. Please let me know if there is any additional information you would like.

@antonbabenko
Copy link
Member

You should specify computed_ingress_with_source_security_group_id instead of ingress_with_source_security_group_id argument and set number_of_computed_ingress_with_source_security_group_id when referencing computed values (values from the module).

See this example:

computed_ingress_with_source_security_group_id = [
{
rule = "mysql-tcp"
source_security_group_id = "${module.http_sg.this_security_group_id}"
},
]
number_of_computed_ingress_with_source_security_group_id = 1

Could you show the code how you invoke this module, I don't understand why output is not working for you.

@jdb1441
Copy link
Author

jdb1441 commented Oct 9, 2018

Hi Anton,

Here is an example of how I am invoking it that works fine with the old version of the output and fails with the new:

module "example_sg" {
  source = "terraform-aws-modules/security-group/aws"

  name        = "${var.environment}-example"
  description = "Security group for example"
  vpc_id      = "${module.vpc.vpc_id}"

  ingress_with_cidr_blocks = [
    {
      from_port   = 22
      to_port     = 22
      protocol    = "tcp"
      description = "default ssh port"
      cidr_blocks = "1.2.3.4/32"
    },
  ]

  ingress_with_source_security_group_id = [
    {
      from_port                = 22
      to_port                  = 22
      protocol                 = "tcp"
      description              = "SSH"
      source_security_group_id = "${module.other_example_sg.this_security_group_id}"
    }
  ]

  egress_rules = ["all-all"]
}

@jdb1441
Copy link
Author

jdb1441 commented Oct 19, 2018

Hey @antonbabenko ,

Any idea on why this is happening? This is causing significant problems so we will likely be moving to our own module with the previous code if we can't get this resolved soon.

Thanks!
Josh

@antonbabenko
Copy link
Member

As I have pointed out in the previous comment, you need to specify configuration inside computed_ingress_with_source_security_group_id instead of ingress_with_source_security_group_id if you are using values from modules.

Also add number_of_computed_ingress_with_source_security_group_id = 1.

@antonbabenko
Copy link
Member

Closing this issue.

@github-actions
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 Nov 16, 2022
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

2 participants