Closed piotrgwiazda closed 2 years ago
I've updated the bug report for completeness.
I've confirmed that the azure_policy addon is removed also, when we try to add Open Service Mesh.
@ms-henglu please take a look at a draft concept https://github.com/hashicorp/terraform-provider-azurerm/pull/18068 This is my first approach to Go, so it might not be 100% correct, but it is worth looking.
Closing for the moment since the current implementation is deliberate and working as expected, please see this comment over on #18068 for more details.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Is there an existing issue for this?
Community Note
Terraform Version
1.2.4
AzureRM Provider Version
3.16.0
Affected Resource(s)/Data Source(s)
azurerm_kubernetes_cluster
Terraform Configuration Files
Any terraform file containing:
Debug Output/Panic Output
The
addonProfiles.azurepolicy
section in the JSON sent to Azure API via PUT is missing.Expected Behaviour
I would expect that every time when I update the cluster, the
addonProfiles.azurePolicy
section of the JSON sent to Azure API via PUT request is added when the azure_policy_enabled attribute is set to true.Expecting:
Actual Behaviour
The
addonProfiles.azurePolicy
section is added only when the cluster is created, but not on updates. When adding another addon (e.g. key_vault_secrets_provider ), the azure policy addon is removed.This causes a deployment failure in my environment where I want to implement a custom Azure policy for organization that will Deny any kubernetes cluster that does not have the Azure Policy addon enabled. My policy requires that the
addonProfiles.azurePolicy.enabled
property exists and is set to true. However, if ti was not blocked by the policy it will probably remove the policy addon from the cluster.The
addonProfiles.azurepolicy
section in the JSON sent to Azure API via PUT is missing.This blocks me from upgrading to AzureRM provider 3.x.x as this is inconsistent with 2.x.x that was always sending the property.
Steps to Reproduce
azure_policy_enabled = true
but without thekey_vault_secrets_provider
block.key_vault_secrets_provider
block.Important Factoids
No response
References
https://github.com/hashicorp/terraform-provider-azurerm/blob/dff3c08bb294f4049bd6e7ec7fca2b15820414fa/internal/services/containers/kubernetes_cluster_resource.go#L1337
When any of the listed properties changes, then addonProfiles are recalculated by calling expandKubernetesAddOns. As a result azure policy addon is removed as it has not changed. If nothing changes, then the block is not executed and the azure policy addon is left "as is".
It seems to be implemented in https://github.com/hashicorp/terraform-provider-azurerm/blob/v3.16.0/internal/services/containers/kubernetes_addons.go#L295
The addon profile is added only when anything changed. However, if the recalculation is triggered by another addon, the azure policy addon is omited.