<p>I am getting error while creating AKS Cluster Using Terraform</p>
<h1>Error:</h1>
<pre><code>│ Error: Unsupported block type
│
│   on main.tf line 97, in resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks&quot;:
│   97:     image_reference {
│
│ Blocks of type &quot;image_reference&quot; are not expected here.
╵
╷
│ Error: Unsupported block type
│
│   on main.tf line 105, in resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks&quot;:
│  105:   node_pools {
│
│ Blocks of type &quot;node_pools&quot; are not expected here.
╵
╷
│ Error: Unsupported block type
│
│   on main.tf line 124, in resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks&quot;:
│  124:   node_pool {
│
│ Blocks of type &quot;node_pool&quot; are not expected here.
╵
╷
│ Error: Unsupported block type
│
│   on main.tf line 153, in resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks&quot;:
│  153:   kubernetes_cluster_config {
│
│ Blocks of type &quot;kubernetes_cluster_config&quot; are not expected here.
╵
╷
│ Error: Unsupported argument
│
│   on main.tf line 180, in resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks&quot;:
│  180:     network_security_group_id = azurerm_network_security_group.azure-sg.id
│
│ An argument named &quot;network_security_group_id&quot; is not expected here.
</code></pre>
<p>Above is the error i am facing. I have written Terraform code as shown below.</p>
<pre><code>provider.tf:
============

provider &quot;azurerm&quot; {
  features {}
}

terraform {
  required_providers {
    azurerm = {
      source  = &quot;hashicorp/azurerm&quot;
      version = &quot;2.39.0&quot;
    }
  }
}


terraform.tfvars:
=================

resource_group_name = &quot;a0474899701&quot;
location            = &quot;CentralUS&quot;
cluster_name        = &quot;aks01&quot;
kubernetes_version  = &quot;1.24.4&quot;
system_node_count   = 2
user_node_count     = 1
spot_node_count     = 2
acr_name            = &quot;devops_acr_tf&quot;
aks_network_plugin  = &quot;kubenet&quot;
client_id           = &quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;
client_secret       = &quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;


main.tf:
========
# Create an Resource Group
resource &quot;azurerm_resource_group&quot; &quot;aks-rg&quot; {
  name     = var.resource_group_name
  location = var.location
}

# Create an ACR instance
resource &quot;azurerm_container_registry&quot; &quot;acr&quot; {
  name                = var.acr_name
  resource_group_name = azurerm_resource_group.aks-rg.name
  location            = var.location
  sku                 = &quot;Standard&quot;
  admin_enabled       = false
}

# Create a role assignment to allow AKS to access ACR
resource &quot;azurerm_role_assignment&quot; &quot;role_acrpull&quot; {
  scope                            = azurerm_container_registry.acr.id
  role_definition_name             = &quot;AcrPull&quot;
  # principal_id                     = azurerm_kubernetes_cluster.aks.kubelet_identity.0.object_id
  principal_id                     = azurerm_kubernetes_cluster.aks.kubelet_identity.0.client_id
  skip_service_principal_aad_check = true
}

# Create a Kubernetes secret to hold the ACR credentials
# It holds the ACR credentials in a Docker config JSON format
resource &quot;kubernetes_secret&quot; &quot;acr_credentials&quot; {
  metadata {
    name = &quot;acr-credentials&quot;
  }

  data = {
    &quot;.dockerconfigjson&quot; = azurerm_container_registry.acr.docker_config_json
  }
}    

# Private Key Creation
resource &quot;tls_private_key&quot; &quot;aks_ssh_key&quot; {
  algorithm = &quot;RSA&quot;
}

resource &quot;file&quot; &quot;private_key&quot; {
  content  = tls_private_key.aks_ssh_key.private_key_pem
  filename = &quot;aks_private_key.pem&quot;
}

# virtual network (aks_vnet) is created in the same resource group
resource &quot;azurerm_virtual_network&quot; &quot;aks_vnet&quot; {
  name                = &quot;${var.resource_group_name}-vnet01&quot;
  # address_space       = [&quot;10.0.0.0/16&quot;]
  address_space       = [&quot;10.172.144.0/26&quot;]
  location            = azurerm_resource_group.aks_rg.location
  resource_group_name = azurerm_resource_group.aks_rg.name
}

# subnet (aks_subnet) is created within the virtual network
resource &quot;azurerm_subnet&quot; &quot;aks_subnet&quot; {
  name                 = &quot;${var.resource_group_name}-vnet01-subnet01&quot;
  resource_group_name  = azurerm_resource_group.aks_rg.name
  virtual_network_name = azurerm_virtual_network.aks_vnet.name
  # address_prefix       = &quot;10.0.1.0/24&quot;
  address_prefix       = &quot;10.172.144.0/27&quot;
}


resource &quot;azurerm_network_security_group&quot; &quot;azure-sg&quot; {
  name                = &quot;${var.resource_group_name}-nsg01&quot;
  location            = azurerm_resource_group.aks_rg.location
  resource_group_name = azurerm_resource_group.aks_rg.name

  security_rule {
    name                       = &quot;allow-ssh&quot;
    priority                   = 100
    direction                  = &quot;Inbound&quot;
    access                     = &quot;Allow&quot;
    protocol                   = &quot;Tcp&quot;
    source_port_range          = &quot;*&quot;
    destination_port_range     = &quot;22&quot;
    source_address_prefix      = &quot;*&quot;
    destination_address_prefix = &quot;*&quot;
  }
}

resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks&quot; {
  name                = var.cluster_name
  kubernetes_version  = var.kubernetes_version
  location            = var.location
  resource_group_name = azurerm_resource_group.aks-rg.name
  security_group_name = azurerm_network_security_group.azure-sg.name
  dns_prefix          = var.cluster_name
  
  default_node_pool {
    name                = &quot;system&quot;
    node_count          = var.system_node_count
    vm_size             = &quot;Standard_E4as_v4&quot;
    os_disk_size_gb     = 20
    os_disk_type        = &quot;Ephemeral&quot;
    vnet_subnet_id      = azurerm_subnet.aks_subnet.id
    os_type             = &quot;Linux&quot;
    node_image_version = &quot;AKSUbuntu-1804gen2containerd-2023.01.10&quot;
    enable_node_public_ip = false
    enable_auto_scaling = false
  }
  additional_node_pools {
    name                = &quot;user&quot;
    node_count          = var.user_node_count
    vm_size             = &quot;Standard_E8as_v4&quot;
    os_disk_size_gb     = 20
    os_disk_type        = &quot;Ephemeral&quot;
    vnet_subnet_id      = azurerm_subnet.aks_subnet.id
    type                = &quot;User&quot;
      # os_type             = &quot;RedHat&quot;
    os_type             = &quot;Linux&quot;
    node_image_version = &quot;AKSUbuntu-1804gen2containerd-2023.01.10&quot;
    enable_node_public_ip = false
    enable_auto_scaling = false
  }
  additional_node_pools {
    name                = &quot;spot&quot;
    node_count          = var.spot_node_count
    vm_size             = &quot;Standard_D2s_v3&quot;
    os_disk_size_gb     = 20
    os_disk_type        = &quot;Ephemeral&quot;
    vnet_subnet_id      = azurerm_subnet.aks_subnet.id
    type                = &quot;User&quot;
      # os_type             = &quot;RedHat&quot;
    os_type             = &quot;Linux&quot;
    node_image_version = &quot;AKSUbuntu-1804gen2containerd-2023.01.10&quot;
    max_price           = 0.5
    enable_node_public_ip = false
    enable_auto_scaling = false
    eviction_policy      = &quot;Spot&quot;
    taints               = [&quot;kubernetes.azure.com/scalesetpriority=spot:NoSchedule&quot;]
    labels = {
      &quot;kubernetes.azure.com/scalesetpriority&quot; = &quot;spot&quot;
    }
  }

  kubernetes_cluster_config {
    max_pods_per_node = &quot;110&quot;
  }
  
  identity {
    type = &quot;SystemAssigned&quot;
  }
  
  linux_profile {
    admin_username = &quot;azureuser&quot;

    ssh_key {
      key_data = tls_private_key.aks_ssh_key.public_key_openssh
    }
  }
  
  network_profile {
    pod_cidr = &quot;172.32.0.0/19&quot;
    service_cidr = &quot;172.32.0.0/19&quot;
    load_balancer_sku = &quot;Standard&quot;
    network_plugin    = var.aks_network_plugin 
    dns_service_ip = &quot;172.32.0.10&quot;
    docker_bridge_cidr = &quot;172.34.0.1/16&quot;
  }
  
  service_principal {
    client_id     = var.client_id
    client_secret = var.client_secret
  }
  
  tags = {
    Environment = &quot;Development&quot;
  }
}

# ACR can be attached to the AKS cluster using the &quot;azurerm_kubernetes_cluster_container_registry_config&quot; resource type
resource &quot;azurerm_kubernetes_cluster_container_registry_config&quot; &quot;acr_config&quot; {
  cluster_name        = azurerm_kubernetes_cluster.aks.name
  registry_id         = azurerm_container_registry.acr.id
  namespace           = &quot;aks&quot;
  default_action      = &quot;Allow&quot;
}
</code></pre>
<p>Above is my Code I am facing above error. I am getting some depreciation. Can anyone please tell me How to solve this error</p>
<p>what i need to replace instead of these errors</p>
<p>Thanks</p>

Vinay Kumar
<p>If you see official doc there is no field like <strong>additional_node_pools</strong> for AKS cluster.</p>
<p>Filed is not supported however still you have added in</p>
<pre><code>resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks&quot;
</code></pre>
<p>so that's the reason behind the error.</p>
<p>Check this doc for adding more node pool : <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster_node_pool" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster_node_pool</a></p>
