Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform throwing invalid subnet range error

I keep getting the following error while I try to create a subnet using terraform. No issues creating subnet using aws console. Could someone help me?

Error: error creating subnet: InvalidSubnet.Range: The CIDR '192.168.1.0/24' is invalid.
    status code: 400

Code to create VPC:

resource "aws_vpc" "vpc_worker" {
  provider             = aws.region-worker
  cidr_block           = "198.168.0.0/16"
  enable_dns_support   = true
  enable_dns_hostnames = true
  tags = {
    Name = "master-vpc-jenkins"
  }
}

Code to create subnet:

#Create subnet in us-west-2
resource "aws_subnet" "subnet_1_worker" {
  provider   = aws.region-worker
  vpc_id     = aws_vpc.vpc_worker.id
  cidr_block = "192.168.1.0/24"
}

Terraform version: 0.12.29

Thanks in advance.

like image 456
Nanthini Muniapan Avatar asked Jul 17 '26 08:07

Nanthini Muniapan


1 Answers

Your VPC is 198.168.0.0/16, but subnet is 192.168.1.0/24 (note 198 and 192). Please change VPC to 192.168.0.0/16.

like image 139
Marcin Avatar answered Jul 20 '26 09:07

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!