# Dynamic block content update

**URL:** <https://discuss.hashicorp.com/t/dynamic-block-content-update/8965>\
**Category:** Terraform\
**Created:** [May 20, 2020, 1:51pm UTC](https://discuss.hashicorp.com/t/dynamic-block-content-update/8965 "2020-05-20T13:51:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sraddhananda](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sraddhananda/32/6219_2.png) [@sraddhananda](https://discuss.hashicorp.com/u/sraddhananda)\
**Post date:** [May 20, 2020, 1:51pm UTC](https://discuss.hashicorp.com/t/dynamic-block-content-update/8965/1 "2020-05-20T13:51:00Z")

</div>

When there is an update to the data map which is used in dynamic block, the next apply is doing the in-place update for the whole data map instead of the only change.

From this example [https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/](https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/)

Create a vnet with dynamic subnet block. Then add an entry to subnet variable and do plan/apply to observe removal of all subnets and recreate.

---

<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:** [May 20, 2020, 4:33pm UTC](https://discuss.hashicorp.com/t/dynamic-block-content-update/8965/2 "2020-05-20T16:33:25Z")

</div>

Hi @sraddhananda,

How updates to blocks of a particular type are interpreted is up to the provider, depending on how it internally represents those blocks. You didn’t include any example output showing what you’re seeing so it’s hard for me to know exactly what’s going on for you, but if you can share an example output from `terraform plan`, ideally also with the configuration that produced it, I might be able to explain it more specifically.

---

<div class="post-metadata">

**Author:** ![sraddhananda](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sraddhananda/32/6219_2.png) [@sraddhananda](https://discuss.hashicorp.com/u/sraddhananda)\
**Post date:** [May 20, 2020, 5:25pm UTC](https://discuss.hashicorp.com/t/dynamic-block-content-update/8965/3 "2020-05-20T17:25:47Z")

</div>

Hi @apparentlymart,

I took the example under dynamic nested blocks from [https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/](https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/)

I created a Vnet using the below code.

```
variable "subnets" {
  default = [
    {
      name = "a"
      number = 1
    },
    {
      name = "b"
      number = 2
    },
    {
      name = "c"
      number = 3
    },
  ]
}

locals {
  base_cidr_block = "24.2.0.0/26"
}

resource "azurerm_virtual_network" "example" {
  name = "dynamictest"
  resource_group_name = "sradtest4"
  address_space = ["24.2.0.0/26"]
  location = "northeurope"

  dynamic "subnet" {
    for_each = [for s in var.subnets: {
      name = s.name
      prefix = cidrsubnet(local.base_cidr_block, 2, s.number)
    }]

    content {
      name = subnet.value.name
      address_prefix = subnet.value.prefix
    }
  }
}

```

![image](https://global.discourse-cdn.com/hashicorp/original/2X/8/8a7d144465b9936d004c2e49c3c26ddf54b18f2c.png)

Then I added an entry in subnets variable to create one more subnet.

```
variable "subnets" {
  default = [
    {
      name = "a"
      number = 1
    },
    {
      name = "b"
      number = 2
    },
    {
      name = "c"
      number = 3
    },
    {
      name = "d"
      number = 3
    },
  ]
}

```

This is what I got from plan after adding an entry.

 ![image](https://global.discourse-cdn.com/hashicorp/original/2X/1/17d6d806089bb1fbe1630821203d99df08df789b.png)

Instead of a dynamic block, if we use for\_each resource it is working fine irrespective of configuration. Would you please guide on how to achieve this without recreating everything?

---

<div class="post-metadata">

**Author:** ![sraddhananda](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sraddhananda/32/6219_2.png) [@sraddhananda](https://discuss.hashicorp.com/u/sraddhananda)\
**Post date:** [May 28, 2020, 8:08am UTC](https://discuss.hashicorp.com/t/dynamic-block-content-update/8965/4 "2020-05-28T08:08:50Z")

</div>

Hi @apparentlymart,

Looks like it is a provider issue. In virtual network resource, a hash value has been set for subnet block. And this hash value changes when there is an update to any of the object in the map. But it is actually updating the resource which needs change.  
I’ll create a new issue for respective azurerm resources. Thank you!
