Skip to content

Commit

Permalink
azurerm_kubernetes_cluster - mark dns_zone_id optional (#20341)
Browse files Browse the repository at this point in the history
* `azurerm_kubernetes_cluster` - mark `dns_zone_id` optional

* update

* fix testcase
  • Loading branch information
ms-henglu authored Feb 16, 2023
1 parent ce7ea8a commit c6f7554
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ func TestAccKubernetesCluster_webAppRouting(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.webAppRoutingWithDnsZone(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

Expand Down Expand Up @@ -2256,7 +2263,7 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) webAppRouting(data acceptance.TestData) string {
func (KubernetesClusterResource) webAppRoutingWithDnsZone(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -2295,6 +2302,45 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) webAppRouting(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}
resource "azurerm_dns_zone" "test" {
name = "acctestzone%d.com"
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 = ""
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) webAppRoutingDisabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
27 changes: 18 additions & 9 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,12 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"dns_zone_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: dnsValidate.ValidateDnsZoneID,
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.Any(
dnsValidate.ValidateDnsZoneID,
validation.StringIsEmpty,
),
},
},
},
Expand Down Expand Up @@ -3705,23 +3708,29 @@ func base64IsEncoded(data string) bool {
}

func expandKubernetesClusterIngressProfile(d *pluginsdk.ResourceData, input []interface{}) *managedclusters.ManagedClusterIngressProfile {
if (len(input) == 0 || input[0] == nil) && d.HasChange("web_app_routing") {
if len(input) == 0 && d.HasChange("web_app_routing") {
return &managedclusters.ManagedClusterIngressProfile{
WebAppRouting: &managedclusters.ManagedClusterIngressProfileWebAppRouting{
Enabled: utils.Bool(false),
},
}
} else if len(input) == 0 || input[0] == nil {
} else if len(input) == 0 {
return nil
}

config := input[0].(map[string]interface{})
return &managedclusters.ManagedClusterIngressProfile{
out := managedclusters.ManagedClusterIngressProfile{
WebAppRouting: &managedclusters.ManagedClusterIngressProfileWebAppRouting{
Enabled: utils.Bool(true),
DnsZoneResourceId: utils.String(config["dns_zone_id"].(string)),
Enabled: utils.Bool(true),
},
}
if input[0] != nil {
config := input[0].(map[string]interface{})
dnsZoneResourceId := config["dns_zone_id"].(string)
if dnsZoneResourceId != "" {
out.WebAppRouting.DnsZoneResourceId = utils.String(dnsZoneResourceId)
}
}
return &out
}

func flattenKubernetesClusterIngressProfile(input *managedclusters.ManagedClusterIngressProfile) []interface{} {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ A `sysctl_config` block supports the following:

A `web_app_routing` block supports the following:

* `dns_zone_id` - (Required) Specifies the ID of the DNS Zone in which DNS entries are created for applications deployed to the cluster when Web App Routing is enabled.
* `dns_zone_id` - (Required) Specifies the ID of the DNS Zone in which DNS entries are created for applications deployed to the cluster when Web App Routing is enabled. For Bring-Your-Own DNS zones this property should be set to an empty string `""`.

---

Expand Down

0 comments on commit c6f7554

Please sign in to comment.