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: support for ingress_application_gateway addon #11376

Merged
merged 18 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 118 additions & 16 deletions azurerm/internal/services/containers/kubernetes_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ import (
"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
commonValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
logAnalyticsValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/validate"
applicationGatewayValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/validate"
subnetValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"

laparse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/parse"
)

const (
// note: the casing on these keys is important
aciConnectorKey = "aciConnectorLinux"
azurePolicyKey = "azurepolicy"
kubernetesDashboardKey = "kubeDashboard"
httpApplicationRoutingKey = "httpApplicationRouting"
omsAgentKey = "omsagent"
aciConnectorKey = "aciConnectorLinux"
azurePolicyKey = "azurepolicy"
kubernetesDashboardKey = "kubeDashboard"
httpApplicationRoutingKey = "httpApplicationRouting"
omsAgentKey = "omsagent"
ingressApplicationGatewayKey = "ingressApplicationGateway"
)

// The AKS API hard-codes which add-ons are supported in which environment
Expand Down Expand Up @@ -155,6 +159,42 @@ func schemaKubernetesAddOnProfiles() *schema.Schema {
},
},
},

"ingress_application_gateway": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
"gateway_id": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"addon_profile.0.ingress_application_gateway.0.subnet_cidr", "addon_profile.0.ingress_application_gateway.0.subnet_id"},
ValidateFunc: applicationGatewayValidate.ApplicationGatewayID,
},
"subnet_cidr": {
markrzasa marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"addon_profile.0.ingress_application_gateway.0.gateway_id", "addon_profile.0.ingress_application_gateway.0.subnet_id"},
ValidateFunc: commonValidate.CIDR,
},
"subnet_id": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"addon_profile.0.ingress_application_gateway.0.gateway_id", "addon_profile.0.ingress_application_gateway.0.subnet_cidr"},
ValidateFunc: subnetValidate.SubnetID,
},
"effective_gateway_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
}
Expand All @@ -166,11 +206,12 @@ func expandKubernetesAddOnProfiles(input []interface{}, env azure.Environment) (
}

profiles := map[string]*containerservice.ManagedClusterAddonProfile{
aciConnectorKey: &disabled,
azurePolicyKey: &disabled,
kubernetesDashboardKey: &disabled,
httpApplicationRoutingKey: &disabled,
omsAgentKey: &disabled,
aciConnectorKey: &disabled,
azurePolicyKey: &disabled,
kubernetesDashboardKey: &disabled,
httpApplicationRoutingKey: &disabled,
omsAgentKey: &disabled,
ingressApplicationGatewayKey: &disabled,
}

if len(input) == 0 || input[0] == nil {
Expand Down Expand Up @@ -249,6 +290,30 @@ func expandKubernetesAddOnProfiles(input []interface{}, env azure.Environment) (
}
}

ingressApplicationGateway := profile["ingress_application_gateway"].([]interface{})
if len(ingressApplicationGateway) > 0 && ingressApplicationGateway[0] != nil {
value := ingressApplicationGateway[0].(map[string]interface{})
config := make(map[string]*string)
enabled := value["enabled"].(bool)

if gatewayId, ok := value["gateway_id"]; ok && gatewayId != "" {
config["applicationGatewayId"] = utils.String(gatewayId.(string))
}

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

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

addonProfiles[ingressApplicationGatewayKey] = &containerservice.ManagedClusterAddonProfile{
Enabled: utils.Bool(enabled),
Config: config,
}
}

return filterUnsupportedKubernetesAddOns(addonProfiles, env)
}

Expand Down Expand Up @@ -365,18 +430,55 @@ func flattenKubernetesAddOnProfiles(profile map[string]*containerservice.Managed
})
}

ingressApplicationGateways := make([]interface{}, 0)
if ingressApplicationGateway := kubernetesAddonProfileLocate(profile, ingressApplicationGatewayKey); ingressApplicationGateway != nil {
enabled := false
if enabledVal := ingressApplicationGateway.Enabled; enabledVal != nil {
enabled = *enabledVal
}

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

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

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

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

ingressApplicationGateways = append(ingressApplicationGateways, map[string]interface{}{
"enabled": enabled,
"gateway_id": gatewayId,
"effective_gateway_id": effectiveGatewayId,
"subnet_cidr": subnetCIDR,
"subnet_id": subnetId,
})
}

// this is a UX hack, since if the top level block isn't defined everything should be turned off
if len(aciConnectors) == 0 && len(azurePolicies) == 0 && len(httpApplicationRoutes) == 0 && len(kubeDashboards) == 0 && len(omsAgents) == 0 {
if len(aciConnectors) == 0 && len(azurePolicies) == 0 && len(httpApplicationRoutes) == 0 && len(kubeDashboards) == 0 && len(omsAgents) == 0 && len(ingressApplicationGateways) == 0 {
return []interface{}{}
}

return []interface{}{
map[string]interface{}{
"aci_connector_linux": aciConnectors,
"azure_policy": azurePolicies,
"http_application_routing": httpApplicationRoutes,
"kube_dashboard": kubeDashboards,
"oms_agent": omsAgents,
"aci_connector_linux": aciConnectors,
"azure_policy": azurePolicies,
"http_application_routing": httpApplicationRoutes,
"kube_dashboard": kubeDashboards,
"oms_agent": omsAgents,
"ingress_application_gateway": ingressApplicationGateways,
},
}
}
Expand Down
Loading