1
votes

I have been trying to deploy aks cluster using terraform. Below is my template file:
main.tf

locals {
  cluster_name               = "aks-${random_integer.random_int.result}"
  agents_resource_group_name = "MC_${var.resource_group_name}_${local.cluster_name}_${azurerm_resource_group.k8s.location}"
}

resource "azurerm_resource_group" "k8s" {
  name     = "${var.resource_group_name}"
  location = "${var.resource_group_location}"
}

#Keep the AKS name (and dns label) somewhat unique
resource "random_integer" "random_int" {
  min = 100
  max = 999
}

resource "azurerm_kubernetes_cluster" "k8s" {
  name                = "${local.cluster_name}"
  location            = "${azurerm_resource_group.k8s.location}"
  resource_group_name = "${azurerm_resource_group.k8s.name}"
  dns_prefix          = "${local.cluster_name}"

  linux_profile {
    admin_username = "${var.linux_admin_username}"

    ssh_key {
      key_data = "${file("${var.linux_admin_ssh_publickey}")}"
    }
  }

  agent_pool_profile {
    name            = "agentpool"
    count           = "${var.node_count}"
    vm_size         = "${var.vm_size}"
    os_type         = "Linux"
    os_disk_size_gb = "${var.os_disk_size_gb}"
  }

  service_principal {
    client_id     = "${var.client_id}"
    client_secret = "${var.client_secret}"
  }

  tags {
    Environment = "Production"
  }
}

data "azurerm_resource_group" "agents" {
  name = "${local.agents_resource_group_name}"

  depends_on = [
    "azurerm_kubernetes_cluster.k8s",
  ]
}  

The variables are all correct since I face no errors with respect to it. The error that I keep getting after ~2m is

azurerm_kubernetes_cluster.k8s: Error waiting for completion of Managed Kubernetes Cluster "aks-136" (Resource Group "azure-aks"): Code="NotFound" Message="resources.DeploymentsClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code=\"DeploymentNotFound\" Message=\"Deployment '898a5255-0c27-4eed-963a-65183e7d693c' could not be found.\"

It does seem like azure API is refusing to respond and maybe terraform recognizes that as an error and panics.

2
looks weird, do you see any errors on the portal? are there any deployments in the said resource group?4c74356b41
It seems your deployment is failed. There are two possible reasons on my side. One is your quota is not enough. Another is the region you deploy do not support the AKS, at least current.Charles Xu
@CharlesXu Thanks, that helped! Would you post this as an answer?Anshul Verma
@AnshulVerma I add the answer.Charles Xu

2 Answers

0
votes

From the error shows, it seems your deployment is failed. There are two possible reasons on my side. One is your quota is not enough. Another is the region you deploy do not support the AKS, at least current.

0
votes

Try Below code

    #variables file
arm_subscription_id = "XXXXXXXXXXXXXXXXXXXXXXXXXXX"

arm_client_id = "XXXXXXXXXXXXXXXXXXXXXXX"

arm_client_secret = "XXXXXXXXXXXXXXXXXXX"

arm_tenent_id = "XXXXXXXXXXXXXXX"

resource_group_name = "k8terraform"

location = "East US"

cluster_name = "k8terraform"

dns_prifix = "k8terraform1232"

#Running on a Windows add front slash to ignore characters 
ssh_public_key = "E:\\DevOps\\Terraform\\Azure\\AKS\\aksdeploy"

agent_count = 3

#Variable
variable "arm_subscription_id" {
}

variable "arm_client_id" {
}

variable "arm_client_secret" {
}

variable "arm_tenent_id" {
}

variable "location" {
}

variable "cluster_name" {
}

variable "dns_prifix" {
}

variable "ssh_public_key" {
}

variable "agent_count" {
    default = 3
}

variable "resource_group_name" {
}

#Add Azure Provider
provider "azurerm" {
}

#Create Resource Group
resource "azurerm_resource_group" "k8terraform" {
    name = "${var.resource_group_name}"
    location = "${var.location}"
}

#Create AKS Cluster
resource "azurerm_kubernetes_cluster" "k8cluster" {
    name = "${var.cluster_name}"
    location = "${azurerm_resource_group.k8terraform.location}"
    resource_group_name = "${azurerm_resource_group.k8terraform.name}"
    dns_prefix = "${var.dns_prifix}"

    linux_profile{
        admin_username = "localadmin"
        ssh_key{
            key_data = "${file("${var.ssh_public_key}")}"
        }
    }

    agent_pool_profile{
        name = "aksterraform"
        count = "${var.agent_count}"
        vm_size = "Standard_B2ms"
        os_type = "Linux"
        os_disk_size_gb = 30
    }

    service_principal{
        client_id = "${var.arm_client_id}"
        client_secret = "${var.arm_client_secret}"
    }
    tags{
        Environment = "Development"
    }
}

#Outputs -Optional
#output "kube_config" {
#  value = "${azurerm_kubernetes_cluster.k8s.kube_config_raw}"
#}

#output "host" {
#  value = "${azurerm_kubernetes_cluster.k8s.kube_config.0.host}"
#}