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 on first run #10

Open
stavxyz opened this issue Feb 23, 2019 · 2 comments
Open

value of 'count' cannot be computed on first run #10

stavxyz opened this issue Feb 23, 2019 · 2 comments

Comments

@stavxyz
Copy link
Owner

stavxyz commented Feb 23, 2019

Error: Error refreshing state: 2 error(s) occurred:

* module.mailer.aws_route53_zone.this: aws_route53_zone.this: value of 'count' cannot be computed
* module.mailer.aws_route53_zone.this: aws_route53_zone.this: value of 'count' cannot be computed

Why does this happen? Is this expected?

@stavxyz stavxyz transferred this issue from stavxyz/terraform-aws-backend Feb 23, 2019
@stavxyz
Copy link
Owner Author

stavxyz commented Feb 23, 2019

I forgot about this...

hashicorp/terraform#12570 (comment)

A more fiddly way is to use the -target option to request that Terraform should create or update a particular resource in isolation first, thus making it available in state for use as count on a subsequent run. This allows count to refer to a managed resource attribute, but requires this extra -target step first. (Automating this two-step process is what #4149 is about.)

We need to include instructions in the README for circumstances where users want to plan the creation of their zone outside of the terraform-mailgun-aws module. The module already handles existing/non-existing route 53 zones fine, but terraform needs that resource to already exist so that it can be used to compute count.

The workaround for now will be to use -target on my route53 zone(s) and ensure those are created in advance during a plan/apply run.

My definitions looked like this

resource "aws_route53_zone" "example-dot-com" {
  name          = "example.com."
}

module "mailer" {
  source                = "github.com/samstav/terraform-mailgun-aws?ref=v2.0.1a"
  domain                = "example.com"
  mailgun_smtp_password = "${var.mailgun_smtp_password}"
  zone_id               = "${aws_route53_zone.example-dot-com.zone_id}"
}

The reason I ran into the error noted in the issue description is that the route53 zone did not exist when I first attempted to plan/apply this.

The count for the route53 zone is computed using the zone id which is optionally passed in. For a resource that hasn't been created yet, terraform is unable to determine count which must be computed at plan time. This is impossible since the resource doesn't exist yet.

https://github.com/samstav/terraform-mailgun-aws/blob/master/main.tf#L80

@stavxyz
Copy link
Owner Author

stavxyz commented Jun 14, 2019

Can address this when a solution for hashicorp/terraform#4149 comes to life.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant