Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_kubernetes_cluster - mark dns_zone_id optional #20341

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,43 @@ 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 {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've fixed it.

}
`, 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
20 changes: 13 additions & 7 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
Schema: map[string]*pluginsdk.Schema{
"dns_zone_id": {
Type: pluginsdk.TypeString,
Required: true,
Optional: true,
ValidateFunc: dnsValidate.ValidateDnsZoneID,
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved
},
},
Expand Down Expand Up @@ -3705,23 +3705,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` - (Optional) 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.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

---

Expand Down