Introduction
This article explains how to resolve an error encountered during the terraform plan phase related to azurerm_kubernetes_cluster_node_pool resource configurations. The issue occurs due to a mismatch in attribute naming between different major versions of the Terraform AzureRM provider.
Problem
Terraform fails during the plan phase with an error indicating it cannot decode a resource from the state due to an unsupported attribute.
Error: Failed to decode resource from state Error decoding "module.aks.azurerm_kubernetes_cluster_node_pool.builder[0]" from previous state: unsupported attribute "auto_scaling_enabled" Failed generating plan JSON Failed to marshal plan to json: error marshaling prior state: unsupported attribute "auto_scaling_enabled"
Prerequisites
- Terraform configuration using the
azurerm_kubernetes_cluster_node_poolresource. - An environment where the Terraform state was created with version 3.x of the AzureRM provider, but subsequent operations use version 4.x.
Cause
This error is caused by a breaking change in an argument name for the azurerm_kubernetes_cluster_node_pool resource between major versions of the AzureRM provider.
- In AzureRM provider v3.x, the attribute was
enable_auto_scaling. - In AzureRM provider v4.x, this attribute was renamed to
auto_scaling_enabled.
When you run terraform plan using AzureRM v4.x, Terraform expects the new attribute name. However, if the existing Terraform state file was written by v3.x, it contains the old attribute name (enable_auto_scaling). Terraform cannot decode the resource from the state because the attribute recorded in the state does not exist in the v4.x provider schema, leading to the decoding error.
Solution
To resolve this error, you must align your Terraform configuration with the AzureRM provider version 4.x schema. This involves updating the provider version constraint and refactoring the attribute name in your resource block.
Step 1: Update the Provider Version Constraint
Modify your provider block to require version 4.0.0 or higher of the AzureRM provider. This ensures your configuration uses the newer provider schema.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 4.0.0"
}
}
}
provider "azurerm" {
features {}
}Step 2: Refactor the Attribute Name
In your azurerm_kubernetes_cluster_node_pool resource configuration, change the attribute name from enable_auto_scaling to auto_scaling_enabled.
Before (for AzureRM v3.x):
resource "azurerm_kubernetes_cluster_node_pool" "example" {
# ...
enable_auto_scaling = true
}After (for AzureRM v4.x):
resource "azurerm_kubernetes_cluster_node_pool" "example" {
# ...
auto_scaling_enabled = true
}Outcome
After completing these steps, rerun terraform plan. If the mismatch between the state and configuration is resolved, the plan should succeed without decoding errors.
If you continue to see decoding issues, verify that no other modules or provider blocks in your configuration reference the old attribute name.