Terraform removes all service endpoints on VNET during changes to VNET DNS.
Terraform v0.11.10
azurerm_virtual_network
#################################
# Resources
#################################
resource "azurerm_resource_group" "test_rg" {
name = "${var.env}"
location = "${var.azurerm_location}"
}
resource "azurerm_virtual_network" "test_vnet" {
name = "${var.env}"
address_space = ["10.103.12.0/22"]
location = "${var.azurerm_location}"
resource_group_name = "${azurerm_resource_group.test_rg.name}"
}
resource "azurerm_subnet" "test_subnet" {
name = "${var.env}-subnet"
address_prefix = "10.103.14.0/24"
virtual_network_name = "${azurerm_virtual_network.test_vnet.name}"
resource_group_name = "${azurerm_resource_group.test_rg.name}"
service_endpoints = ["Microsoft.KeyVault"]
}
$ terraform apply
azurerm_resource_group.test_rg: Refreshing state... (ID: /<...>/resourceGroups/dns-bug)
azurerm_virtual_network.test_vnet: Refreshing state... (ID: /subscriptions/<...>...rosoft.Network/virtualNetworks/dns-bug)
azurerm_subnet.test_subnet: Refreshing state... (ID: /subscriptions/<...>/dns-bug/subnets/dns-bug-subnet)
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
~ azurerm_virtual_network.test_vnet
dns_servers.#: "1" => "0"
dns_servers.0: "192.168.3.56" => ""
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
azurerm_virtual_network.test_vnet: Modifying... (ID: /subscriptions/<...>...rosoft.Network/virtualNetworks/dns-bug)
dns_servers.#: "1" => "0"
dns_servers.0: "192.168.3.56" => ""
azurerm_virtual_network.test_vnet: Still modifying... (ID: /subscriptions/<...>-...rosoft.Network/virtualNetworks/dns-bug, 10s elapsed)
azurerm_virtual_network.test_vnet: Modifications complete after 11s (ID: /subscriptions/<...>-...rosoft.Network/virtualNetworks/dns-bug)
Terraform should remove DNS IP which was added manually but leave SE endpoints for KV
Terraform removes DNS IP that was added manually and also all Service Endpoints
I have encountered a similar issue in two different environments. In both the cases modifying VNet custom DNS resulted in invisible (neither terraform plan nor apply outputs) removal of VNet service endpoints.
Terraform: v0.11.10
AzureRM Provider: v1.21.0
Follow-up to above post: Running terraform again detects that service endpoints are missing and creates them as per resource definitions.