From 1103c7adf2763ec46b5267a07eeae2db51bd4738 Mon Sep 17 00:00:00 2001 From: Himanshu Ahirwar <83774016+h1manshu98@users.noreply.github.com> Date: Wed, 1 Nov 2023 22:53:14 +0530 Subject: [PATCH] fix: 'failed: cannot use element function with an empty list' with single_nat_gateway attribute (#62) --- _example/complete/example.tf | 26 +++++++++++++++++--------- main.tf | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/_example/complete/example.tf b/_example/complete/example.tf index 43200bc..fbe52b9 100644 --- a/_example/complete/example.tf +++ b/_example/complete/example.tf @@ -1,20 +1,24 @@ provider "aws" { - region = "eu-west-1" + region = local.region } locals { name = "app" environment = "test" + region = "eu-west-1" } ##----------------------------------------------------------------------------- ## Vpc Module call. ##----------------------------------------------------------------------------- module "vpc" { - source = "clouddrove/vpc/aws" - version = "2.0.0" - name = local.name - environment = local.environment + source = "clouddrove/vpc/aws" + version = "2.0.0" + + enable = true + name = local.name + environment = local.environment + cidr_block = "10.0.0.0/16" enable_flow_log = true # Flow logs will be stored in cloudwatch log group. Variables passed in default. create_flow_log_cloudwatch_iam_role = true @@ -31,11 +35,15 @@ module "vpc" { #tfsec:ignore:aws-ec2-no-excessive-port-access #tfsec:ignore:aws-ec2-no-public-ingress-acl module "subnets" { - source = "./../../" - name = local.name - environment = local.environment + source = "./../../" + + enable = true + name = local.name + environment = local.environment + nat_gateway_enabled = true - availability_zones = ["eu-west-1a", "eu-west-1b", "eu-west-1c"] + single_nat_gateway = true + availability_zones = ["${local.region}a", "${local.region}b", "${local.region}c"] vpc_id = module.vpc.vpc_id type = "public-private" igw_id = module.vpc.igw_id diff --git a/main.tf b/main.tf index cea917c..cf47d07 100644 --- a/main.tf +++ b/main.tf @@ -7,7 +7,7 @@ locals { public_count = var.enable == true && (var.type == "public" || var.type == "public-private") ? length(var.availability_zones) : 0 private_count = var.enable == true && (var.type == "private" || var.type == "public-private") ? length(var.availability_zones) : 0 - nat_gateway_count = var.single_nat_gateway ? 1 : (var.enable == true && (var.type == "private" || var.type == "public-private") && var.nat_gateway_enabled == true ? length(var.availability_zones) : 0) + nat_gateway_count = var.enable == true && var.single_nat_gateway ? 1 : (var.enable == true && (var.type == "private" || var.type == "public-private") && var.nat_gateway_enabled == true ? length(var.availability_zones) : 0) } ##----------------------------------------------------------------------------- ## Labels module called that will be used for naming and tags.