Skip to content

Commit

Permalink
azurerm_kubernetes_cluster - remove default_node_pool.node_taints
Browse files Browse the repository at this point in the history
… for 4.0 and rename `enable_*` to `*_enabled` (#24167)

* remove node_taints in v4.0

* rename enable_* to *_enabled

* goimports
  • Loading branch information
stephybun authored Jan 4, 2024
1 parent f5c9d85 commit 1c08aae
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/zones"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-preview/agentpools"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -22,7 +23,7 @@ import (
)

func dataSourceKubernetesClusterNodePool() *pluginsdk.Resource {
return &pluginsdk.Resource{
dataSource := &pluginsdk.Resource{
Read: dataSourceKubernetesClusterNodePoolRead,

Timeouts: &pluginsdk.ResourceTimeout{
Expand All @@ -44,18 +45,6 @@ func dataSourceKubernetesClusterNodePool() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

// TODO 4.0: change this from enable_* to *_enabled
"enable_auto_scaling": {
Type: pluginsdk.TypeBool,
Computed: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_node_public_ip": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"eviction_policy": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -159,6 +148,28 @@ func dataSourceKubernetesClusterNodePool() *pluginsdk.Resource {
"zones": commonschema.ZonesMultipleComputed(),
},
}

if features.FourPointOhBeta() {
dataSource.Schema["auto_scaling_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Computed: true,
}
dataSource.Schema["node_public_ip_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Computed: true,
}
} else {
dataSource.Schema["enable_auto_scaling"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Computed: true,
}
dataSource.Schema["enable_node_public_ip"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Computed: true,
}
}

return dataSource
}

func dataSourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -199,8 +210,13 @@ func dataSourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta int
props := model.Properties
d.Set("zones", zones.FlattenUntyped(props.AvailabilityZones))

d.Set("enable_auto_scaling", props.EnableAutoScaling)
d.Set("enable_node_public_ip", props.EnableNodePublicIP)
if features.FourPointOhBeta() {
d.Set("auto_scaling_enabled", props.EnableAutoScaling)
d.Set("node_public_ip_enabled", props.EnableNodePublicIP)
} else {
d.Set("enable_auto_scaling", props.EnableAutoScaling)
d.Set("enable_node_public_ip", props.EnableNodePublicIP)
}

evictionPolicy := ""
if props.ScaleSetEvictionPolicy != nil && *props.ScaleSetEvictionPolicy != "" {
Expand Down
101 changes: 68 additions & 33 deletions internal/services/containers/kubernetes_cluster_node_pool_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,6 @@ func resourceKubernetesClusterNodePoolSchema() map[string]*pluginsdk.Schema {
Optional: true,
},

"enable_auto_scaling": {
Type: pluginsdk.TypeBool,
Optional: true,
},

"enable_host_encryption": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
},

"enable_node_public_ip": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
},

"eviction_policy": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -396,6 +379,42 @@ func resourceKubernetesClusterNodePoolSchema() map[string]*pluginsdk.Schema {
string(agentpools.OSSKUWindowsTwoZeroOneNine),
string(agentpools.OSSKUWindowsTwoZeroTwoTwo),
}, false)

s["enable_auto_scaling"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
}

s["enable_node_public_ip"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
}

s["enable_host_encryption"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
}
}

if features.FourPointOhBeta() {
s["auto_scaling_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
}

s["node_public_ip_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
}

s["host_encryption_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
}
}

return s
Expand Down Expand Up @@ -454,6 +473,17 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int

