<p>Terraform plan always forces AKS cluster to be recreated if we increase  worker node in node pool</p>
<p>Trying Creating AKS Cluster with 1 worker node, via Terraform, it went well , Cluster is Up and running.</p>
<p><a href="https://i.stack.imgur.com/ZAQOc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZAQOc.png" alt="enter image description here" /></a></p>
<p>Post that, i tried to add one more worker node in my AKS, Terraform Show Plan: 2 to add, 0 to change, 2 to destroy.</p>
<p><a href="https://i.stack.imgur.com/IEKkD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IEKkD.png" alt="enter image description here" /></a></p>
<p>Not Sure how can we increase worker node in aks node pool, if it delate the existing node pool.</p>
<pre><code>  default_node_pool {
    name                  = var.nodepool_name
    vm_size               = var.instance_type
    orchestrator_version  = data.azurerm_kubernetes_service_versions.current.latest_version
    availability_zones    = var.zones
    enable_auto_scaling   = var.node_autoscalling
    node_count            = var.instance_count
    enable_node_public_ip = var.publicip
    vnet_subnet_id        = data.azurerm_subnet.subnet.id
    node_labels = {
      &quot;node_pool_type&quot;         = var.tags[0].node_pool_type
      &quot;environment&quot;            = var.tags[0].environment
      &quot;nodepool_os&quot;            = var.tags[0].nodepool_os
      &quot;application&quot;            = var.tags[0].application
      &quot;manged_by&quot;              = var.tags[0].manged_by
 }
}
</code></pre>
<p>Error</p>
<pre><code>Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # azurerm_kubernetes_cluster.aks_cluster must be replaced
-/+ resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks_cluster&quot; {
</code></pre>
<p>Thanks
Satyam</p>

Satyam Pandey
<p><em><strong>I tested the same in my environment by creating a cluster with 2 node counts and then changed it to 3 using something like below :</strong></em></p>
<p><a href="https://i.stack.imgur.com/H9RHK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H9RHK.png" alt="enter image description here" /></a></p>
<p>If you are using <code>HTTP_proxy</code> then it will <em><strong>by default force a replacement on that block</strong></em> and that's the reason the whole cluster will get replaced with the new configurations.</p>
<p><a href="https://i.stack.imgur.com/FajBY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FajBY.png" alt="enter image description here" /></a></p>
<p>So, for a solution you can use lifecycle block in your code as I have done below:</p>
<pre><code>  lifecycle {
    ignore_changes = [http_proxy_config]
  }
</code></pre>
<p><em><strong>The code will be :</strong></em></p>
<pre><code>resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks_cluster&quot; {
  name                       = &quot;${var.global-prefix}-${var.cluster-id}-${var.envid}-azwe-aks-01&quot;
  location                   = data.azurerm_resource_group.example.location
  resource_group_name        = data.azurerm_resource_group.example.name
  dns_prefix                 = &quot;${var.global-prefix}-${var.cluster-id}-${var.envid}-azwe-aks-01&quot;
  kubernetes_version         = var.cluster-version
  private_cluster_enabled    = var.private_cluster



  default_node_pool {
    name                  = var.nodepool_name
    vm_size               = var.instance_type
    orchestrator_version  = data.azurerm_kubernetes_service_versions.current.latest_version
    availability_zones    = var.zones
    enable_auto_scaling   = var.node_autoscalling
    node_count            = var.instance_count
    enable_node_public_ip = var.publicip
    vnet_subnet_id        = azurerm_subnet.example.id  
  }


# RBAC and Azure AD Integration Block
  role_based_access_control {
    enabled = true
} 

  http_proxy_config {
    http_proxy       = &quot;http://xxxx&quot;
    https_proxy      = &quot;http://xxxx&quot;
    no_proxy         = [&quot;localhost&quot;,&quot;xxx&quot;,&quot;xxxx&quot;]
  }
# Identity (System Assigned or Service Principal)
  identity {
    type = &quot;SystemAssigned&quot;
}

# Add On Profiles
  addon_profile {
    azure_policy {enabled =  true}
  }
# Network Profile
  network_profile {
    network_plugin = &quot;azure&quot;
    network_policy = &quot;calico&quot;
  }
  lifecycle {
    ignore_changes = [http_proxy_config]
  }
}
</code></pre>
