From c5c6231574923dd8f83fcb7612bf342521d37f9a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 17 Sep 2018 21:58:35 -0700 Subject: [PATCH] modules/aws/bootstrap: Add elbs_length To work around Terraform's limitations on length() of computed lists at plan-time [1]. By avoiding the generated resources and just computing the number of elastic load-balancers based on our input counts, we avoid confusing Terraform and getting [2]: * module.bootstrap.aws_elb_attachment.bootstrap: aws_elb_attachment.bootstrap: value of 'count' cannot be computed The value of 2 comes from: * One internal LB (either aws_elb.api_internal or aws_elb.api_external) and * One aws_elb.console. [1]: https://github.com/hashicorp/terraform/issues/12570#issuecomment-318414280 [2]: https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_installer/268/pull-ci-openshift-installer-e2e-aws/316/build-log.txt --- modules/aws/bootstrap/main.tf | 2 +- modules/aws/bootstrap/variables.tf | 4 ++++ modules/aws/vpc/outputs.tf | 4 ++++ steps/infra/aws/main.tf | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/aws/bootstrap/main.tf b/modules/aws/bootstrap/main.tf index c83b0cefecd..1dec9bc5949 100644 --- a/modules/aws/bootstrap/main.tf +++ b/modules/aws/bootstrap/main.tf @@ -121,7 +121,7 @@ resource "aws_instance" "bootstrap" { } resource "aws_elb_attachment" "bootstrap" { - count = "${length(var.elbs)}" + count = "${var.elbs_length}" elb = "${var.elbs[count.index]}" instance = "${aws_instance.bootstrap.id}" } diff --git a/modules/aws/bootstrap/variables.tf b/modules/aws/bootstrap/variables.tf index f67481c01fc..fd7b1726142 100644 --- a/modules/aws/bootstrap/variables.tf +++ b/modules/aws/bootstrap/variables.tf @@ -24,6 +24,10 @@ variable "elbs" { description = "Elastic load balancer IDs to attach to the bootstrap node." } +variable "elbs_length" { + description = "The length of the 'elbs' variable, to work around https://github.com/hashicorp/terraform/issues/12570." +} + variable "iam_role" { type = "string" default = "" diff --git a/modules/aws/vpc/outputs.tf b/modules/aws/vpc/outputs.tf index cab4d40f9b6..70647446172 100644 --- a/modules/aws/vpc/outputs.tf +++ b/modules/aws/vpc/outputs.tf @@ -46,6 +46,10 @@ output "aws_lbs" { value = ["${compact(concat(aws_elb.api_internal.*.id, list(aws_elb.console.id), aws_elb.api_external.*.id))}"] } +output "aws_lbs_length" { + value = "2" +} + output "aws_elb_api_external_dns_name" { value = "${element(concat(aws_elb.api_external.*.dns_name, list("")), 0)}" } diff --git a/steps/infra/aws/main.tf b/steps/infra/aws/main.tf index 0035320e40b..55b26035d89 100644 --- a/steps/infra/aws/main.tf +++ b/steps/infra/aws/main.tf @@ -23,6 +23,7 @@ module "bootstrap" { bucket = "${aws_s3_bucket.tectonic.bucket}" cluster_name = "${var.tectonic_cluster_name}" elbs = "${module.vpc.aws_lbs}" + elbs_length = "${module.vpc.aws_lbs_length}" iam_role = "${var.tectonic_aws_master_iam_role_name}" ignition = "${local.ignition_bootstrap}" subnet_id = "${module.vpc.master_subnet_ids[0]}"