0
votes

Main.tf

provider "azurerm" {
  features {}
}

data "azurestack_resource_group" "demo" {
  name = "k8sample-rg-rg"
}

data "azurestack_subnet" "demo" {
  name                 = "k8sample-rg-subnet"
  virtual_network_name = "k8sample-rg-network"
  resource_group_name  = "k8sample-rg-rg"
}

resource "azurerm_kubernetes_cluster" "demo" {
  name                = "aathi-sample-aks"
  location             = data.azurestack_resource_group.demo.location
  resource_group_name  = data.azurestack_resource_group.demo.name
  dns_prefix          = "aathi-sample-aks"

  default_node_pool {
    name                = "default"
    node_count          = 2
    vm_size             = "Standard_D2_v2"
    type                = "VirtualMachineScaleSets"
    availability_zones  = ["1", "2"]
    enable_auto_scaling = true
    min_count           = 2
    max_count           = 4

    # Required for advanced networking
    vnet_subnet_id = data.azurestack_subnet.demo.id
  }

  identity {
    type = "SystemAssigned"
  }

  network_profile {
    network_plugin    = "azure"
    load_balancer_sku = "standard"
    network_policy    = "calico"
  }

  tags = {
    Environment = "Development"
  }
}

outputs.tf

output "client_certificate" {
  value = azurerm_kubernetes_cluster.demo.kube_config.0.client_certificate
}

output "kube_config" {
  value = azurerm_kubernetes_cluster.demo.kube_config_raw
}

output "resource_group_name" {
  value = data.azurestack_resource_group.demo.name
}

output "resource_group_location" {
  value = data.azurestack_resource_group.demo.location
}

output "subnet_id" {
  value = data.azurestack_subnet.demo.id
}

previously I have created the resource group in my Azure portal. I need to consume these resources for my aks cluster. so I have used the data source method. All the resources id are received in the terminal but I am not able to proceed. I am getting the below error.

Comments to reproduce

  1. terraform init
  2. terraform plan
  3. terraform apply

Before this, we need to create a resource group and Vnet with a subnet in AZURE.

 resource_group_name  = "k8sample-rg-rg"
 virtual_network_name = "k8sample-rg-network"
  Subnet_name         = "k8sample-rg-subnet"

enter image description here

1
What steps do you run to reproduce the above error?Nancy Xiong
terraform init terraform plan terraform applyAthithanambi
But resource groups are running in my azure account.Athithanambi
I am using azurerm and azurestack. please let me know how to use both in the same script.Athithanambi

1 Answers

0
votes

For your issue, it seems that you need to register the cloud for the Azure Stack with the CLI command and it will set the endpoint, more details here. In addition, Azure Stack does not support the AKS cluster, you need to add the service yourself. Take a look at the document here.