New to Terraform and trying to create the following VPC from Adrian Cantril's class using the DRY method.
I can get the first 4 subnets created but when I try to repeat it, it duplicates it per AZ giving me an error.
I have tried a few other things that created 1 subnet per AZ, e.g. 10.16.0.0/20 in AZ A, 10.16.16.0 /20 in AZ B, etc..
Below is a snippet of the code I am using.
variable "vpc_cidr" {
type = string
default = "10.16.0.0/16"
}
resource "aws_subnet" "private_subnets-az-a" {
count = 4
vpc_id = aws_vpc.vpc.id
cidr_block = cidrsubnet(var.vpc_cidr, 4, count.index)
availability_zone = data.aws_availability_zones.available.names[0]
}
resource "aws_subnet" "private_subnets-az-b" {
count = 4
vpc_id = aws_vpc.vpc.id
cidr_block = cidrsubnet(var.vpc_cidr, 4, count.index)
availability_zone = data.aws_availability_zones.available.names[1]