count := d.Get("node_count").(int)
enableAutoScaling := d.Get("enable_auto_scaling").(bool)
if features.FourPointOhBeta() {
enableAutoScaling = d.Get("auto_scaling_enabled").(bool)
}
hostEncryption := d.Get("enable_host_encryption").(bool)
if features.FourPointOhBeta() {
hostEncryption = d.Get("host_encryption_enabled").(bool)
}
nodeIp := d.Get("enable_node_public_ip").(bool)
if features.FourPointOhBeta() {
nodeIp = d.Get("node_public_ip_enabled").(bool)
}
evictionPolicy := d.Get("eviction_policy").(string)
mode := agentpools.AgentPoolMode(d.Get("mode").(string))
osType := d.Get("os_type").(string)
Expand All @@ -466,9 +496,9 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int
EnableAutoScaling: pointer.To(enableAutoScaling),
EnableCustomCATrust: pointer.To(d.Get("custom_ca_trust_enabled").(bool)),
EnableFIPS: pointer.To(d.Get("fips_enabled").(bool)),
EnableEncryptionAtHost: pointer.To(d.Get("enable_host_encryption").(bool)),
EnableEncryptionAtHost: pointer.To(hostEncryption),
EnableUltraSSD: pointer.To(d.Get("ultra_ssd_enabled").(bool)),
EnableNodePublicIP: pointer.To(d.Get("enable_node_public_ip").(bool)),
EnableNodePublicIP: pointer.To(nodeIp),
KubeletDiskType: pointer.To(agentpools.KubeletDiskType(d.Get("kubelet_disk_type").(string))),
Mode: pointer.To(mode),
ScaleSetPriority: pointer.To(agentpools.ScaleSetPriority(d.Get("priority").(string))),
Expand Down Expand Up @@ -688,23 +718,22 @@ func resourceKubernetesClusterNodePoolUpdate(d *pluginsdk.ResourceData, meta int
log.Printf("[DEBUG] Determining delta for existing %s..", *id)

// delta patching
if d.HasChange("enable_auto_scaling") {
enableAutoScaling = d.Get("enable_auto_scaling").(bool)
props.EnableAutoScaling = utils.Bool(enableAutoScaling)
}

if d.HasChange("enable_host_encryption") {
props.EnableEncryptionAtHost = utils.Bool(d.Get("enable_host_encryption").(bool))
if features.FourPointOhBeta() {
if d.HasChange("auto_scaling_enabled") {
enableAutoScaling = d.Get("auto_scaling_enabled").(bool)
props.EnableAutoScaling = utils.Bool(enableAutoScaling)
}
} else {
if d.HasChange("enable_auto_scaling") {
enableAutoScaling = d.Get("enable_auto_scaling").(bool)
props.EnableAutoScaling = utils.Bool(enableAutoScaling)
}
}

if d.HasChange("custom_ca_trust_enabled") {
props.EnableCustomCATrust = utils.Bool(d.Get("custom_ca_trust_enabled").(bool))
}

if d.HasChange("enable_node_public_ip") {
props.EnableNodePublicIP = utils.Bool(d.Get("enable_node_public_ip").(bool))
}

if d.HasChange("max_count") || d.Get("enable_auto_scaling").(bool) {
props.MaxCount = utils.Int64(int64(d.Get("max_count").(int)))
}
Expand Down Expand Up @@ -852,9 +881,15 @@ func resourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta inter
if model := resp.Model; model != nil && model.Properties != nil {
props := model.Properties
d.Set("zones", zones.FlattenUntyped(props.AvailabilityZones))
d.Set("enable_auto_scaling", props.EnableAutoScaling)
d.Set("enable_node_public_ip", props.EnableNodePublicIP)
d.Set("enable_host_encryption", props.EnableEncryptionAtHost)
if features.FourPointOhBeta() {
d.Set("auto_scaling_enabled", props.EnableAutoScaling)
d.Set("node_public_ip_enabled", props.EnableNodePublicIP)
d.Set("host_encryption_enabled", props.EnableEncryptionAtHost)
} else {
d.Set("enable_auto_scaling", props.EnableAutoScaling)
d.Set("enable_node_public_ip", props.EnableNodePublicIP)
d.Set("enable_host_encryption", props.EnableEncryptionAtHost)
}
d.Set("custom_ca_trust_enabled", props.EnableCustomCATrust)
d.Set("fips_enabled", props.EnableFIPS)
d.Set("ultra_ssd_enabled", props.EnableUltraSSD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,6 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{}
"default_node_pool.0.kubelet_config",
"default_node_pool.0.linux_os_config",
"default_node_pool.0.max_pods",
"default_node_pool.0.node_taints",
"default_node_pool.0.only_critical_addons_enabled",
"default_node_pool.0.os_disk_size_gb",
"default_node_pool.0.os_disk_type",
Expand Down
101 changes: 75 additions & 26 deletions internal/services/containers/kubernetes_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,6 @@ func SchemaDefaultNodePool() *pluginsdk.Schema {
Optional: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_auto_scaling": {
Type: pluginsdk.TypeBool,
Optional: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_node_public_ip": {
Type: pluginsdk.TypeBool,
Optional: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_host_encryption": {
Type: pluginsdk.TypeBool,
Optional: true,
},

"kubelet_config": schemaNodePoolKubeletConfig(),

"linux_os_config": schemaNodePoolLinuxOSConfig(),
Expand Down Expand Up @@ -305,6 +287,48 @@ func SchemaDefaultNodePool() *pluginsdk.Schema {
string(agentpools.OSSKUWindowsTwoZeroOneNine),
string(agentpools.OSSKUWindowsTwoZeroTwoTwo),
}, false)

s["node_taints"] = &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
Deprecated: "This field will be removed in v4.0 of the Azure Provider since the AKS API doesn't allow arbitrary node taints on the default node pool",
}

s["enable_auto_scaling"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
}

s["enable_node_public_ip"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
}

s["enable_host_encryption"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
}

}

if features.FourPointOhBeta() {
s["auto_scaling_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
}

s["node_public_ip_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
}

s["host_encryption_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
}
}

return s
Expand Down Expand Up @@ -942,12 +966,18 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]managedclusters.Manage

