Skip to content

Commit

Permalink
fix: Declare data resource only for requested VPC endpoints (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixb committed Jun 16, 2022
1 parent 41da688 commit 024fbc0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/vpc-endpoints/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# Endpoint(s)
################################################################################

locals {
endpoints = { for k, v in var.endpoints : k => v if var.create && try(v.create, true) }
}

data "aws_vpc_endpoint_service" "this" {
for_each = { for k, v in var.endpoints : k => v if var.create }
for_each = local.endpoints

service = lookup(each.value, "service", null)
service_name = lookup(each.value, "service_name", null)
Expand All @@ -15,7 +19,7 @@ data "aws_vpc_endpoint_service" "this" {
}

resource "aws_vpc_endpoint" "this" {
for_each = { for k, v in var.endpoints : k => v if var.create && try(v.create, true) }
for_each = local.endpoints

vpc_id = var.vpc_id
service_name = data.aws_vpc_endpoint_service.this[each.key].service_name
Expand Down

0 comments on commit 024fbc0

Please sign in to comment.