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

Using existing origin access identity fails with explicit context #240

Open
alexjurkiewicz opened this issue Aug 29, 2022 · 1 comment
Open
Labels
bug 🐛 An issue with the system

Comments

@alexjurkiewicz
Copy link
Contributor

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

Code:

module "label" {
  source  = "cloudposse/label/null"
  version = "0.25.0"
  name        = "foo"
}
resource "aws_cloudfront_origin_access_identity" "this" {
  comment = module.label.id
}
module "cdn" {
  source  = "cloudposse/cloudfront-s3-cdn/aws"
  version = "0.82.5"
  # ...
  context = module.label.context
  cloudfront_origin_access_identity_iam_arn = aws_cloudfront_origin_access_identity.this.iam_arn
}

Gives error:

│ Error: Invalid count argument
│ 
│   on .terraform/modules/cdn/main.tf line 103, in resource "aws_cloudfront_origin_access_identity" "default":
│  103:   count = local.create_cloudfront_origin_access_identity ? 1 : 0
│ 
│ The "count" value depends on resource attributes that cannot be determined
│ until apply, so Terraform cannot predict how many instances will be
│ created. To work around this, use the -target argument to first apply only
│ the resources that the count depends on.

This local variable is defined as:

locals {
  enabled = module.this.enabled
  create_cloudfront_origin_access_identity = local.enabled && length(compact([var.cloudfront_origin_access_identity_iam_arn])) == 0 # "" or null
}

I'm not 100% clear why this fails, but I believe it's because module.this.enabled can't be determined from static data.

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:
Terraform 1.2.6

@rafaljanicki
Copy link
Contributor

Can this PR be merged? I'm running into that issue as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants