hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.59k stars 4.62k forks source link

While adding dns_server to vnet using azurerm_virtual_network_dns_servers this resource block its replacing everytime when I am trying to attach the diff DNS SERVER to same VNET #17620

Open Divyabd opened 2 years ago

Divyabd commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.0.7

AzureRM Provider Version

3.13.0

Affected Resource(s)/Data Source(s)

azurerm_virtual_network_dns_servers

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">=3.0.0"
    }
}

provider "azurerm" {
  subscription_id = ""
  #tenant_id       = var.tenant_id
  #client_id       = var.client_id
  #client_secret   = var.client_secret
  features {}
}
# resource  block resource "azurerm_virtual_network_dns_servers" "example" {
 virtual_network_id = var.vnet_id
  dns_servers        = var.dns_servers
}
variable "vnet_id" {
  type=string 
}

variable "dns_servers" {

}

# module to call the resource block for each  where Vnet and VM are creating in the  diff module

module "vnet_dns_attachment" {
   source          = "./modules/vnet_dns_attachment"
   for_each        = var.vnet_dns_attachment
   vnet_id         = module.azurem_vnet_subnet[each.value.vnet_name].vnet_id
   dns_servers     = [module.dns_vm[each.value.vm_name].private_ip]
   depends_on = [
     module.dns_vm
   ]
}
 variable "vnet_dns_attachment" {

}

# Tfvars to pass values 

vnet_dns_attachment={
  v-dns-1={
    vnet_name="VNET-BTS-ISRM-EDSS-10.180.136.0-25-eastasia"
    vm_name=  "dns01"
    }
     v-dns-1={
    vnet_name="VNET-BTS-ISRM-EDSS-10.180.136.0-25-eastasia"
    vm_name=  "dns02"
    }
  }

Debug Output/Panic Output

# module.vnet_dns_attachment["v-dns-1"].azurerm_virtual_network_dns_servers.example will be updated in-place
  ~ resource "azurerm_virtual_network_dns_servers" "example" {
      ~ dns_servers        = [
          - "10.2.1.5",
          + "10.2.1.4",
        ]
        id                 = "/subscriptions//resourceGroups/RG-BTS-NETWORKING-easia/providers/Microsoft.Network/virtualNetworks/VNET-BTS-ISRM-EDSS-10.180.136.0-25-eastasia/dnsServers/default"
        # (1 unchanged attribute hidden)
    }

Expected Behaviour

for the same Vnet if I am passing different DNS ip for single Vnet using for each it should attach 1 more it should not replace older one

Actual Behaviour

No response

Steps to Reproduce

module.vnet_dns_attachment["v-dns-1"].azurerm_virtual_network_dns_servers.example will be updated in-place

~ resource "azurerm_virtual_network_dns_servers" "example" { ~ dns_servers = [

Important Factoids

No response

References

No response

Divyabd commented 2 years ago

vnet_dns_attachment={ v-dns-1={ vnet_name="VNET-BTS-ISRM-EDSS-10.180.136.0-25-eastasia" vm_name= "dns01" } v-dns-2={ vnet_name="VNET-BTS-ISRM-EDSS-10.180.136.0-25-eastasia" vm_name= "dns02" } }

previously key name is same so i changed but still same Issue didn't resolved