# Terraform 0.12 dynamic block for subnet

**URL:** <https://discuss.hashicorp.com/t/terraform-0-12-dynamic-block-for-subnet/7860>\
**Category:** Terraform\
**Created:** [April 20, 2020, 2:50pm UTC](https://discuss.hashicorp.com/t/terraform-0-12-dynamic-block-for-subnet/7860 "2020-04-20T14:50:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pzowghi](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/pzowghi/32/5430_2.png) [@pzowghi](https://discuss.hashicorp.com/u/pzowghi)\
**Post date:** [April 20, 2020, 2:50pm UTC](https://discuss.hashicorp.com/t/terraform-0-12-dynamic-block-for-subnet/7860/1 "2020-04-20T14:50:47Z")

</div>

I am wondering, is it possible to use a dynamic block for aws\_subnet resource?  
if so, could you send me an example?  
I tried it, but I got an error.The argument “cidr\_block” is required, but no definition was found.  
Blocks of type “cidr\_block” are not expected here.  
resource “aws\_subnet” “subnetp” {  
vpc\_id = aws\_vpc.vpc22.id  
map\_public\_ip\_on\_launch = true  
availability\_zone = data.aws\_availability\_zones.available.names[1]

dynamic “cidr\_block” {  
for\_each = [for cidrblock in var.cidr\_blocks\_subnet: {  
cidr\_block = cidrblock.CidrBlock  
name = cidrblock.Name  
}]  
content {  
cidr\_block = cidr\_block.value.cidr\_block  
tags = merge(map(“Name”, cidr\_block.value.name), var.default\_tags)  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [April 20, 2020, 6:07pm UTC](https://discuss.hashicorp.com/t/terraform-0-12-dynamic-block-for-subnet/7860/2 "2020-04-20T18:07:56Z")

</div>

Hi @pzowghi,

The `cidr_block` argument for `aws_subnet` expects a single string, so none of Terraform’s repetition constructs are really appropriate for it.

Could you share a little more about your underlying goal? If you can describe the problem you want to solve separately from what you tried in order to solve it I might be able to offer an alternative approach.

---

<div class="post-metadata">

**Author:** ![pzowghi](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/pzowghi/32/5430_2.png) [@pzowghi](https://discuss.hashicorp.com/u/pzowghi)\
**Post date:** [April 20, 2020, 7:12pm UTC](https://discuss.hashicorp.com/t/terraform-0-12-dynamic-block-for-subnet/7860/3 "2020-04-20T19:12:22Z")

</div>

I have 6 subnets like this, I want to prevent to create 6 aws\_subnet resources.  
how I can use one or two subnets for all 6 subnets?  
thank you
