Hi,
I’m stucked with the following subnets configuration:
+ aws = [
+ {
+ accounts = "prod"
+ id = "523131231043"
+ private_subnets = {
+ eu-central-1a = "10.44.4.96/27"
+ eu-central-1b = "10.44.5.128/27"
+ eu-central-1c = "10.44.6.160/27"
}
+ public_subnets = {
+ eu-central-1a = "10.44.7.0/27"
+ eu-central-1b = "10.44.8.32/27"
+ eu-central-1c = "10.44.9.64/27"
}
},
+ {
+ accounts = "dev"
+ id = "098453041777"
+ private_subnets = {
+ eu-central-1a = "10.44.7.0/27"
+ eu-central-1b = "10.44.8.32/27"
+ eu-central-1c = "10.44.9.64/27"
}
+ public_subnets = {
+ eu-central-1a = "10.44.10.96/27"
+ eu-central-1b = "10.44.12.160/27"
+ eu-central-1c = "10.44.12.160/27"
}
},
]
I’ve created the subnet resource this way:
resource "aws_subnet" "private" {
count = length(var.aws[*].private_subnets)
availability_zone = element(keys(var.aws[*].private_subnets), count.index)
cidr_block = element(values(var.aws[*].private_subnets), count.index)
map_public_ip_on_launch = false
vpc_id = aws_vpc.this.id
}
This produces this error:
│ Error: Invalid function argument
│
│ on test.tf line 42, in resource "aws_subnet" "private":
│ 42: availability_zone = element(keys(var.aws[*].private_subnets), count.index)
│ ├────────────────
│ │ var.aws is tuple with 2 elements
│
│ Invalid value for "inputMap" parameter: must have map or object type.
╵
╷
│ Error: Invalid function argument
│
│ on test.tf line 42, in resource "aws_subnet" "private":
│ 42: availability_zone = element(keys(var.aws[*].private_subnets), count.index)
│ ├────────────────
│ │ var.aws is tuple with 2 elements
│
│ Invalid value for "inputMap" parameter: must have map or object type.
╵
╷
│ Error: Error in function call
│
│ on test.tf line 43, in resource "aws_subnet" "private":
│ 43: cidr_block = element(values(var.aws[*].private_subnets), count.index)
│ ├────────────────
│ │ var.aws is tuple with 2 elements
│
│ Call to function "values" failed: values() requires a map as the first
│ argument.
╵
╷
│ Error: Error in function call
│
│ on test.tf line 43, in resource "aws_subnet" "private":
│ 43: cidr_block = element(values(var.aws[*].private_subnets), count.index)
│ ├────────────────
│ │ var.aws is tuple with 2 elements
│
│ Call to function "values" failed: values() requires a map as the first
│ argument.
╵
ERRO[0012] 1 error occurred:
* exit status 1
I have tried concating and a lot of other stuff but I don’t get this stuff to work. I need help please. I need to work with count as I need to create a NAT GW only in the first subnet of each account. I was able to work trough with for_each but then I’m not able to have a NAT GW only in the first subnet. It then creates them in all puplic subnets.