Skip to content

Commit

Permalink
add conditional ForceNew for CA trust cert (#23737)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephybun authored Nov 1, 2023
1 parent 9f832ba commit 2699162
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
10 changes: 5 additions & 5 deletions internal/services/containers/kubernetes_cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func dataSourceKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{}
return fmt.Errorf("setting `key_management_service`: %+v", err)
}

customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile.CustomCATrustCertificates)
customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile)
if err := d.Set("custom_ca_trust_certificates_base64", customCaTrustCertList); err != nil {
return fmt.Errorf("setting `custom_ca_trust_certificates_base64`: %+v", err)
}
Expand Down Expand Up @@ -1481,14 +1481,14 @@ func flattenKubernetesClusterDataSourceUpgradeSettings(input *managedclusters.Ag
}
}

func flattenCustomCaTrustCerts(input *[]string) []interface{} {
if input == nil {
func flattenCustomCaTrustCerts(input *managedclusters.ManagedClusterSecurityProfile) []interface{} {
if input == nil || input.CustomCATrustCertificates == nil {
return make([]interface{}, 0)
}

customCaTrustCertInterface := make([]interface{}, len(*input))
customCaTrustCertInterface := make([]interface{}, len(*input.CustomCATrustCertificates))

for index, value := range *input {
for index, value := range *input.CustomCATrustCertificates {
customCaTrustCertInterface[index] = value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ func TestAccKubernetesCluster_customCaTrustCerts(t *testing.T) {
"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURmakNDQW1hZ0F3SUJBZ0lFZnlWdk56QU5CZ2txaGtpRzl3MEJBUXNGQURCWU1Rc3dDUVlEVlFRR0V3SlEKVERFVU1CSUdBMVVFQXd3TFJtRnJaU0JEWlhKMElESXhGVEFUQmdOVkJBY01ERVJsWm1GMWJIUWdRMmww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S0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ==",
}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.customCATrustCertificates(data, fakeCertList),
Expand All @@ -967,10 +971,10 @@ func TestAccKubernetesCluster_customCaTrustCerts(t *testing.T) {
},
data.ImportStep(),
{
Config: r.customCATrustCertificates(data, nil),
Config: r.customCATrustCertificates(data, fakeCertList2),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("custom_ca_trust_certificates_base64.0").DoesNotExist(),
check.That(data.ResourceName).Key("custom_ca_trust_certificates_base64.0").Exists(),
check.That(data.ResourceName).Key("custom_ca_trust_certificates_base64.1").DoesNotExist(),
),
},
Expand Down
5 changes: 4 additions & 1 deletion internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
pluginsdk.ForceNewIfChange("network_profile.0.network_policy", func(ctx context.Context, old, new, meta interface{}) bool {
return old.(string) != "" || new.(string) != string(managedclusters.NetworkPolicyCilium)
}),
pluginsdk.ForceNewIfChange("custom_ca_trust_certificates_base64", func(ctx context.Context, old, new, meta interface{}) bool {
return len(old.([]interface{})) > 0 && len(new.([]interface{})) == 0
}),
),

Timeouts: &pluginsdk.ResourceTimeout{
Expand Down Expand Up @@ -2614,7 +2617,7 @@ func resourceKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{})
d.Set("node_os_channel_upgrade", nodeOSUpgradeChannel)
}

customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile.CustomCATrustCertificates)
customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile)
d.Set("custom_ca_trust_certificates_base64", customCaTrustCertList)

enablePrivateCluster := false
Expand Down
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 @@ -103,6 +103,8 @@ In addition, one of either `identity` or `service_principal` blocks must be spec

* `custom_ca_trust_certificates_base64` - (Optional) A list of up to 10 base64 encoded CAs that will be added to the trust store on nodes with the `custom_ca_trust_enabled` feature enabled.

-> **Note:** Removing `custom_ca_trust_certificates_base64` after it has been set forces a new resource to be created.

* `disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set which should be used for the Nodes and Volumes. More information [can be found in the documentation](https://docs.microsoft.com/azure/aks/azure-disk-customer-managed-keys). Changing this forces a new resource to be created.

* `edge_zone` - (Optional) Specifies the Edge Zone within the Azure Region where this Managed Kubernetes Cluster should exist. Changing this forces a new resource to be created.
Expand Down

0 comments on commit 2699162

Please sign in to comment.