Skip to content

AKS Cluster provisioning state check does not catch the state succeeded #7

@anderl80

Description

@anderl80
resource "null_resource" "wait_for_aks" {
  depends_on = [azurerm_kubernetes_cluster.k8s]

  provisioner "local-exec" {
    command = <<EOT
      max_retries=10
      retries=0
      while [ "$(az aks show --resource-group ${azurerm_resource_group.rg.name} --name ${azurerm_kubernetes_cluster.k8s.name} --query "provisioningState" -o tsv)" != "Succeeded" ]; do
        if [ $retries -ge $max_retries ]; then
          echo "Max retries exceeded. Exiting..."
          exit 1
        fi
        echo "Waiting for AKS cluster to be fully provisioned... (Attempt: $((retries+1)))"
        retries=$((retries+1))
        sleep 30
      done
    EOT
  }
}

This script runs endlessly for me though the state is "Succeeded".

I modified the script so it echoes the output of the variable:

while [ "$(az aks show --resource-group ${azurerm_resource_group.rg.name} --name ${azurerm_kubernetes_cluster.k8s.name} --query "provisioningState" -o tsv)" != "Succeeded" ]; do
        echo "Current provisioning state: $(az aks show --resource-group ${azurerm_resource_group.rg.name} --name ${azurerm_kubernetes_cluster.k8s.name} --query "provisioningState" -o tsv)"

Which results in:

➜ terraform apply "main.tfplan"  
null_resource.wait_for_aks: Destroying... [id=9197381911910652745]
null_resource.wait_for_aks: Destruction complete after 0s
azurerm_kubernetes_cluster.k8s: Modifying... [id=/subscriptions/b87de7fe-844d-4fd7-aaa7-2754e58c687a/resourceGroups/rg-calm-marlin/providers/Microsoft.ContainerService/managedClusters/cluster-top-gopher]
azurerm_kubernetes_cluster.k8s: Still modifying... [id=/subscriptions/b87de7fe-844d-4fd7-aaa7-...ice/managedClusters/cluster-top-gopher, 10s elapsed]
azurerm_kubernetes_cluster.k8s: Modifications complete after 20s [id=/subscriptions/b87de7fe-844d-4fd7-aaa7-2754e58c687a/resourceGroups/rg-calm-marlin/providers/Microsoft.ContainerService/managedClusters/cluster-top-gopher]
null_resource.wait_for_aks: Creating...
null_resource.wait_for_aks: Provisioning with 'local-exec'...
null_resource.wait_for_aks (local-exec): Executing: ["/bin/sh" "-c" "      max_retries=10\n      retries=0\n      while [ \"$(az aks show --resource-group rg-calm-marlin --name cluster-top-gopher --query \"provisioningState\" -o tsv)\" != \"Succeeded\" ]; do\n        echo \"Current provisioning state: $(az aks show --resource-group rg-calm-marlin --name cluster-top-gopher --query \"provisioningState\" -o tsv)\"\n        if [ $retries -ge $max_retries ]; then\n          echo \"Max retries exceeded. Exiting...\"\n          exit 1\n        fi\n        echo \"Waiting for AKS cluster to be fully provisioned... (Attempt: $((retries+1)))\"\n        retries=$((retries+1))\n        sleep 30\n      done\n"]
null_resource.wait_for_aks (local-exec): WARNING: The behavior of this command has been altered by the following extension: aks-preview
null_resource.wait_for_aks: Still creating... [12s elapsed]
null_resource.wait_for_aks (local-exec): WARNING: The behavior of this command has been altered by the following extension: aks-preview
null_resource.wait_for_aks (local-exec): Current provisioning state: Succeeded
null_resource.wait_for_aks (local-exec): Waiting for AKS cluster to be fully provisioned... (Attempt: 1)
null_resource.wait_for_aks: Still creating... [22s elapsed]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions