From f87450cabbe9a2c0dc6f972998df6ddb044f852f Mon Sep 17 00:00:00 2001 From: stephybun Date: Thu, 29 Feb 2024 09:28:13 +0100 Subject: [PATCH] allow private dns for web app routing (#25038) --- .../kubernetes_cluster_other_resource_test.go | 55 +++++++++++++++++++ .../containers/kubernetes_cluster_resource.go | 1 + 2 files changed, 56 insertions(+) diff --git a/internal/services/containers/kubernetes_cluster_other_resource_test.go b/internal/services/containers/kubernetes_cluster_other_resource_test.go index ee6ea9416e7a..c56256236b61 100644 --- a/internal/services/containers/kubernetes_cluster_other_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_other_resource_test.go @@ -908,6 +908,22 @@ func TestAccKubernetesCluster_webAppRouting(t *testing.T) { }) } +func TestAccKubernetesCluster_webAppRoutingPrivateDNS(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") + r := KubernetesClusterResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.webAppRoutingPrivateDNS(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("web_app_routing.0.web_app_routing_identity.#").HasValue("1"), + ), + }, + data.ImportStep(), + }) +} + func TestAccKubernetesCluster_azureMonitorKubernetesMetrics(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") r := KubernetesClusterResource{} @@ -2923,6 +2939,45 @@ resource "azurerm_kubernetes_cluster" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } +func (KubernetesClusterResource) webAppRoutingPrivateDNS(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-aks-%d" + location = "%s" +} + +resource "azurerm_private_dns_zone" "test" { + name = "privatelink.%s.azmk8s.io" + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_kubernetes_cluster" "test" { + name = "acctestaks%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + dns_prefix = "acctestaks%d" + + default_node_pool { + name = "default" + node_count = 1 + vm_size = "Standard_DS2_v2" + } + + identity { + type = "SystemAssigned" + } + + web_app_routing { + dns_zone_id = azurerm_private_dns_zone.test.id + } +} + `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) +} + func (KubernetesClusterResource) customCATrustEnabled(data acceptance.TestData, enabled bool) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/internal/services/containers/kubernetes_cluster_resource.go b/internal/services/containers/kubernetes_cluster_resource.go index 2e6a93c3a2a4..cf81c00711e1 100644 --- a/internal/services/containers/kubernetes_cluster_resource.go +++ b/internal/services/containers/kubernetes_cluster_resource.go @@ -489,6 +489,7 @@ func resourceKubernetesCluster() *pluginsdk.Resource { Required: true, ValidateFunc: validation.Any( dnsValidate.ValidateDnsZoneID, + privatezones.ValidatePrivateDnsZoneID, validation.StringIsEmpty, ), },