Skip to content

Commit

Permalink
modules/aws/bootstrap: Add elbs_length
Browse files Browse the repository at this point in the history
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]: hashicorp/terraform#12570 (comment)
[2]: https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_installer/268/pull-ci-openshift-installer-e2e-aws/316/build-log.txt
  • Loading branch information
wking committed Sep 21, 2018
1 parent e4bfe27 commit c5c6231
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/aws/bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
4 changes: 4 additions & 0 deletions modules/aws/bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
4 changes: 4 additions & 0 deletions modules/aws/vpc/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
}
Expand Down
1 change: 1 addition & 0 deletions steps/infra/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand Down

0 comments on commit c5c6231

Please sign in to comment.