raw := input[0].(map[string]interface{})
enableAutoScaling := raw["enable_auto_scaling"].(bool)
if features.FourPointOhBeta() {
enableAutoScaling = raw["auto_scaling_enabled"].(bool)
}
nodeLabelsRaw := raw["node_labels"].(map[string]interface{})
nodeLabels := expandNodeLabels(nodeLabelsRaw)
nodeTaintsRaw := raw["node_taints"].([]interface{})
nodeTaints := utils.ExpandStringSlice(nodeTaintsRaw)
var nodeTaints *[]string
if !features.FourPointOhBeta() {
nodeTaintsRaw := raw["node_taints"].([]interface{})
nodeTaints = utils.ExpandStringSlice(nodeTaintsRaw)
}

if len(*nodeTaints) != 0 {
if !features.FourPointOhBeta() && len(*nodeTaints) != 0 {
return nil, fmt.Errorf("The AKS API has removed support for tainting all nodes in the default node pool and it is no longer possible to configure this. To taint a node pool, create a separate one.")
}

Expand All @@ -958,12 +988,22 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]managedclusters.Manage

t := raw["tags"].(map[string]interface{})

nodePublicIp := raw["enable_node_public_ip"].(bool)
if features.FourPointOhBeta() {
nodePublicIp = raw["node_public_ip_enabled"].(bool)
}

hostEncryption := raw["enable_host_encryption"].(bool)
if features.FourPointOhBeta() {
nodePublicIp = raw["host_encryption_enabled"].(bool)
}

profile := managedclusters.ManagedClusterAgentPoolProfile{
EnableAutoScaling: utils.Bool(enableAutoScaling),
EnableCustomCATrust: utils.Bool(raw["custom_ca_trust_enabled"].(bool)),
EnableFIPS: utils.Bool(raw["fips_enabled"].(bool)),
EnableNodePublicIP: utils.Bool(raw["enable_node_public_ip"].(bool)),
EnableEncryptionAtHost: utils.Bool(raw["enable_host_encryption"].(bool)),
EnableNodePublicIP: utils.Bool(nodePublicIp),
EnableEncryptionAtHost: utils.Bool(hostEncryption),
KubeletDiskType: pointer.To(managedclusters.KubeletDiskType(raw["kubelet_disk_type"].(string))),
Name: raw["name"].(string),
NodeLabels: nodeLabels,
Expand Down Expand Up @@ -1493,9 +1533,6 @@ func FlattenDefaultNodePool(input *[]managedclusters.ManagedClusterAgentPoolProf
networkProfile := flattenClusterPoolNetworkProfile(agentPool.NetworkProfile)

out := map[string]interface{}{
"enable_auto_scaling": enableAutoScaling,
"enable_node_public_ip": enableNodePublicIP,
"enable_host_encryption": enableHostEncryption,
"custom_ca_trust_enabled": customCaTrustEnabled,
"fips_enabled": enableFIPS,
"gpu_instance": gpuInstanceProfile,
Expand Down Expand Up @@ -1534,6 +1571,18 @@ func FlattenDefaultNodePool(input *[]managedclusters.ManagedClusterAgentPoolProf
"capacity_reservation_group_id": capacityReservationGroupId,
}

if features.FourPointOhBeta() {
out["auto_scaling_enabled"] = enableAutoScaling
out["node_public_ip_enabled"] = enableNodePublicIP
out["host_encryption_enabled"] = enableHostEncryption
}

if !features.FourPointOhBeta() {
out["enable_auto_scaling"] = enableAutoScaling
out["enable_node_public_ip"] = enableNodePublicIP
out["enable_host_encryption"] = enableHostEncryption
}

return &[]interface{}{
out,
}, nil
Expand Down
Loading

0 comments on commit 1c08aae

Please sign in to comment.