Hi, guys I'm having an error "The parameter groupName cannot be used with the pa . . .

Vishv Deshwal:
Alright, and we will hard code the values of var.vpc_cidr in .tfvars file (Correct?)

Alistair Mackay:
The only cidr you have to provide is that one. The change I just made ensures that subnet cidrs are correctly calculated from any VPC cidr - as ling as the cidr is large enough
Note the comment I put at the top of the tfvars file!

Vishv Deshwal:
To be honest with you here, I understood most of the points, But I’m trying to get a hold on to the optimization that you’ve done with the subnet. Because I’ve never used this kind of optimization, and I mostly created subnets in the similar manner as If I’m in AWS console, putting every line in the code as if I’m selecting options in console.

I’ll take some time to understand the sequence of it and absorb the optimization. Along with that I’m unable to see any separate tfvars file

Vishv Deshwal:
Oh, Just got it. To not commit in final version, because of sensitive information.

Alistair Mackay:
For the subnets, I did this

aws_availability_zones - get only the first 3 zones (us-east-1a, us-east-1b, us-east-1c)

locals - create 3 maps, one for each set of subnets, where the map key is AZ name, and map value is computed cidr range

For each set of subnets, we create one resource with a for_each which iterates over the 3 AZs we have, so each.key will in sequence take the values us-east-1a, us-east-1b, us-east-1c. using that we can look up the cidr range in the map for that group of subnets and also set availablilty_zone

When you apply, you will see resources created with names e.g.

aws_subnet.pb_sn["us-east-1a"]
aws_subnet.pb_sn["us-east-1b"]
aws_subnet.pb_sn["us-east-1c"]

Same trick is used for efs mount targets and route table associations

Vishv Deshwal:
Thanks for the further detail. I’ll first go through this subnet thoroughly and will try to run terraform apply.
Will be confirming you for the same.

Vishv Deshwal:
I was wondering if I could do this or not

This was my public subnet in AZ1 code

resource “aws_subnet” “pb_sn_az1” {
vpc_id = aws_vpc.main_vpc.id
cidr_block = var.pb_sn_az1_cidr
availability_zone = data.aws_availability_zones.available_zones.names[0]
map_public_ip_on_launch = true

tags = {
Name = “pb-sn-az1”
}
}

This was my subnet ids in tfvars file

subnet_ids_pb_sn = [
“subnet-0b1c4af9e87df5136”,
“subnet-0831f92674766cc10”,
“subnet-0824128e2316de411”
]

Should I put value of yet to be created subnet like this ?? Replacing other values with the similar one??

subnet_ids_pb_sn = [
“aws_subnet.pb_sn_az1.id”,
“subnet-0831f92674766cc10”,
“subnet-0824128e2316de411”
]

I understand that I’ll have to optimize this at one point of time, but I want to make sure that my earlier configuration would work with this way or not. I got the other errors, now I want to make the correction without optimization of my vpc? Will that be fine?

Alistair Mackay:
Not sure what you are trying to do there.
Presumably you currently either have no infrastructure, or half built infrastructure.
If it is half-built, then you should terraform destroy using the original configuration and state files you built it with, then rebuild it from my version.