Skip to content

Commit

Permalink
kubernetes_cluster: Support for gateway_name for Application Gate…
Browse files Browse the repository at this point in the history
…way add-on (#11984)
  • Loading branch information
aristosvo authored Jun 1, 2021
1 parent e2700d9 commit 02c49a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
15 changes: 15 additions & 0 deletions azurerm/internal/services/containers/kubernetes_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ func schemaKubernetesAddOnProfiles() *pluginsdk.Schema {
ConflictsWith: []string{"addon_profile.0.ingress_application_gateway.0.subnet_cidr", "addon_profile.0.ingress_application_gateway.0.subnet_id"},
ValidateFunc: applicationGatewayValidate.ApplicationGatewayID,
},
"gateway_name": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"subnet_cidr": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -319,6 +324,10 @@ func expandKubernetesAddOnProfiles(input []interface{}, env azure.Environment) (
config["applicationGatewayId"] = utils.String(gatewayId.(string))
}

if gatewayName, ok := value["gateway_name"]; ok && gatewayName != "" {
config["applicationGatewayName"] = utils.String(gatewayName.(string))
}

if subnetCIDR, ok := value["subnet_cidr"]; ok && subnetCIDR != "" {
config["subnetCIDR"] = utils.String(subnetCIDR.(string))
}
Expand Down Expand Up @@ -461,6 +470,11 @@ func flattenKubernetesAddOnProfiles(profile map[string]*containerservice.Managed
gatewayId = *v
}

gatewayName := ""
if v := kubernetesAddonProfilelocateInConfig(ingressApplicationGateway.Config, "applicationGatewayName"); v != nil {
gatewayName = *v
}

effectiveGatewayId := ""
if v := kubernetesAddonProfilelocateInConfig(ingressApplicationGateway.Config, "effectiveApplicationGatewayId"); v != nil {
effectiveGatewayId = *v
Expand All @@ -481,6 +495,7 @@ func flattenKubernetesAddOnProfiles(profile map[string]*containerservice.Managed
ingressApplicationGateways = append(ingressApplicationGateways, map[string]interface{}{
"enabled": enabled,
"gateway_id": gatewayId,
"gateway_name": gatewayName,
"effective_gateway_id": effectiveGatewayId,
"subnet_cidr": subnetCIDR,
"subnet_id": subnetId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func testAccKubernetesCluster_addonProfileIngressApplicationGateway_subnetCIDR(t
Config: r.addonProfileIngressApplicationGatewaySubnetCIDRConfig(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("addon_profile.0.ingress_application_gateway.0.gateway_name").Exists(),
check.That(data.ResourceName).Key("addon_profile.0.ingress_application_gateway.0.effective_gateway_id").Exists(),
check.That(data.ResourceName).Key("addon_profile.0.ingress_application_gateway.0.subnet_cidr").HasValue(addOnAppGatewaySubnetCIDR),
),
Expand Down Expand Up @@ -332,6 +333,7 @@ func testAccKubernetesCluster_addonProfileIngressApplicationGateway_subnetId(t *
Config: r.addonProfileIngressApplicationGatewaySubnetIdConfig(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("addon_profile.0.ingress_application_gateway.0.gateway_name").Exists(),
check.That(data.ResourceName).Key("addon_profile.0.ingress_application_gateway.0.effective_gateway_id").Exists(),
),
},
Expand Down Expand Up @@ -968,8 +970,9 @@ resource "azurerm_kubernetes_cluster" "test" {
addon_profile {
ingress_application_gateway {
enabled = true
subnet_cidr = "%s"
enabled = true
gateway_name = "acctestgwn%d"
subnet_cidr = "%s"
}
kube_dashboard {
enabled = false
Expand All @@ -980,7 +983,7 @@ resource "azurerm_kubernetes_cluster" "test" {
type = "SystemAssigned"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, addOnAppGatewaySubnetCIDR)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, addOnAppGatewaySubnetCIDR)
}

func (KubernetesClusterResource) addonProfileIngressApplicationGatewayDisabledConfig(data acceptance.TestData) string {
Expand Down Expand Up @@ -1077,8 +1080,9 @@ resource "azurerm_kubernetes_cluster" "test" {
addon_profile {
ingress_application_gateway {
enabled = true
subnet_id = azurerm_subnet.test.id
enabled = true
gateway_name = "acctestgwn%d"
subnet_id = azurerm_subnet.test.id
}
kube_dashboard {
enabled = false
Expand All @@ -1089,5 +1093,5 @@ resource "azurerm_kubernetes_cluster" "test" {
type = "SystemAssigned"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
2 changes: 2 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ An `ingress_application_gateway` block supports the following:

* `gateway_id` - (Optional) The ID of the Application Gateway to integrate with the ingress controller of this Kubernetes Cluster. See [this](https://docs.microsoft.com/en-us/azure/application-gateway/tutorial-ingress-controller-add-on-existing) page for further details.

* `gateway_name` - (Optional) The name of the Application Gateway to be used or created in the Nodepool Resource Group, which in turn will be integrated with the ingress controller of this Kubernetes Cluster. See [this](https://docs.microsoft.com/en-us/azure/application-gateway/tutorial-ingress-controller-add-on-new) page for further details.

* `subnet_cidr` - (Optional) The subnet CIDR to be used to create an Application Gateway, which in turn will be integrated with the ingress controller of this Kubernetes Cluster. See [this](https://docs.microsoft.com/en-us/azure/application-gateway/tutorial-ingress-controller-add-on-new) page for further details.

* `subnet_id` - (Optional) The ID of the subnet on which to create an Application Gateway, which in turn will be integrated with the ingress controller of this Kubernetes Cluster. See [this](https://docs.microsoft.com/en-us/azure/application-gateway/tutorial-ingress-controller-add-on-new) page for further details.
Expand Down

0 comments on commit 02c49a6

Please sign in to comment.