Azure delegation issue after first plan

Hi,

I’m trying to enable a delegation for a subnet defined as below on my tfvars file:

# Subnets
subnets = {
  apptier-snet = {
    address_prefixes   = ["192.168.32.64/26"]
    service_delegation = false
    delegation_name    = ""
    delegation_action  = []
  }
  containers-snet = {
    address_prefixes   = ["192.168.32.192/28"]
    service_delegation = true
    delegation_name    = "Microsoft.ContainerInstance/containerGroups"
    delegation_action  = []
  }

And inside vnet.tf file I’m using this code to deploy:

  dynamic "delegation" {
    for_each = lookup(each.value, "service_delegation", {}) ? [1] : []


    content {
      name = "delegation"

      service_delegation {
        name = each.value.delegation_name
      }
    }
  }

Vnet and Delegation creation works fine when I execute apply for the first time.
But, after that every plan or apply to none or any other related service(even if I change a tag), I receive this:

  # azurerm_subnet.subnetdata["containers-snet"] will be updated in-place
  ~ resource "azurerm_subnet" "subnetdata" {
        id                                             = "(REDACTED)/containers-snet"
        name                                           = "containers-snet"
        # (7 unchanged attributes hidden)

      ~ delegation {
            name = "delegation"

          ~ service_delegation {
              ~ actions = [
                  - "Microsoft.Network/virtualNetworks/subnets/action",
                ]
                name    = "Microsoft.ContainerInstance/containerGroups"
            }
        }
    }

Apply command returns:

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

If I ran plan again, it will try to update the delegation again.

Also tried:

tfvars:

# Subnets
subnets = {
  apptier-snet = {
    address_prefixes   = ["192.168.32.64/26"]
    service_delegation = false
    delegation_name    = ""
    delegation_action  = []
  }
  containers-snet = {
    address_prefixes   = ["192.168.32.192/28"]
    service_delegation = true
    delegation_name    = "Microsoft.ContainerInstance/containerGroups"
    delegation_action  = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
  }

vnet.tf:

  dynamic "delegation" {
    for_each = lookup(each.value, "service_delegation", {}) ? [1] : []


    content {
      name = "delegation"

      service_delegation {
        name = each.value.delegation_name
        actions = each.value.delegation_action
      }
    }
  }

Even this way I got no luck to stop messages to update the delegation. Anyone faced the same issue? Or there is something that I missed on lookup sentence?

Appreciate any help on that!

Thanks

Hi @saraivaf!

I think you are describing the same behavior that was discussed in this issue in the Azure provider repository:

1 Like