Skip to content

Commit

Permalink
Fix var.enabled conditional logic within for_each meta-argument in vp…
Browse files Browse the repository at this point in the history
…c-endpoints submodule

set() is neither a real Terraform function nor will the valid toset([]) work in this instance of for_each (due to type mismatch in the ternary operator), however due to the short-circuit with enabled=true, this wasn't picked up in tests.
  • Loading branch information
korenyoni authored May 4, 2021
1 parent fee1f21 commit 17fcb3c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/vpc-endpoints/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module "gateway_endpoint_label" {
source = "cloudposse/label/null"
version = "0.24.1"

for_each = local.enabled ? data.aws_vpc_endpoint_service.gateway_endpoint_service : set()
for_each = local.enabled ? data.aws_vpc_endpoint_service.gateway_endpoint_service : {}
attributes = [each.key]

context = module.this.context
Expand All @@ -28,14 +28,14 @@ module "interface_endpoint_label" {
source = "cloudposse/label/null"
version = "0.24.1"

for_each = local.enabled ? data.aws_vpc_endpoint_service.interface_endpoint_service : set()
for_each = local.enabled ? data.aws_vpc_endpoint_service.interface_endpoint_service : {}
attributes = [each.key]

context = module.this.context
}

resource "aws_vpc_endpoint" "gateway_endpoint" {
for_each = local.enabled ? data.aws_vpc_endpoint_service.gateway_endpoint_service : set()
for_each = local.enabled ? data.aws_vpc_endpoint_service.gateway_endpoint_service : {}
service_name = data.aws_vpc_endpoint_service.gateway_endpoint_service[each.key].service_name
policy = var.gateway_vpc_endpoints[each.key].policy
vpc_endpoint_type = data.aws_vpc_endpoint_service.gateway_endpoint_service[each.key].service_type
Expand All @@ -45,7 +45,7 @@ resource "aws_vpc_endpoint" "gateway_endpoint" {
}

resource "aws_vpc_endpoint" "interface_endpoint" {
for_each = local.enabled ? data.aws_vpc_endpoint_service.interface_endpoint_service : set()
for_each = local.enabled ? data.aws_vpc_endpoint_service.interface_endpoint_service : {}
service_name = data.aws_vpc_endpoint_service.interface_endpoint_service[each.key].service_name
policy = var.interface_vpc_endpoints[each.key].policy
security_group_ids = var.interface_vpc_endpoints[each.key].security_group_ids
Expand Down

0 comments on commit 17fcb3c

Please sign in to comment.