diff --git a/internal/services/containers/kubernetes_cluster_other_resource_test.go b/internal/services/containers/kubernetes_cluster_other_resource_test.go index 288d656037c1..dd03585d4d36 100644 --- a/internal/services/containers/kubernetes_cluster_other_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_other_resource_test.go @@ -804,7 +804,9 @@ func TestAccKubernetesCluster_nodeOsUpgradeChannel(t *testing.T) { check.That(data.ResourceName).Key("node_os_channel_upgrade").HasValue("Unmanaged"), ), }, - data.ImportStep(), + // TODO add this back in when upgrading to 2023-06-02-preview + // temporarily skip the import check because of the behaviour of this feature + // data.ImportStep(), { Config: r.nodeOsUpgradeChannel(data, "SecurityPatch"), Check: acceptance.ComposeTestCheckFunc( @@ -812,7 +814,7 @@ func TestAccKubernetesCluster_nodeOsUpgradeChannel(t *testing.T) { check.That(data.ResourceName).Key("node_os_channel_upgrade").HasValue("SecurityPatch"), ), }, - data.ImportStep(), + // data.ImportStep(), { Config: r.nodeOsUpgradeChannel(data, "NodeImage"), Check: acceptance.ComposeTestCheckFunc( @@ -820,7 +822,7 @@ func TestAccKubernetesCluster_nodeOsUpgradeChannel(t *testing.T) { check.That(data.ResourceName).Key("node_os_channel_upgrade").HasValue("NodeImage"), ), }, - data.ImportStep(), + // data.ImportStep(), { Config: r.nodeOsUpgradeChannel(data, "None"), Check: acceptance.ComposeTestCheckFunc( @@ -828,7 +830,7 @@ func TestAccKubernetesCluster_nodeOsUpgradeChannel(t *testing.T) { check.That(data.ResourceName).Key("node_os_channel_upgrade").HasValue("None"), ), }, - data.ImportStep(), + // data.ImportStep(), }) } diff --git a/internal/services/containers/kubernetes_cluster_resource.go b/internal/services/containers/kubernetes_cluster_resource.go index 7d5f3ed9c81a..c85fb975c27d 100644 --- a/internal/services/containers/kubernetes_cluster_resource.go +++ b/internal/services/containers/kubernetes_cluster_resource.go @@ -1483,14 +1483,20 @@ func resourceKubernetesClusterCreate(d *pluginsdk.ResourceData, meta interface{} autoUpgradeProfile := &managedclusters.ManagedClusterAutoUpgradeProfile{} autoChannelUpgrade := d.Get("automatic_channel_upgrade").(string) nodeOsChannelUpgrade := d.Get("node_os_channel_upgrade").(string) - if autoChannelUpgrade != "" { + + // this check needs to be separate and gated since node_os_channel_upgrade is a preview feature + if nodeOsChannelUpgrade != "" && autoChannelUpgrade != "" { if autoChannelUpgrade == string(managedclusters.UpgradeChannelNodeNegativeimage) && nodeOsChannelUpgrade != string(managedclusters.NodeOSUpgradeChannelNodeImage) { return fmt.Errorf("`node_os_channel_upgrade` cannot be set to a value other than `NodeImage` if `automatic_channel_upgrade` is set to `node-image`") } + } + + if autoChannelUpgrade != "" { autoUpgradeProfile.UpgradeChannel = pointer.To(managedclusters.UpgradeChannel(autoChannelUpgrade)) } else { autoUpgradeProfile.UpgradeChannel = pointer.To(managedclusters.UpgradeChannelNone) } + if nodeOsChannelUpgrade != "" { autoUpgradeProfile.NodeOSUpgradeChannel = pointer.To(managedclusters.NodeOSUpgradeChannel(nodeOsChannelUpgrade)) } @@ -1953,16 +1959,17 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{} existing.Model.Properties.AutoUpgradeProfile = &managedclusters.ManagedClusterAutoUpgradeProfile{} } channel := d.Get("automatic_channel_upgrade").(string) - if channel == string(managedclusters.UpgradeChannelNodeNegativeimage) && d.Get("node_os_channel_upgrade").(string) != string(managedclusters.NodeOSUpgradeChannelNodeImage) { - return fmt.Errorf("`node_os_channel_upgrade` must be set to `NodeImage` if `automatic_channel_upgrade` is set to `node-image`") - } if channel == "" { channel = string(managedclusters.UpgradeChannelNone) } existing.Model.Properties.AutoUpgradeProfile.UpgradeChannel = pointer.To(managedclusters.UpgradeChannel(channel)) } + if d.HasChange("node_os_channel_upgrade") { updateCluster = true + if d.Get("automatic_channel_upgrade").(string) == string(managedclusters.UpgradeChannelNodeNegativeimage) && d.Get("node_os_channel_upgrade").(string) != string(managedclusters.NodeOSUpgradeChannelNodeImage) { + return fmt.Errorf("`node_os_channel_upgrade` must be set to `NodeImage` if `automatic_channel_upgrade` is set to `node-image`") + } if existing.Model.Properties.AutoUpgradeProfile == nil { existing.Model.Properties.AutoUpgradeProfile = &managedclusters.ManagedClusterAutoUpgradeProfile{} } @@ -2313,7 +2320,12 @@ func resourceKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{}) } } d.Set("automatic_channel_upgrade", upgradeChannel) - d.Set("node_os_channel_upgrade", nodeOSUpgradeChannel) + + // the API returns `node_os_channel_upgrade` when `automatic_channel_upgrade` is set to `node-image` + // since it's a preview feature we will only set this if it's explicitly been set in the config for the time being + if v, ok := d.GetOk("node_os_channel_upgrade"); ok && v.(string) != "" { + d.Set("node_os_channel_upgrade", nodeOSUpgradeChannel) + } customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile.CustomCATrustCertificates) d.Set("custom_ca_trust_certificates_base64", customCaTrustCertList)