# How to create multiple subnets automatically with with same subnetmast

**URL:** <https://discuss.hashicorp.com/t/how-to-create-multiple-subnets-automatically-with-with-same-subnetmast/8960>\
**Category:** AWS\
**Tags:** testing\
**Created:** [May 20, 2020, 12:43pm UTC](https://discuss.hashicorp.com/t/how-to-create-multiple-subnets-automatically-with-with-same-subnetmast/8960 "2020-05-20T12:43:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohitmitrah](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/rohitmitrah/32/7057_2.png) [@rohitmitrah](https://discuss.hashicorp.com/u/rohitmitrah)\
**Post date:** [May 20, 2020, 12:43pm UTC](https://discuss.hashicorp.com/t/how-to-create-multiple-subnets-automatically-with-with-same-subnetmast/8960/1 "2020-05-20T12:43:06Z")

</div>

I am new to Terraform. I am trying to create a code in which I can create the subnet in loop but cidrsubnet function is not working out as I don’t want to change the subnet mask. For Example: I want to create the subnet with these IPs: Subnet 1: 10.90.46.0/27, subnet 2: 10.90.46.32/27 subnet3: 10.90.46.64/27 and so on till subnet 8: 10.90.46.224/27. So is there anyway I can put the the First subnet 10.90.46.0/27 then it can create rest 8 subnet automatically without me mentioning all subnet CIDR. I am asking as in the other requirement I have work on is to create 16 subnet and I don’t want to put the subnet manually. My Code looks like this:

```auto
variable "vpc_id" {
  default = "vpc-123"
}

#Here add all your 8 CIDR's to the list in "subnet_cidr" and for each one add one entry in "subnet_azs". You can repeat values in "subnet_azs" but not in subnet_cidr"

variable "subnet_cidr" {
  default = ["10.90.46.0/27", "10.90.46.32/27", "10.90.46.64/27", "10.90.46.224/27"]
}

variable "subnet_azs" {
  default = ["us-east-1a", "us-east-1b", "us-east-1c", "us-east-1c"]
}

resource "aws_subnet" "my_subnets" {
  count = 8
  vpc_id = "${var.vpc_id}"
  cidr_block = "${element(var.subnet_cidr, count.index)}"
  availability_zone = "${element(var.subnet_azs, count.index)}"
}
```
