Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Added workaround for length() on a calculated value for efs_volume
Browse files Browse the repository at this point in the history
see: hashicorp/terraform#10857

`length()` cannot be used on variables that aren’t known ahead of running terraform plan. To work around this, a `num_subnets` variable and output value has been added to the `aws_vpc` module, which is then used as to calculate the `count` attribute of `module.efs_volume.aws_efs_mount_target.mount_target`.
  • Loading branch information
Kerin Cosford committed Jul 2, 2018
1 parent b06248a commit 6d9b1c2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion infra/terraform/modules/aws_vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ output "storage_subnet_ids" {
value = ["${aws_subnet.storage.*.id}"]
}

output "storage_cidr_blocks" {
value = "${var.storage_cidr_blocks}"
}

output "dmz_subnets" {
value = "${zipmap(aws_subnet.dmz.*.id, aws_subnet.dmz.*.availability_zone)}"
}
Expand Down Expand Up @@ -103,4 +107,3 @@ output "nat_gateway_subnets" {
# output "sg_inbound_http_id" {
# value = "${aws_security_group.inbound_http.id}"
# }

2 changes: 1 addition & 1 deletion infra/terraform/modules/efs_volume/efs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ resource "aws_efs_mount_target" "mount_target" {
file_system_id = "${aws_efs_file_system.fs.id}"
subnet_id = "${element(var.subnet_ids, count.index)}"
security_groups = ["${aws_security_group.sg.id}"]
count = "${length(var.subnet_ids)}"
count = "${var.num_subnets}"
}
2 changes: 2 additions & 0 deletions infra/terraform/modules/efs_volume/inputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ variable "subnet_ids" {
type = "list"
}

variable "num_subnets" {}

variable "performance_mode" {
default = "generalPurpose"
}
1 change: 1 addition & 0 deletions infra/terraform/platform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module "airflow_storage_efs_volume" {
vpc_id = "${module.aws_vpc.vpc_id}"
node_security_group_id = "${module.aws_vpc.extra_node_sg_id}"
subnet_ids = "${module.aws_vpc.storage_subnet_ids}"
num_subnets = "${length(module.aws_vpc.storage_cidr_blocks)}"
}

module "airflow_db" {
Expand Down

0 comments on commit 6d9b1c2

Please sign in to comment.