From b86afde2f3a0fa84c26e53c80a84e1015c873e10 Mon Sep 17 00:00:00 2001 From: zhangqiqing <1434071196@qq.com> Date: Tue, 10 May 2022 13:21:43 +0800 Subject: [PATCH 01/10] [init](aks_cluster/node_pool): supports props --- ...ernetes_cluster_node_pool_resource_test.go | 1 + .../kubernetes_cluster_other_resource_test.go | 119 +++++++++++++++++- .../containers/kubernetes_cluster_resource.go | 34 +++++ .../containers/kubernetes_nodepool.go | 61 +++++++++ .../docs/r/kubernetes_cluster.html.markdown | 8 ++ ...kubernetes_cluster_node_pool.html.markdown | 2 + 6 files changed, 220 insertions(+), 5 deletions(-) diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go b/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go index 41d854d46fc9..4506e01c8c13 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go @@ -1895,6 +1895,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { node_count = 3 fips_enabled = true kubelet_disk_type = "OS" + message_of_day = "message_of_day" } `, r.templateConfig(data)) } diff --git a/internal/services/containers/kubernetes_cluster_other_resource_test.go b/internal/services/containers/kubernetes_cluster_other_resource_test.go index 62dec9683399..e9821fc118af 100644 --- a/internal/services/containers/kubernetes_cluster_other_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_other_resource_test.go @@ -283,6 +283,28 @@ func TestAccKubernetesCluster_upgrade(t *testing.T) { }) } +func TestAccKubernetesCluster_scaleDownMode(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") + r := KubernetesClusterResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.scaleDownMode(data, "Delete"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.scaleDownMode(data, "Deallocate"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccKubernetesCluster_tags(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") r := KubernetesClusterResource{} @@ -348,6 +370,28 @@ func TestAccKubernetesCluster_windowsProfileLicense(t *testing.T) { }) } +func TestAccKubernetesCluster_workloadRuntime(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") + r := KubernetesClusterResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.workloadRuntime(data, "OCIContainer"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.workloadRuntime(data, "WasmWasi"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccKubernetesCluster_updateWindowsProfileLicense(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") r := KubernetesClusterResource{} @@ -1182,11 +1226,13 @@ resource "azurerm_kubernetes_cluster" "test" { dns_prefix = "acctestaks%d" default_node_pool { - name = "default" - node_count = 1 - vm_size = "Standard_DS2_v2" - fips_enabled = true - kubelet_disk_type = "OS" + name = "default" + node_count = 1 + vm_size = "Standard_DS2_v2" + fips_enabled = true + kubelet_disk_type = "OS" + message_of_day = "tips_of_message" + message_outbound_ipv6_count = 3 } identity { @@ -1528,6 +1574,38 @@ resource "azurerm_kubernetes_cluster" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } +func (KubernetesClusterResource) workloadRuntime(data acceptance.TestData, workloadRuntime string) string { + return fmt.Sprintf(` + +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-aks-%d" + location = "%s" +} + +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" + workload_runtime = "%s" + } + + identity { + type = "SystemAssigned" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, workloadRuntime) +} + func (KubernetesClusterResource) diskEncryptionConfig(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { @@ -1807,6 +1885,37 @@ resource "azurerm_kubernetes_cluster" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, ultraSSDEnabled) } +func (KubernetesClusterResource) scaleDownMode(data acceptance.TestData, scaleDownMode string) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-aks-%d" + location = "%s" +} + +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" + scale_down_mode = "%s" + } + + identity { + type = "SystemAssigned" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, scaleDownMode) +} + func (KubernetesClusterResource) privateClusterPublicFqdn(data acceptance.TestData, privateClusterPublicFqdnEnabled bool) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/internal/services/containers/kubernetes_cluster_resource.go b/internal/services/containers/kubernetes_cluster_resource.go index 248cc05d25af..194b1c733002 100644 --- a/internal/services/containers/kubernetes_cluster_resource.go +++ b/internal/services/containers/kubernetes_cluster_resource.go @@ -530,6 +530,13 @@ func resourceKubernetesCluster() *pluginsdk.Resource { ValidateFunc: validation.IntBetween(1, 100), ConflictsWith: []string{"network_profile.0.load_balancer_profile.0.outbound_ip_prefix_ids", "network_profile.0.load_balancer_profile.0.outbound_ip_address_ids"}, }, + "managed_outbound_ipv6_count": { + Type: pluginsdk.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntBetween(1, 100), + ConflictsWith: []string{"network_profile.0.load_balancer_profile.0.outbound_ip_prefix_ids", "network_profile.0.load_balancer_profile.0.outbound_ip_address_ids"}, + }, "outbound_ip_prefix_ids": { Type: pluginsdk.TypeSet, Optional: true, @@ -1430,6 +1437,20 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{} loadBalancerProfile.OutboundIPPrefixes = nil } + if key := "network_profile.0.load_balancer_profile.0.managed_outbound_ipv6_count"; d.HasChange(key) { + managedOutboundIPV6Count := d.Get(key).(int) + if loadBalancerProfile.ManagedOutboundIPs == nil { + loadBalancerProfile.ManagedOutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{ + CountIPv6: utils.Int32(int32(managedOutboundIPV6Count)), + } + } + loadBalancerProfile.ManagedOutboundIPs.CountIPv6 = utils.Int32(int32(managedOutboundIPV6Count)) + + // fixes: Load balancer profile must specify one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs. + loadBalancerProfile.OutboundIPs = nil + loadBalancerProfile.OutboundIPPrefixes = nil + } + if key := "network_profile.0.load_balancer_profile.0.outbound_ip_address_ids"; d.HasChange(key) { outboundIPAddress := d.Get(key) if v := outboundIPAddress.(*pluginsdk.Set).List(); len(v) == 0 { @@ -2206,6 +2227,15 @@ func expandLoadBalancerProfile(d []interface{}) *containerservice.ManagedCluster } } + if ipv6Count := config["managed_outbound_ipv6_count"]; ipv6Count != nil { + if c := int32(ipv6Count.(int)); c > 0 { + if profile.ManagedOutboundIPs == nil { + profile.ManagedOutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{CountIPv6: &c} + } + profile.ManagedOutboundIPs.CountIPv6 = &c + } + } + if ipPrefixes := idsToResourceReferences(config["outbound_ip_prefix_ids"]); ipPrefixes != nil { profile.OutboundIPPrefixes = &containerservice.ManagedClusterLoadBalancerProfileOutboundIPPrefixes{PublicIPPrefixes: ipPrefixes} } @@ -2337,6 +2367,10 @@ func flattenKubernetesClusterNetworkProfile(profile *containerservice.NetworkPro if count := ips.Count; count != nil { lb["managed_outbound_ip_count"] = count } + + if countIPv6 := ips.CountIPv6; countIPv6 != nil { + lb["managed_outbound_ipv6_count"] = countIPv6 + } } if oip := lbp.OutboundIPs; oip != nil { diff --git a/internal/services/containers/kubernetes_nodepool.go b/internal/services/containers/kubernetes_nodepool.go index 18d2cfe1e208..957103b2b0cf 100644 --- a/internal/services/containers/kubernetes_nodepool.go +++ b/internal/services/containers/kubernetes_nodepool.go @@ -108,6 +108,11 @@ func SchemaDefaultNodePool() *pluginsdk.Schema { ForceNew: true, }, + "message_of_day": { + Type: pluginsdk.TypeString, + Optional: true, + }, + "min_count": { Type: pluginsdk.TypeInt, Optional: true, @@ -193,31 +198,55 @@ func SchemaDefaultNodePool() *pluginsdk.Schema { ForceNew: true, ValidateFunc: azure.ValidateResourceID, }, + "orchestrator_version": { Type: pluginsdk.TypeString, Optional: true, Computed: true, ValidateFunc: validation.StringIsNotEmpty, }, + "pod_subnet_id": { Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ValidateFunc: networkValidate.SubnetID, }, + "proximity_placement_group_id": { Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ValidateFunc: computeValidate.ProximityPlacementGroupID, }, + "only_critical_addons_enabled": { Type: pluginsdk.TypeBool, Optional: true, ForceNew: true, }, + "scale_down_mode": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + Default: string(containerservice.ScaleDownModeDelete), + ValidateFunc: validation.StringInSlice([]string{ + string(containerservice.ScaleDownModeDeallocate), + string(containerservice.ScaleDownModeDelete), + }, false), + }, + "upgrade_settings": upgradeSettingsSchema(), + + "workload_runtime": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(containerservice.WorkloadRuntimeOCIContainer), + string(containerservice.WorkloadRuntimeWasmWasi), + }, false), + }, } s["zones"] = commonschema.ZonesMultipleOptionalForceNew() @@ -589,6 +618,7 @@ func ConvertDefaultNodePoolToAgentPool(input *[]containerservice.ManagedClusterA MaxPods: defaultCluster.MaxPods, OsType: defaultCluster.OsType, MaxCount: defaultCluster.MaxCount, + MessageOfTheDay: defaultCluster.MessageOfTheDay, MinCount: defaultCluster.MinCount, EnableAutoScaling: defaultCluster.EnableAutoScaling, EnableFIPS: defaultCluster.EnableFIPS, @@ -606,8 +636,10 @@ func ConvertDefaultNodePoolToAgentPool(input *[]containerservice.ManagedClusterA NodeLabels: defaultCluster.NodeLabels, NodeTaints: defaultCluster.NodeTaints, PodSubnetID: defaultCluster.PodSubnetID, + ScaleDownMode: defaultCluster.ScaleDownMode, Tags: defaultCluster.Tags, UpgradeSettings: defaultCluster.UpgradeSettings, + WorkloadRuntime: defaultCluster.WorkloadRuntime, }, } } @@ -639,6 +671,7 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]containerservice.Manag EnableNodePublicIP: utils.Bool(raw["enable_node_public_ip"].(bool)), EnableEncryptionAtHost: utils.Bool(raw["enable_host_encryption"].(bool)), KubeletDiskType: containerservice.KubeletDiskType(raw["kubelet_disk_type"].(string)), + MessageOfTheDay: utils.String(raw["message_of_day"].(string)), Name: utils.String(raw["name"].(string)), NodeLabels: nodeLabels, NodeTaints: nodeTaints, @@ -693,6 +726,11 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]containerservice.Manag profile.PodSubnetID = utils.String(podSubnetID) } + profile.ScaleDownMode = containerservice.ScaleDownModeDelete + if scaleOfMode := raw["scale_down_mode"].(string); scaleOfMode != "" { + profile.ScaleDownMode = containerservice.ScaleDownMode(scaleOfMode) + } + if ultraSSDEnabled, ok := raw["ultra_ssd_enabled"]; ok { profile.EnableUltraSSD = utils.Bool(ultraSSDEnabled.(bool)) } @@ -709,6 +747,11 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]containerservice.Manag profile.ProximityPlacementGroupID = utils.String(proximityPlacementGroupId) } + profile.WorkloadRuntime = "" + if workloadRunTime := raw["workload_runtime"].(string); workloadRunTime != "" { + profile.WorkloadRuntime = containerservice.WorkloadRuntime(workloadRunTime) + } + count := raw["node_count"].(int) maxCount := raw["max_count"].(int) minCount := raw["min_count"].(int) @@ -989,6 +1032,11 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro maxPods = int(*agentPool.MaxPods) } + messageOfTheDay := "" + if agentPool.MessageOfTheDay != nil { + messageOfTheDay = *agentPool.MessageOfTheDay + } + minCount := 0 if agentPool.MinCount != nil { minCount = int(*agentPool.MinCount) @@ -1051,11 +1099,21 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro proximityPlacementGroupId = *agentPool.ProximityPlacementGroupID } + scaleDownMode := containerservice.ScaleDownModeDelete + if agentPool.ScaleDownMode != "" { + scaleDownMode = agentPool.ScaleDownMode + } + vmSize := "" if agentPool.VMSize != nil { vmSize = *agentPool.VMSize } + workloadRunTime := "" + if agentPool.WorkloadRuntime != "" { + workloadRunTime = string(agentPool.WorkloadRuntime) + } + upgradeSettings := flattenUpgradeSettings(agentPool.UpgradeSettings) linuxOSConfig, err := flattenAgentPoolLinuxOSConfig(agentPool.LinuxOSConfig) if err != nil { @@ -1070,6 +1128,7 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro "kubelet_disk_type": string(agentPool.KubeletDiskType), "max_count": maxCount, "max_pods": maxPods, + "message_of_day": messageOfTheDay, "min_count": minCount, "name": name, "node_count": count, @@ -1079,10 +1138,12 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro "os_disk_size_gb": osDiskSizeGB, "os_disk_type": string(osDiskType), "os_sku": string(agentPool.OsSKU), + "scale_down_mode": string(scaleDownMode), "tags": tags.Flatten(agentPool.Tags), "type": string(agentPool.Type), "ultra_ssd_enabled": enableUltraSSD, "vm_size": vmSize, + "workload_runtime": workloadRunTime, "pod_subnet_id": podSubnetId, "orchestrator_version": orchestratorVersion, "proximity_placement_group_id": proximityPlacementGroupId, diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 13efd170d47c..866da047406e 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -334,6 +334,8 @@ A `default_node_pool` block supports the following: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. +* `message_of_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It must not be specified for Windows nodes. It must be a static string (i.e., will be printed raw and not be executed as a script). + * `node_public_ip_prefix_id` - (Optional) Resource ID for the Public IP Addresses Prefix for the nodes in this Node Pool. `enable_node_public_ip` should be `true`. Changing this forces a new resource to be created. * `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the Default Node Pool. @@ -354,6 +356,8 @@ A `default_node_pool` block supports the following: -> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/PodSubnetPreview` is enabled and the Resource Provider is re-registered, see [the documentation](https://docs.microsoft.com/en-us/azure/aks/configure-azure-cni#register-the-podsubnetpreview-preview-feature) for more information. +* `scale_down_mode` - This also effects the cluster autoscaler behavior. If not specified, it defaults to Delete. Possible values include: 'ScaleDownModeDelete', 'ScaleDownModeDeallocate'. Changing this forces a new resource to be created. + * `type` - (Optional) The type of Node Pool which should be created. Possible values are `AvailabilitySet` and `VirtualMachineScaleSets`. Defaults to `VirtualMachineScaleSets`. * `tags` - (Optional) A mapping of tags to assign to the Node Pool. @@ -384,6 +388,8 @@ If `enable_auto_scaling` is set to `false`, then the following fields can also b -> **Note:** If `enable_auto_scaling` is set to `false` both `min_count` and `max_count` fields need to be set to `null` or omitted from the configuration. +* `workload_runtime` - (Optional) Used to specify the workload runtime. Allowed values are `OCIContainer` and `WasmWasi`. + * `zones` - (Optional) Specifies a list of Availability Zones in which this Kubernetes Cluster should be located. Changing this forces a new Kubernetes Cluster to be created. -> **Note:** This requires that the `type` is set to `VirtualMachineScaleSets` and that `load_balancer_sku` is set to `standard`. @@ -546,6 +552,8 @@ A `load_balancer_profile` block supports the following: * `managed_outbound_ip_count` - (Optional) Count of desired managed outbound IPs for the cluster load balancer. Must be between `1` and `100` inclusive. +* `managed_outbound_ipv6_count` - (Optional) The desired number of IPv6 outbound IPs created/managed by Azure for the cluster load balancer. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 0 for single-stack and 1 for dual-stack. + * `outbound_ip_address_ids` - (Optional) The ID of the Public IP Addresses which should be used for outbound communication for the cluster load balancer. -> **Note:** Set `outbound_ip_address_ids` to an empty slice `[]` in order to unlink it from the cluster. Unlinking a `outbound_ip_address_ids` will revert the load balancing for the cluster back to a managed one. diff --git a/website/docs/r/kubernetes_cluster_node_pool.html.markdown b/website/docs/r/kubernetes_cluster_node_pool.html.markdown index 4e084b4eddb2..8ac8dafcb5b9 100644 --- a/website/docs/r/kubernetes_cluster_node_pool.html.markdown +++ b/website/docs/r/kubernetes_cluster_node_pool.html.markdown @@ -95,6 +95,8 @@ The following arguments are supported: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. +* `message_of_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It must not be specified for Windows nodes. It must be a static string (i.e., will be printed raw and not be executed as a script). + * `mode` - (Optional) Should this Node Pool be used for System or User resources? Possible values are `System` and `User`. Defaults to `User`. * `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in this Node Pool. From 864e3ffd9dfe7a2bdf4a05005b58853813bf26f7 Mon Sep 17 00:00:00 2001 From: zhangqiqing <1434071196@qq.com> Date: Tue, 10 May 2022 14:32:19 +0800 Subject: [PATCH 02/10] [add]add messageOfDay in aks_cluster_node_pool --- .../kubernetes_cluster_node_pool_resource.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource.go b/internal/services/containers/kubernetes_cluster_node_pool_resource.go index ad5fa953d21d..a923897a6a72 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource.go @@ -141,6 +141,12 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource { ForceNew: true, }, + "message_of_day": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "message", + }, + "mode": { Type: pluginsdk.TypeString, Optional: true, @@ -373,6 +379,7 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int EnableUltraSSD: utils.Bool(d.Get("ultra_ssd_enabled").(bool)), EnableNodePublicIP: utils.Bool(d.Get("enable_node_public_ip").(bool)), KubeletDiskType: containerservice.KubeletDiskType(d.Get("kubelet_disk_type").(string)), + MessageOfTheDay: utils.String(d.Get("message_of_day").(string)), Mode: mode, ScaleSetPriority: containerservice.ScaleSetPriority(priority), Tags: tags.Expand(t), @@ -576,6 +583,10 @@ func resourceKubernetesClusterNodePoolUpdate(d *pluginsdk.ResourceData, meta int props.MaxCount = utils.Int32(int32(d.Get("max_count").(int))) } + if d.HasChange("message_of_day") { + props.MessageOfTheDay = utils.String(d.Get("message_of_day").(string)) + } + if d.HasChange("mode") { props.Mode = containerservice.AgentPoolMode(d.Get("mode").(string)) } @@ -760,6 +771,12 @@ func resourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta inter } d.Set("max_count", maxCount) + messageOfTheDay := "" + if props.MessageOfTheDay != nil { + messageOfTheDay = *props.MessageOfTheDay + } + d.Set("message_of_day", messageOfTheDay) + maxPods := 0 if props.MaxPods != nil { maxPods = int(*props.MaxPods) From 0d65663a0abc097d12ce84f465cb2647b7ff9ad7 Mon Sep 17 00:00:00 2001 From: zhangqiqing <1434071196@qq.com> Date: Tue, 10 May 2022 15:37:52 +0800 Subject: [PATCH 03/10] [style] remove uselless line --- .../containers/kubernetes_cluster_node_pool_resource.go | 1 - internal/services/containers/kubernetes_nodepool.go | 4 ---- 2 files changed, 5 deletions(-) diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource.go b/internal/services/containers/kubernetes_cluster_node_pool_resource.go index a923897a6a72..06927b0a210a 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource.go @@ -144,7 +144,6 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource { "message_of_day": { Type: pluginsdk.TypeString, Optional: true, - Default: "message", }, "mode": { diff --git a/internal/services/containers/kubernetes_nodepool.go b/internal/services/containers/kubernetes_nodepool.go index 957103b2b0cf..1b13cbf5355b 100644 --- a/internal/services/containers/kubernetes_nodepool.go +++ b/internal/services/containers/kubernetes_nodepool.go @@ -198,28 +198,24 @@ func SchemaDefaultNodePool() *pluginsdk.Schema { ForceNew: true, ValidateFunc: azure.ValidateResourceID, }, - "orchestrator_version": { Type: pluginsdk.TypeString, Optional: true, Computed: true, ValidateFunc: validation.StringIsNotEmpty, }, - "pod_subnet_id": { Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ValidateFunc: networkValidate.SubnetID, }, - "proximity_placement_group_id": { Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ValidateFunc: computeValidate.ProximityPlacementGroupID, }, - "only_critical_addons_enabled": { Type: pluginsdk.TypeBool, Optional: true, From 9f869d9ada700a5f0c867275bc058dcca066995c Mon Sep 17 00:00:00 2001 From: zhangqiqing <1434071196@qq.com> Date: Wed, 11 May 2022 00:03:43 +0800 Subject: [PATCH 04/10] [fix] fix message of the day to base 64(encoded) and add foece new according test --- .../kubernetes_cluster_node_pool_resource.go | 24 +++++++++++++++---- ...ernetes_cluster_node_pool_resource_test.go | 2 +- .../kubernetes_cluster_other_resource_test.go | 13 +++++----- .../containers/kubernetes_nodepool.go | 20 ++++++++++++---- .../docs/r/kubernetes_cluster.html.markdown | 4 ++-- ...kubernetes_cluster_node_pool.html.markdown | 2 +- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource.go b/internal/services/containers/kubernetes_cluster_node_pool_resource.go index 06927b0a210a..362834c48c76 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource.go @@ -1,6 +1,7 @@ package containers import ( + "encoding/base64" "fmt" "log" "strings" @@ -142,8 +143,10 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource { }, "message_of_day": { - Type: pluginsdk.TypeString, - Optional: true, + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, }, "mode": { @@ -378,7 +381,6 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int EnableUltraSSD: utils.Bool(d.Get("ultra_ssd_enabled").(bool)), EnableNodePublicIP: utils.Bool(d.Get("enable_node_public_ip").(bool)), KubeletDiskType: containerservice.KubeletDiskType(d.Get("kubelet_disk_type").(string)), - MessageOfTheDay: utils.String(d.Get("message_of_day").(string)), Mode: mode, ScaleSetPriority: containerservice.ScaleSetPriority(priority), Tags: tags.Expand(t), @@ -446,6 +448,11 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int profile.NodeTaints = nodeTaints } + if v := d.Get("message_of_day").(string); v != "" { + messageOfTheDayEncoded := base64.StdEncoding.EncodeToString([]byte(v)) + profile.MessageOfTheDay = &messageOfTheDayEncoded + } + if osDiskSizeGB := d.Get("os_disk_size_gb").(int); osDiskSizeGB > 0 { profile.OsDiskSizeGB = utils.Int32(int32(osDiskSizeGB)) } @@ -583,7 +590,10 @@ func resourceKubernetesClusterNodePoolUpdate(d *pluginsdk.ResourceData, meta int } if d.HasChange("message_of_day") { - props.MessageOfTheDay = utils.String(d.Get("message_of_day").(string)) + if v := d.Get("message_of_day").(string); v != "" { + messageOfTheDayEncoded := base64.StdEncoding.EncodeToString([]byte(v)) + props.MessageOfTheDay = &messageOfTheDayEncoded + } } if d.HasChange("mode") { @@ -772,7 +782,11 @@ func resourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta inter messageOfTheDay := "" if props.MessageOfTheDay != nil { - messageOfTheDay = *props.MessageOfTheDay + messageOfTheDayDecoded, err := base64.StdEncoding.DecodeString(*props.MessageOfTheDay) + if err != nil { + return fmt.Errorf("setting `message_of_day`: %+v", err) + } + messageOfTheDay = string(messageOfTheDayDecoded) } d.Set("message_of_day", messageOfTheDay) diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go b/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go index 4506e01c8c13..f285cab67216 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go @@ -1895,7 +1895,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { node_count = 3 fips_enabled = true kubelet_disk_type = "OS" - message_of_day = "message_of_day" + message_of_day = "daily message" } `, r.templateConfig(data)) } diff --git a/internal/services/containers/kubernetes_cluster_other_resource_test.go b/internal/services/containers/kubernetes_cluster_other_resource_test.go index e9821fc118af..9fec49a62faf 100644 --- a/internal/services/containers/kubernetes_cluster_other_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_other_resource_test.go @@ -1226,13 +1226,12 @@ resource "azurerm_kubernetes_cluster" "test" { dns_prefix = "acctestaks%d" default_node_pool { - name = "default" - node_count = 1 - vm_size = "Standard_DS2_v2" - fips_enabled = true - kubelet_disk_type = "OS" - message_of_day = "tips_of_message" - message_outbound_ipv6_count = 3 + name = "default" + node_count = 1 + vm_size = "Standard_DS2_v2" + fips_enabled = true + kubelet_disk_type = "OS" + message_of_day = "daily message" } identity { diff --git a/internal/services/containers/kubernetes_nodepool.go b/internal/services/containers/kubernetes_nodepool.go index 1b13cbf5355b..58e17ce603ca 100644 --- a/internal/services/containers/kubernetes_nodepool.go +++ b/internal/services/containers/kubernetes_nodepool.go @@ -1,6 +1,7 @@ package containers import ( + "encoding/base64" "fmt" "regexp" "strconv" @@ -109,8 +110,10 @@ func SchemaDefaultNodePool() *pluginsdk.Schema { }, "message_of_day": { - Type: pluginsdk.TypeString, - Optional: true, + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, }, "min_count": { @@ -238,6 +241,7 @@ func SchemaDefaultNodePool() *pluginsdk.Schema { "workload_runtime": { Type: pluginsdk.TypeString, Optional: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ string(containerservice.WorkloadRuntimeOCIContainer), string(containerservice.WorkloadRuntimeWasmWasi), @@ -667,7 +671,6 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]containerservice.Manag EnableNodePublicIP: utils.Bool(raw["enable_node_public_ip"].(bool)), EnableEncryptionAtHost: utils.Bool(raw["enable_host_encryption"].(bool)), KubeletDiskType: containerservice.KubeletDiskType(raw["kubelet_disk_type"].(string)), - MessageOfTheDay: utils.String(raw["message_of_day"].(string)), Name: utils.String(raw["name"].(string)), NodeLabels: nodeLabels, NodeTaints: nodeTaints, @@ -701,6 +704,11 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]containerservice.Manag profile.MaxPods = utils.Int32(maxPods) } + if v := raw["message_of_day"].(string); v != "" { + messageOfTheDayEncoded := base64.StdEncoding.EncodeToString([]byte(v)) + profile.MessageOfTheDay = &messageOfTheDayEncoded + } + if prefixID := raw["node_public_ip_prefix_id"].(string); prefixID != "" { profile.NodePublicIPPrefixID = utils.String(prefixID) } @@ -1030,7 +1038,11 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro messageOfTheDay := "" if agentPool.MessageOfTheDay != nil { - messageOfTheDay = *agentPool.MessageOfTheDay + messageOfTheDayDecoded, err := base64.StdEncoding.DecodeString(*agentPool.MessageOfTheDay) + if err != nil { + return nil, err + } + messageOfTheDay = string(messageOfTheDayDecoded) } minCount := 0 diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 866da047406e..8509bc80aab6 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -334,7 +334,7 @@ A `default_node_pool` block supports the following: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. -* `message_of_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It must not be specified for Windows nodes. It must be a static string (i.e., will be printed raw and not be executed as a script). +* `message_of_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It must not be specified for Windows nodes. It must be a static string (i.e., will be printed raw and not be executed as a script). Changing this forces a new resource to be created. * `node_public_ip_prefix_id` - (Optional) Resource ID for the Public IP Addresses Prefix for the nodes in this Node Pool. `enable_node_public_ip` should be `true`. Changing this forces a new resource to be created. @@ -388,7 +388,7 @@ If `enable_auto_scaling` is set to `false`, then the following fields can also b -> **Note:** If `enable_auto_scaling` is set to `false` both `min_count` and `max_count` fields need to be set to `null` or omitted from the configuration. -* `workload_runtime` - (Optional) Used to specify the workload runtime. Allowed values are `OCIContainer` and `WasmWasi`. +* `workload_runtime` - (Optional) Used to specify the workload runtime. Allowed values are `OCIContainer` and `WasmWasi`. Changing this forces a new resource to be created. * `zones` - (Optional) Specifies a list of Availability Zones in which this Kubernetes Cluster should be located. Changing this forces a new Kubernetes Cluster to be created. diff --git a/website/docs/r/kubernetes_cluster_node_pool.html.markdown b/website/docs/r/kubernetes_cluster_node_pool.html.markdown index 8ac8dafcb5b9..c97966580eaf 100644 --- a/website/docs/r/kubernetes_cluster_node_pool.html.markdown +++ b/website/docs/r/kubernetes_cluster_node_pool.html.markdown @@ -95,7 +95,7 @@ The following arguments are supported: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. -* `message_of_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It must not be specified for Windows nodes. It must be a static string (i.e., will be printed raw and not be executed as a script). +* `message_of_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It must not be specified for Windows nodes. It must be a static string (i.e., will be printed raw and not be executed as a script). Changing this forces a new resource to be created. * `mode` - (Optional) Should this Node Pool be used for System or User resources? Possible values are `System` and `User`. Defaults to `User`. From bd2ba717eecd61d335a900ea9434b85613419fb5 Mon Sep 17 00:00:00 2001 From: zhangqiqing <1434071196@qq.com> Date: Wed, 11 May 2022 00:08:22 +0800 Subject: [PATCH 05/10] [style] clean up code --- website/docs/r/kubernetes_cluster.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 8509bc80aab6..be0d051381cd 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -356,7 +356,7 @@ A `default_node_pool` block supports the following: -> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/PodSubnetPreview` is enabled and the Resource Provider is re-registered, see [the documentation](https://docs.microsoft.com/en-us/azure/aks/configure-azure-cni#register-the-podsubnetpreview-preview-feature) for more information. -* `scale_down_mode` - This also effects the cluster autoscaler behavior. If not specified, it defaults to Delete. Possible values include: 'ScaleDownModeDelete', 'ScaleDownModeDeallocate'. Changing this forces a new resource to be created. +* `scale_down_mode` - (Optional) This also effects the cluster autoscaler behavior. If not specified, it defaults to Delete. Possible values include: 'ScaleDownModeDelete', 'ScaleDownModeDeallocate'. Changing this forces a new resource to be created. * `type` - (Optional) The type of Node Pool which should be created. Possible values are `AvailabilitySet` and `VirtualMachineScaleSets`. Defaults to `VirtualMachineScaleSets`. From 2874cd2d0565cc4ff896b50917a516bf0f8104b2 Mon Sep 17 00:00:00 2001 From: zhangqiqing <1434071196@qq.com> Date: Wed, 11 May 2022 12:18:47 +0800 Subject: [PATCH 06/10] [fix] workload_runtime can't be `WasmWasi`. --- .../kubernetes_cluster_other_resource_test.go | 55 +------------------ .../containers/kubernetes_nodepool.go | 3 +- .../docs/r/kubernetes_cluster.html.markdown | 2 +- 3 files changed, 3 insertions(+), 57 deletions(-) diff --git a/internal/services/containers/kubernetes_cluster_other_resource_test.go b/internal/services/containers/kubernetes_cluster_other_resource_test.go index 9fec49a62faf..3bc82c68587e 100644 --- a/internal/services/containers/kubernetes_cluster_other_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_other_resource_test.go @@ -370,28 +370,6 @@ func TestAccKubernetesCluster_windowsProfileLicense(t *testing.T) { }) } -func TestAccKubernetesCluster_workloadRuntime(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") - r := KubernetesClusterResource{} - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.workloadRuntime(data, "OCIContainer"), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - { - Config: r.workloadRuntime(data, "WasmWasi"), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - }) -} - func TestAccKubernetesCluster_updateWindowsProfileLicense(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") r := KubernetesClusterResource{} @@ -1232,6 +1210,7 @@ resource "azurerm_kubernetes_cluster" "test" { fips_enabled = true kubelet_disk_type = "OS" message_of_day = "daily message" + workload_runtime = "OCIContainer" } identity { @@ -1573,38 +1552,6 @@ resource "azurerm_kubernetes_cluster" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func (KubernetesClusterResource) workloadRuntime(data acceptance.TestData, workloadRuntime string) string { - return fmt.Sprintf(` - -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-aks-%d" - location = "%s" -} - -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" - workload_runtime = "%s" - } - - identity { - type = "SystemAssigned" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, workloadRuntime) -} - func (KubernetesClusterResource) diskEncryptionConfig(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/internal/services/containers/kubernetes_nodepool.go b/internal/services/containers/kubernetes_nodepool.go index 58e17ce603ca..f26535fcfd1d 100644 --- a/internal/services/containers/kubernetes_nodepool.go +++ b/internal/services/containers/kubernetes_nodepool.go @@ -241,10 +241,9 @@ func SchemaDefaultNodePool() *pluginsdk.Schema { "workload_runtime": { Type: pluginsdk.TypeString, Optional: true, - ForceNew: true, + Computed: true, ValidateFunc: validation.StringInSlice([]string{ string(containerservice.WorkloadRuntimeOCIContainer), - string(containerservice.WorkloadRuntimeWasmWasi), }, false), }, } diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index be0d051381cd..d5acc8c570a0 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -388,7 +388,7 @@ If `enable_auto_scaling` is set to `false`, then the following fields can also b -> **Note:** If `enable_auto_scaling` is set to `false` both `min_count` and `max_count` fields need to be set to `null` or omitted from the configuration. -* `workload_runtime` - (Optional) Used to specify the workload runtime. Allowed values are `OCIContainer` and `WasmWasi`. Changing this forces a new resource to be created. +* `workload_runtime` - (Optional) Used to specify the workload runtime. Allowed values are `OCIContainer`. * `zones` - (Optional) Specifies a list of Availability Zones in which this Kubernetes Cluster should be located. Changing this forces a new Kubernetes Cluster to be created. From f0c75a3ace6aaa41446a725ac283655f0121916d Mon Sep 17 00:00:00 2001 From: zhangqiqing <1434071196@qq.com> Date: Wed, 11 May 2022 13:18:30 +0800 Subject: [PATCH 07/10] [modify] improve code --- internal/services/containers/kubernetes_cluster_resource.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/services/containers/kubernetes_cluster_resource.go b/internal/services/containers/kubernetes_cluster_resource.go index 194b1c733002..d17c18a7668f 100644 --- a/internal/services/containers/kubernetes_cluster_resource.go +++ b/internal/services/containers/kubernetes_cluster_resource.go @@ -1440,9 +1440,7 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{} if key := "network_profile.0.load_balancer_profile.0.managed_outbound_ipv6_count"; d.HasChange(key) { managedOutboundIPV6Count := d.Get(key).(int) if loadBalancerProfile.ManagedOutboundIPs == nil { - loadBalancerProfile.ManagedOutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{ - CountIPv6: utils.Int32(int32(managedOutboundIPV6Count)), - } + loadBalancerProfile.ManagedOutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{} } loadBalancerProfile.ManagedOutboundIPs.CountIPv6 = utils.Int32(int32(managedOutboundIPV6Count)) @@ -2230,7 +2228,7 @@ func expandLoadBalancerProfile(d []interface{}) *containerservice.ManagedCluster if ipv6Count := config["managed_outbound_ipv6_count"]; ipv6Count != nil { if c := int32(ipv6Count.(int)); c > 0 { if profile.ManagedOutboundIPs == nil { - profile.ManagedOutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{CountIPv6: &c} + profile.ManagedOutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{} } profile.ManagedOutboundIPs.CountIPv6 = &c } From 83afcecf4f083e00089a57cfc385e0d19c01623b Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Mon, 11 Jul 2022 11:09:27 +0800 Subject: [PATCH 08/10] fix golint --- internal/services/containers/kubernetes_nodepool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/containers/kubernetes_nodepool.go b/internal/services/containers/kubernetes_nodepool.go index e7ec78a875ef..045d024c755f 100644 --- a/internal/services/containers/kubernetes_nodepool.go +++ b/internal/services/containers/kubernetes_nodepool.go @@ -241,7 +241,7 @@ func SchemaDefaultNodePool() *pluginsdk.Schema { string(containerservice.ScaleDownModeDeallocate), string(containerservice.ScaleDownModeDelete), }, false), - }, + }, "host_group_id": { Type: pluginsdk.TypeString, From 89bc5fe81d98ff778ae6dc8af666a71aa6f9b26c Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Thu, 14 Jul 2022 13:41:34 +0800 Subject: [PATCH 09/10] update --- .../kubernetes_cluster_node_pool_resource.go | 18 +++++++----------- ...bernetes_cluster_node_pool_resource_test.go | 2 +- .../kubernetes_cluster_other_resource_test.go | 14 +++++++------- .../services/containers/kubernetes_nodepool.go | 10 +++++----- .../docs/r/kubernetes_cluster.html.markdown | 10 ++++++---- .../kubernetes_cluster_node_pool.html.markdown | 2 +- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource.go b/internal/services/containers/kubernetes_cluster_node_pool_resource.go index 4bae6c724fb2..2dacacb3e893 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource.go @@ -156,7 +156,7 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource { ForceNew: true, }, - "message_of_day": { + "message_of_the_day": { Type: pluginsdk.TypeString, Optional: true, ForceNew: true, @@ -462,7 +462,10 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int profile.NodeTaints = nodeTaints } - if v := d.Get("message_of_day").(string); v != "" { + if v := d.Get("message_of_the_day").(string); v != "" { + if profile.OsType == containerservice.OSTypeWindows { + return fmt.Errorf("`message_of_the_day` cannot be specified for Windows nodes and must be a static string (i.e. will be printed raw and not executed as a script)") + } messageOfTheDayEncoded := base64.StdEncoding.EncodeToString([]byte(v)) profile.MessageOfTheDay = &messageOfTheDayEncoded } @@ -611,13 +614,6 @@ func resourceKubernetesClusterNodePoolUpdate(d *pluginsdk.ResourceData, meta int props.MaxCount = utils.Int32(int32(d.Get("max_count").(int))) } - if d.HasChange("message_of_day") { - if v := d.Get("message_of_day").(string); v != "" { - messageOfTheDayEncoded := base64.StdEncoding.EncodeToString([]byte(v)) - props.MessageOfTheDay = &messageOfTheDayEncoded - } - } - if d.HasChange("mode") { props.Mode = containerservice.AgentPoolMode(d.Get("mode").(string)) } @@ -806,11 +802,11 @@ func resourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta inter if props.MessageOfTheDay != nil { messageOfTheDayDecoded, err := base64.StdEncoding.DecodeString(*props.MessageOfTheDay) if err != nil { - return fmt.Errorf("setting `message_of_day`: %+v", err) + return fmt.Errorf("setting `message_of_the_day`: %+v", err) } messageOfTheDay = string(messageOfTheDayDecoded) } - d.Set("message_of_day", messageOfTheDay) + d.Set("message_of_the_day", messageOfTheDay) maxPods := 0 if props.MaxPods != nil { diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go b/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go index 211084193434..7067512ba5d0 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go @@ -1996,7 +1996,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { node_count = 3 fips_enabled = true kubelet_disk_type = "OS" - message_of_day = "daily message" + message_of_the_day = "daily message" } `, r.templateConfig(data)) } diff --git a/internal/services/containers/kubernetes_cluster_other_resource_test.go b/internal/services/containers/kubernetes_cluster_other_resource_test.go index 860053db3961..8250e0b825bb 100644 --- a/internal/services/containers/kubernetes_cluster_other_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_other_resource_test.go @@ -1219,13 +1219,13 @@ resource "azurerm_kubernetes_cluster" "test" { dns_prefix = "acctestaks%d" default_node_pool { - name = "default" - node_count = 1 - vm_size = "Standard_DS2_v2" - fips_enabled = true - kubelet_disk_type = "OS" - message_of_day = "daily message" - workload_runtime = "OCIContainer" + name = "default" + node_count = 1 + vm_size = "Standard_DS2_v2" + fips_enabled = true + kubelet_disk_type = "OS" + message_of_the_day = "daily message" + workload_runtime = "OCIContainer" } identity { diff --git a/internal/services/containers/kubernetes_nodepool.go b/internal/services/containers/kubernetes_nodepool.go index 045d024c755f..3fce41a78894 100644 --- a/internal/services/containers/kubernetes_nodepool.go +++ b/internal/services/containers/kubernetes_nodepool.go @@ -116,7 +116,7 @@ func SchemaDefaultNodePool() *pluginsdk.Schema { ForceNew: true, }, - "message_of_day": { + "message_of_the_day": { Type: pluginsdk.TypeString, Optional: true, ForceNew: true, @@ -717,7 +717,7 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]containerservice.Manag profile.MaxPods = utils.Int32(maxPods) } - if v := raw["message_of_day"].(string); v != "" { + if v := raw["message_of_the_day"].(string); v != "" { messageOfTheDayEncoded := base64.StdEncoding.EncodeToString([]byte(v)) profile.MessageOfTheDay = &messageOfTheDayEncoded } @@ -744,8 +744,8 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]containerservice.Manag } profile.ScaleDownMode = containerservice.ScaleDownModeDelete - if scaleOfMode := raw["scale_down_mode"].(string); scaleOfMode != "" { - profile.ScaleDownMode = containerservice.ScaleDownMode(scaleOfMode) + if scaleDownMode := raw["scale_down_mode"].(string); scaleDownMode != "" { + profile.ScaleDownMode = containerservice.ScaleDownMode(scaleDownMode) } if ultraSSDEnabled, ok := raw["ultra_ssd_enabled"]; ok { @@ -1167,7 +1167,7 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro "kubelet_disk_type": string(agentPool.KubeletDiskType), "max_count": maxCount, "max_pods": maxPods, - "message_of_day": messageOfTheDay, + "message_of_the_day": messageOfTheDay, "min_count": minCount, "name": name, "node_count": count, diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 650685381d25..11bf6dfd4693 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -336,7 +336,7 @@ A `default_node_pool` block supports the following: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. -* `message_of_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It must not be specified for Windows nodes. It must be a static string (i.e., will be printed raw and not be executed as a script). Changing this forces a new resource to be created. +* `message_of_the_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It cannot be specified for Windows nodes and must be a static string (i.e. will be printed raw and not executed as a script). Changing this forces a new resource to be created. * `node_public_ip_prefix_id` - (Optional) Resource ID for the Public IP Addresses Prefix for the nodes in this Node Pool. `enable_node_public_ip` should be `true`. Changing this forces a new resource to be created. @@ -358,7 +358,7 @@ A `default_node_pool` block supports the following: -> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/PodSubnetPreview` is enabled and the Resource Provider is re-registered, see [the documentation](https://docs.microsoft.com/azure/aks/configure-azure-cni#register-the-podsubnetpreview-preview-feature) for more information. -* `scale_down_mode` - (Optional) This also effects the cluster autoscaler behavior. If not specified, it defaults to Delete. Possible values include: 'ScaleDownModeDelete', 'ScaleDownModeDeallocate'. Changing this forces a new resource to be created. +* `scale_down_mode` - (Optional) Specifies the autoscaling behaviour of the Kubernetes Cluster. If not specified, it defaults to 'ScaleDownModeDelete'. Possible values include 'ScaleDownModeDelete' and 'ScaleDownModeDeallocate'. Changing this forces a new resource to be created. * `type` - (Optional) The type of Node Pool which should be created. Possible values are `AvailabilitySet` and `VirtualMachineScaleSets`. Defaults to `VirtualMachineScaleSets`. @@ -390,7 +390,7 @@ If `enable_auto_scaling` is set to `false`, then the following fields can also b -> **Note:** If `enable_auto_scaling` is set to `false` both `min_count` and `max_count` fields need to be set to `null` or omitted from the configuration. -* `workload_runtime` - (Optional) Used to specify the workload runtime. Allowed values are `OCIContainer`. +* `workload_runtime` - (Optional) Specifies the workload runtime used by the node pool. Possible values are `OCIContainer`. * `zones` - (Optional) Specifies a list of Availability Zones in which this Kubernetes Cluster should be located. Changing this forces a new Kubernetes Cluster to be created. @@ -554,7 +554,9 @@ A `load_balancer_profile` block supports the following: * `managed_outbound_ip_count` - (Optional) Count of desired managed outbound IPs for the cluster load balancer. Must be between `1` and `100` inclusive. -* `managed_outbound_ipv6_count` - (Optional) The desired number of IPv6 outbound IPs created/managed by Azure for the cluster load balancer. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 0 for single-stack and 1 for dual-stack. +* `managed_outbound_ipv6_count` - (Optional) The desired number of IPv6 outbound IPs created and managed by Azure for the cluster load balancer. Must be in the range of 1 to 100 (inclusive). The default value is 0 for single-stack and 1 for dual-stack. + +~> **Note:** `managed_outbound_ipv6_count` requires Dual-stack networking is enabled and requires that the Preview Feature `Microsoft.ContainerService/AKS-EnableDualStack` is enabled and the Resource Provider is re-registered, see [the documentation](https://docs.microsoft.com/azure/aks/configure-kubenet-dual-stack?tabs=azure-cli%2Ckubectl#register-the-aks-enabledualstack-preview-feature) for more information. * `outbound_ip_address_ids` - (Optional) The ID of the Public IP Addresses which should be used for outbound communication for the cluster load balancer. diff --git a/website/docs/r/kubernetes_cluster_node_pool.html.markdown b/website/docs/r/kubernetes_cluster_node_pool.html.markdown index c38442d8ac19..4929d03bcf9b 100644 --- a/website/docs/r/kubernetes_cluster_node_pool.html.markdown +++ b/website/docs/r/kubernetes_cluster_node_pool.html.markdown @@ -97,7 +97,7 @@ The following arguments are supported: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. -* `message_of_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It must not be specified for Windows nodes. It must be a static string (i.e., will be printed raw and not be executed as a script). Changing this forces a new resource to be created. +* `message_of_the_day` - (Optional) A base64-encoded string which will be written to /etc/motd after decoding. This allows customization of the message of the day for Linux nodes. It cannot be specified for Windows nodes and must be a static string (i.e. will be printed raw and not executed as a script). Changing this forces a new resource to be created. * `mode` - (Optional) Should this Node Pool be used for System or User resources? Possible values are `System` and `User`. Defaults to `User`. From b5d8cfbdf131afac4baa70b84289aba48b1980e8 Mon Sep 17 00:00:00 2001 From: Steph Date: Thu, 6 Oct 2022 16:08:47 +0200 Subject: [PATCH 10/10] fix wording in docs --- internal/services/containers/kubernetes_nodepool.go | 1 - website/docs/r/kubernetes_cluster.html.markdown | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/containers/kubernetes_nodepool.go b/internal/services/containers/kubernetes_nodepool.go index 3fce41a78894..9a92c7a075e6 100644 --- a/internal/services/containers/kubernetes_nodepool.go +++ b/internal/services/containers/kubernetes_nodepool.go @@ -768,7 +768,6 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]containerservice.Manag profile.ProximityPlacementGroupID = utils.String(proximityPlacementGroupId) } - profile.WorkloadRuntime = "" if workloadRunTime := raw["workload_runtime"].(string); workloadRunTime != "" { profile.WorkloadRuntime = containerservice.WorkloadRuntime(workloadRunTime) } diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 11bf6dfd4693..5de2a2ffe8c5 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -364,6 +364,7 @@ A `default_node_pool` block supports the following: * `tags` - (Optional) A mapping of tags to assign to the Node Pool. + ~> At this time there's a bug in the AKS API where Tags for a Node Pool are not stored in the correct case - you [may wish to use Terraform's `ignore_changes` functionality to ignore changes to the casing](https://www.terraform.io/docs/configuration/resources.html#ignore_changes) until this is fixed in the AKS API. * `ultra_ssd_enabled` - (Optional) Used to specify whether the UltraSSD is enabled in the Default Node Pool. Defaults to `false`. See [the documentation](https://docs.microsoft.com/azure/aks/use-ultra-disks) for more information. @@ -556,7 +557,7 @@ A `load_balancer_profile` block supports the following: * `managed_outbound_ipv6_count` - (Optional) The desired number of IPv6 outbound IPs created and managed by Azure for the cluster load balancer. Must be in the range of 1 to 100 (inclusive). The default value is 0 for single-stack and 1 for dual-stack. -~> **Note:** `managed_outbound_ipv6_count` requires Dual-stack networking is enabled and requires that the Preview Feature `Microsoft.ContainerService/AKS-EnableDualStack` is enabled and the Resource Provider is re-registered, see [the documentation](https://docs.microsoft.com/azure/aks/configure-kubenet-dual-stack?tabs=azure-cli%2Ckubectl#register-the-aks-enabledualstack-preview-feature) for more information. +~> **Note:** `managed_outbound_ipv6_count` requires dual-stack networking. To enable dual-stack networking the Preview Feature `Microsoft.ContainerService/AKS-EnableDualStack` needs to be enabled and the Resource Provider re-registered, see [the documentation](https://docs.microsoft.com/azure/aks/configure-kubenet-dual-stack?tabs=azure-cli%2Ckubectl#register-the-aks-enabledualstack-preview-feature) for more information. * `outbound_ip_address_ids` - (Optional) The ID of the Public IP Addresses which should be used for outbound communication for the cluster load balancer.