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

module requires two phase apply due to value of count cannot be computed #13

Closed
joshmyers opened this issue Dec 14, 2018 · 2 comments · Fixed by #73
Closed

module requires two phase apply due to value of count cannot be computed #13

joshmyers opened this issue Dec 14, 2018 · 2 comments · Fixed by #73

Comments

@joshmyers
Copy link

what

While trying to test a new module, which depends on this one, I added example usage:

module "vpc" {
  source    = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=master"
  namespace = "example"
  stage     = "dev"
  name      = "app"
}

resource "aws_route53_zone" "default" {
  name = "cp-example.com"
}

module "subnets" {
  source             = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=master"
  namespace          = "example"
  stage              = "dev"
  name               = "app"
  region             = "us-east-1"
  vpc_id             = "${module.vpc.vpc_id}"
  igw_id             = "${module.vpc.igw_id}"
  cidr_block         = "10.0.0.0/16"
  availability_zones = ["us-east-1a", "us-east-1b"]
}

module "elasticsearch" {
  source                  = "git::https://github.com/cloudposse/terraform-aws-elasticsearch.git?ref=tags/0.1.5"
  namespace               = "example"
  stage                   = "dev"
  name                    = "es"
  dns_zone_id             = "${aws_route53_zone.default.id}"
  security_groups         = []
  vpc_id                  = "${module.vpc.vpc_id}"
  subnet_ids              = ["${module.subnets.public_subnet_ids}"]
  zone_awareness_enabled  = "true"
  elasticsearch_version   = "6.2"
  instance_type           = "t2.small.elasticsearch"
  instance_count          = 4
  kibana_subdomain_name   = "example-kibana-es"
  encrypt_at_rest_enabled = "false"
  ebs_volume_size         = 10
  iam_actions             = ["es:*"]
  iam_role_arns           = ["*"]
}

module "elasticsearch-cleanup" {
  source               = "../"
  es_endpoint          = "${module.elasticsearch.domain_endpoint}"
  es_domain_arn        = "${module.elasticsearch.domain_arn}"
  es_security_group_id = "${module.elasticsearch.security_group_id}"
  vpc_id               = "${module.vpc.vpc_id}"
  enabled              = "true"
  namespace            = "example"
  stage                = "dev"
  schedule             = "rate(5 minutes)"
}

which failed with the below error:

Error: Error running plan: 2 error(s) occurred:

* module.elasticsearch.module.domain_hostname.aws_route53_record.default: aws_route53_record.default: value of 'count' cannot be computed
* module.elasticsearch.module.kibana_hostname.aws_route53_record.default: aws_route53_record.default: value of 'count' cannot be computed

This happens because the ID cannot be computed until after creation.
The workaround for this was using a two stage apply and passing the -target option.

joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 14, 2018
This creates all the base resources necessary to test the 
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 14, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 14, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 14, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 14, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 14, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 14, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 17, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 17, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 17, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 17, 2018
This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13
joshmyers added a commit to cloudposse/terraform-aws-lambda-elasticsearch-cleanup that referenced this issue Dec 17, 2018
* Add first cut of the ES cleanup module

* Add working example usage

This creates all the base resources necessary to test the
elasticsearch-cleanup module. Unfortunately this requires a two stage
apply as the `aws_route53_zone` resource fails to compute ID when
passed into other modules. See: cloudposse/terraform-aws-elasticsearch#13

* Deploy Lambda artifact from S3 bucket

Pull the deployment artifact from S3 using the new
terraform-external-module-artifact module. This approach has the benefit
of not checking in zip files into git, but the downside of more preamble
when wanting to test this module as per the example docs. You need to
know that the function should already be in S3 at a pre determined path.

We need to think of proper deployment and promotion of these artifacts
through different S3 buckets e.g.
artifacts.testing.cloudposse.org -> artifacts.prod.cloudposse.org
@tthayer
Copy link

tthayer commented Jun 11, 2019

@joshmyers I know this is an old issue but the workaround described here would allow you to complete this in one pass:
hashicorp/terraform#1178 (comment)

@Gowiem
Copy link
Member

Gowiem commented Sep 16, 2020

I'm still running into this issue even with Terraform 0.13 and Module depends_on. I've posted about this over in the SweetOps Slack to see if I can get to the bottom of it.

Gowiem added a commit that referenced this issue Sep 16, 2020
Implicit opt-in through checking dns_zone_id was causing folks problems as count / enabled need to be calculated during the plan which caused using target.
See #13 + https://sweetops.slack.com/archives/CB6GHNLG0/p1600294860394500
aknysh added a commit that referenced this issue Sep 17, 2020
* Adds *_hostname_enabled vars for explicit opt-in to hostnames

Implicit opt-in through checking dns_zone_id was causing folks problems as count / enabled need to be calculated during the plan which caused using target.
See #13 + https://sweetops.slack.com/archives/CB6GHNLG0/p1600294860394500

* Updates examples/complete to fix tests

* Update to `context.tf`. Update example. Update Terratest to `go` modules

Co-authored-by: aknysh <andriy.knysh@gmail.com>
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

Successfully merging a pull request may close this issue.

3 participants