PureDevOps Community

Terraform Error: "10.10.0.1/22" is not a valid IPv4 CIDR block for subnet configuration

on terraform plan

│ Error: “10.10.0.1/22” is not a valid IPv4 CIDR block; did you mean “10.10.0.0/22”?

│ with module.vpc.aws_subnet.public_subnet[0],
│ on …/modules/vpc/main.tf line 19, in resource “aws_subnet” “public_subnet”:
│ 19: cidr_block = element(var.public_subnets_cidr, count.index)

This is my subnet details

variable "public_subnets_cidr" {
  type        = list(any)
  description = "CIDR block for Public Subnet"
  default     = ["10.10.0.1/22"]
}

the usage in main.tf

# Public subnet
resource "aws_subnet" "public_subnet" {
  vpc_id                  = aws_vpc.vpc.id
  count                   = length(var.public_subnets_cidr)
  cidr_block              = element(var.public_subnets_cidr, count.index)
  availability_zone       = element(var.availability_zones, count.index)
  map_public_ip_on_launch = true

  tags = {
    Name        = "${var.env}-${element(var.availability_zones, count.index)}-public-subnet"
    Environment = "${var.env}"
  }
}

You can’t create the CIDR as mentioned in your code - 10.10.0.1/22, because you have given an IP and subnet mask, you suppose to give as 10.0.0.0/22, this range will get an IP of 10.0.0.1.

thanks for the suggestion, let me try with this