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
- terraform init
- terraform plan
- 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"