[Azure Provider v4] Upgrade Report: Catching 'Massive Diffs' + [Azure Provider v4] Error Analysis: `AuthorizationFailed` and `RP not registered`
[Azure Provider v4] Upgrade Report: Catching 'Massive Diffs'
If AWS has the v6 cataclysm, Azure has the azurerm v4.0 upgrade. Recently, while upgrading the Provider in the production environment from v3.116.0 to v4.0.0, I experienced a phenomenon where over 300 resource changes (Diffs) were generated just by running plan without any code modifications.
This post records the 3 most frequent 'False Changes (Noise)' among them and how I resolved them to achieve No changes.
1. Observation Environment
- Terraform Core: v1.6.0
- Azure Provider: v3.116.0 → v4.0.0 (Major Upgrade)
- Target: Azure Kubernetes Service (AKS), VNet, Key Vault, etc.
2. Cause 1: Change in Resource Provider Registration Method
From v4, the way Terraform registers Azure Resource Providers (RP) has become stricter. Things that used to be registered automatically now throw errors or cause state changes.
[Symptom]
Unnecessary Provider registration attempts appear during plan, or insufficient permission errors occur.
[Solution]
You must explicitly control resource_provider_registrations in the Provider configuration block.
provider "azurerm" {
features {}
subscription_id = "..."
# v4 Mandatory Setting: Prevent noise/permission errors due to unnecessary RP registration attempts
resource_provider_registrations = "core"
}
none: Do not auto-register (Recommended for environments with minimized permissions)core: Register only core services (Generally recommended value)
3. Cause 2: Resource ID Case Sensitivity
While Azure APIs are often case-insensitive, Terraform State is strict. With the move to v4, the normalization logic for some resource IDs has changed, leading to a terrifying plan that says, "The case is different, so I will Replace it," even though it is actually the same resource.
[Plan Diff]
# azurerm_resource_group.rg will be updated in-place
~ resource_group_id = "/subscriptions/.../resourceGroups/MyRG" -> "/subscriptions/.../resourcegroups/myrg"
*(Attempting to touch the resource even though there is no functional difference)*
[Solution]
You must either match the strings in your code to the 'lowercase-focused' IDs seen in the Azure Portal or ignore them using a lifecycle block. I chose the former and solved it by wrapping the ID reference parts of the code with the lower() function.
4. Cause 3: The Counterattack of Defaults
Just like AWS, Azure v4 also saw massive changes in default values for resources related to AKS (Kubernetes) and VMs.
[Solution: Removing Verified Diffs]
I executed terraform plan -refresh-only first to reflect the latest state of the Azure API into the State, and for any Diffs remaining after that, I defended against them by explicitly declaring those values in the code.
[Azure Provider v4] Error Analysis: AuthorizationFailed and RP not registered
When hitting terraform apply immediately after the upgrade, red error messages explode on the screen. I have summarized the identity and solutions for these errors, which look like permission issues or configuration problems.
1. Error 1: AuthorizationFailed (Insufficient Permissions)
[Log]
Error: authorization.RoleAssignmentsClient#Create: Failure responding to request:
StatusCode=403 -- Original Error: autorest/azure: Service returned an error.
Status=403 Code="AuthorizationFailed" Message="The client '...' does not have authorization to perform action 'Microsoft.Authorization/roleAssignments/write' over scope '...'"
[Cause]
When azurerm v4 creates resources, it internally calls new API versions or attempts to check additional attributes (e.g., Flow Log permissions) that were not checked in the past. Existing Service Principal (SP) permissions might be insufficient.
[Solution]
- Short-term: Add the
Actionshown in the error message (e.g.,Microsoft.Authorization/...) to the SP's custom role. - Long-term: The SP for Terraform needs clear Role assignments based on the principle of least privilege, such as
User Access Administrator(when assigning Roles) in addition toContributor.
2. Error 2: MissingSubscriptionRegistration
[Log]
Error: The subscription is not registered to use namespace 'Microsoft.ContainerService'.
See https://aka.ms/rps-not-found for how to register subscriptions.
[Cause]
This occurs when Terraform attempted to activate an Azure Resource Provider (RP) to handle the resource (e.g., AKS) but failed. In v4, this check is performed more aggressively.
[Solution]
Rather than bypassing it with Terraform code (skip_provider_registration), it is cleanest to register it once via Azure CLI.
# You only need to run this once
az provider register --namespace Microsoft.ContainerService
Wait about 1–5 minutes after registration, then re-run terraform apply to resolve the issue.