From fd67b404146de22a1123c4c739e6d37869fd46ec Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Thu, 2 Nov 2023 19:24:08 -0400 Subject: [PATCH] fix: Use `lookup()` on computed resource attribute lookups in `for_each` loop --- .pre-commit-config.yaml | 4 ++-- examples/complete/main.tf | 7 +++---- main.tf | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d5886a6..145baf9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.77.0 + rev: v1.83.5 hooks: - id: terraform_fmt - id: terraform_validate @@ -23,7 +23,7 @@ repos: - '--args=--only=terraform_standard_module_structure' - '--args=--only=terraform_workspace_remote' - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-merge-conflict - id: end-of-file-fixer diff --git a/examples/complete/main.tf b/examples/complete/main.tf index fe2a5ef..327d336 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -4,7 +4,7 @@ provider "aws" { locals { region = "eu-west-1" - name = "efs-ex-${replace(basename(path.cwd), "_", "-")}" + name = "ex-${basename(path.cwd)}" azs = slice(data.aws_availability_zones.available.names, 0, 3) @@ -135,9 +135,8 @@ module "vpc" { public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"] private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"] - enable_nat_gateway = false - single_nat_gateway = true - map_public_ip_on_launch = false + enable_nat_gateway = false + single_nat_gateway = true tags = local.tags } diff --git a/main.tf b/main.tf index 439afbd..8183940 100644 --- a/main.tf +++ b/main.tf @@ -158,11 +158,11 @@ resource "aws_security_group_rule" "this" { from_port = try(each.value.from_port, 2049) to_port = try(each.value.to_port, 2049) protocol = try(each.value.protocol, "tcp") - cidr_blocks = try(each.value.cidr_blocks, null) - ipv6_cidr_blocks = try(each.value.ipv6_cidr_blocks, null) - prefix_list_ids = try(each.value.prefix_list_ids, null) + cidr_blocks = lookup(each.value, "cidr_blocks", null) + ipv6_cidr_blocks = lookup(each.value, "ipv6_cidr_blocks", null) + prefix_list_ids = lookup(each.value, "prefix_list_ids", null) self = try(each.value.self, null) - source_security_group_id = try(each.value.source_security_group_id, null) + source_security_group_id = lookup(each.value, "source_security_group_id", null) lifecycle { create_before_destroy = true