Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

Terraform rejects addon_profile in azurerm_kubernetes_cluster

Your error

Error: Unsupported block type3 more lines it can show

Fix it fast

Most common cause, 1 of 3

addon_profile was removed in azurerm 3.0

Delete the addon_profile wrapper and the old enabled flags.

Fix
resource "azurerm_kubernetes_cluster" "aks" {
  # ...name, location, default_node_pool, identity...

  azure_policy_enabled = true

  oms_agent {
    log_analytics_workspace_id = azurerm_log_analytics_workspace.main.id
  }

  key_vault_secrets_provider {
    secret_rotation_enabled = true
  }
}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Error: Unsupported block type in azurerm_kubernetes_cluster means your config uses a block that the installed azurerm provider no longer has. addon_profile and role_based_access_control were removed in 3.0, and 4.0 renamed node pool arguments such as enable_auto_scaling. Move each setting to its current top-level form and pin the provider version. Applies to azurerm 4.x and 5.14.

  • Applies to hashicorp/azurerm 5.14.0, hashicorp/azurerm 4.x, Terraform 1.17.2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Check which azurerm release Terraform actually installed. A config written for 2.x meets a 3.x or newer provider in causes 1 and 2; a 3.x config on a 4.x or 5.x provider gives the renamed-argument errors of cause 3.

Run this first
terraform version
grep -n -A3 "azurerm" versions.tf main.tf

Then find the line you see in this list and open its fix:

  1. 1addon_profile was removed in azurerm 3.0The message names addon_profile, and the block wraps oms_agent, azure_policy or azure_keyvault_secrets_provider
  2. 2role_based_access_control was split into an argument and a new blockThe message names role_based_access_control, usually with an azure_active_directory block nested inside it
  3. 3A 4.0 rename hits the node pool and API server settingsThe error is Unsupported argument for enable_auto_scaling, enable_node_public_ip, enable_host_encryption or api_server_authorized_ip_ranges

What does the error look like?

  • Error: Unsupported block type
  • Blocks of type "addon_profile" are not expected here.
  • Blocks of type "role_based_access_control" are not expected here.
  • An argument named "enable_auto_scaling" is not expected here.

Cause 1 of 3

addon_profile was removed in azurerm 3.0

You seeThe message names addon_profile, and the block wraps oms_agent, azure_policy or azure_keyvault_secrets_provider

Check

Unsupported block type for addon_profile appears because the azurerm 3.0 upgrade guide removed that wrapper block and moved every add-on to the top level of the cluster resource. azure_policy became the azure_policy_enabled boolean, oms_agent and key_vault_secrets_provider became top-level blocks, and kube_dashboard was dropped entirely.

Check
grep -n -A12 "addon_profile" *.tf

Fix

Delete the addon_profile wrapper and the old enabled flags. An add-on block is now switched on by being present. kube_dashboard has no replacement and simply goes.

Fix
resource "azurerm_kubernetes_cluster" "aks" {
  # ...name, location, default_node_pool, identity...

  azure_policy_enabled = true

  oms_agent {
    log_analytics_workspace_id = azurerm_log_analytics_workspace.main.id
  }

  key_vault_secrets_provider {
    secret_rotation_enabled = true
  }
}

Verify

terraform validate passes, and terraform plan shows no change for add-ons that were already on.

Verify
terraform validate && terraform plan

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

role_based_access_control was split into an argument and a new block

You seeThe message names role_based_access_control, usually with an azure_active_directory block nested inside it

Check

The same 3.0 guide removed the role_based_access_control block in favour of the role_based_access_control_enabled argument and a separate azure_active_directory_role_based_access_control block. A config that still nests Azure AD settings inside the old block fails with Unsupported block type.

Check
grep -n -A8 "role_based_access_control" *.tf

Fix

Replace the old block with the argument and the new block. Azure AD admin groups go in admin_group_object_ids, and azure_rbac_enabled switches on role-based access control based on Azure AD.

Fix
role_based_access_control_enabled = true

azure_active_directory_role_based_access_control {
  admin_group_object_ids = [var.aks_admin_group_id]
  azure_rbac_enabled     = true
}

Verify

terraform plan shows no replacement of the cluster. The provider docs note that changing role_based_access_control_enabled forces a new cluster, so stop if plan wants to replace it.

Verify
terraform plan

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

A 4.0 rename hits the node pool and API server settings

You seeThe error is Unsupported argument for enable_auto_scaling, enable_node_public_ip, enable_host_encryption or api_server_authorized_ip_ranges

Check

Configs written for 3.x break on 4.0 and later because the 4.0 guide renamed default_node_pool.enable_auto_scaling to auto_scaling_enabled, enable_node_public_ip to node_public_ip_enabled and enable_host_encryption to host_encryption_enabled. It also removed api_server_authorized_ip_ranges in favour of api_server_access_profile.authorized_ip_ranges.

Check
grep -nE "enable_auto_scaling|enable_node_public_ip|enable_host_encryption|api_server_authorized_ip_ranges" *.tf

Fix

Rename the arguments and move the IP list into the api_server_access_profile block.

Fix
default_node_pool {
  name                 = "system"
  vm_size              = "Standard_D4s_v5"
  auto_scaling_enabled = true
  min_count            = 1
  max_count            = 3
}

api_server_access_profile {
  authorized_ip_ranges = ["203.0.113.0/24"]
}

Verify

terraform validate finishes without the Unsupported argument errors, and plan shows the node pool unchanged.

Verify
terraform validate

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Pin azurerm with a ~> constraint such as ~> 5.14 in required_providers, and move to a new major only with its upgrade guide open.
  • Commit .terraform.lock.hcl so every machine and CI job installs the same provider build.
  • Make terraform validate a required pull-request check, so a removed block is caught in review rather than during apply.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.