diff --git a/quickstart/101-aks-automatic-azapi/main.tf b/quickstart/101-aks-automatic-azapi/main.tf new file mode 100644 index 000000000..f42c0f3ba --- /dev/null +++ b/quickstart/101-aks-automatic-azapi/main.tf @@ -0,0 +1,39 @@ +# Create a random name for the resource group using random_pet +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +# Create a resource group using the generated random name +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id +} + +# Create a random name for the AKS Automatic cluster +resource "random_pet" "cluster_name" { + prefix = var.cluster_name_prefix +} + +# Create the AKS Automatic cluster. +# The AzAPI provider is used here to get direct control over the managed cluster +# API payload and API version. Reach for this pattern when you need a property +# or an API version that the AzureRM provider hasn't surfaced yet. For the +# provider-native equivalent, see the 101-aks-automatic sample. +resource "azapi_resource" "aks_automatic" { + type = "Microsoft.ContainerService/managedClusters@2026-02-01" + name = random_pet.cluster_name.id + parent_id = azurerm_resource_group.rg.id + location = azurerm_resource_group.rg.location + + identity { + type = "SystemAssigned" + } + + body = { + sku = { + name = "Automatic" + } + } + + response_export_values = ["properties.nodeResourceGroup", "properties.fqdn"] +} diff --git a/quickstart/101-aks-automatic-azapi/outputs.tf b/quickstart/101-aks-automatic-azapi/outputs.tf new file mode 100644 index 000000000..a4a376c88 --- /dev/null +++ b/quickstart/101-aks-automatic-azapi/outputs.tf @@ -0,0 +1,15 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "cluster_name" { + value = azapi_resource.aks_automatic.name +} + +output "cluster_id" { + value = azapi_resource.aks_automatic.id +} + +output "node_resource_group" { + value = azapi_resource.aks_automatic.output.properties.nodeResourceGroup +} diff --git a/quickstart/101-aks-automatic-azapi/providers.tf b/quickstart/101-aks-automatic-azapi/providers.tf new file mode 100644 index 000000000..2c375b07c --- /dev/null +++ b/quickstart/101-aks-automatic-azapi/providers.tf @@ -0,0 +1,24 @@ +terraform { + required_version = ">= 1.0" + required_providers { + azapi = { + source = "Azure/azapi" + version = "~>2.0" + } + azurerm = { + source = "hashicorp/azurerm" + version = "~>5.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} + +provider "azurerm" { + features {} +} + +provider "azapi" { +} diff --git a/quickstart/101-aks-automatic-azapi/readme.md b/quickstart/101-aks-automatic-azapi/readme.md new file mode 100644 index 000000000..0597630ca --- /dev/null +++ b/quickstart/101-aks-automatic-azapi/readme.md @@ -0,0 +1,30 @@ +# Azure Kubernetes Service (AKS) Automatic cluster (AzAPI provider) + +This template deploys an AKS Automatic cluster with a system-assigned managed identity into a resource group with a random name beginning with "rg-". + +The cluster is declared with the AzAPI provider's [`azapi_resource`](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/resource) against the `Microsoft.ContainerService/managedClusters` API. Use this pattern when you need direct control over the managed cluster API payload, or when you need an API version or property that the AzureRM provider doesn't expose yet. The cluster SKU is hard-coded to `Automatic`. + +For the equivalent sample that uses the AzureRM provider's `azurerm_kubernetes_automatic_cluster` resource, see [101-aks-automatic](../101-aks-automatic/). + +## Terraform resource types + +- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +- [azapi_resource](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/resource) + +## Variables + +| Name | Description | Default | +|-|-|-| +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | westus2 | +| `cluster_name_prefix` | Prefix of the AKS Automatic cluster name that's combined with a random ID so the name is unique in your Azure subscription. | aks-automatic | + +## Example + +```console +terraform init -upgrade +terraform plan -out main.tfplan +terraform apply main.tfplan +``` + diff --git a/quickstart/101-aks-automatic-azapi/variables.tf b/quickstart/101-aks-automatic-azapi/variables.tf new file mode 100644 index 000000000..9bbb8f888 --- /dev/null +++ b/quickstart/101-aks-automatic-azapi/variables.tf @@ -0,0 +1,17 @@ +variable "resource_group_location" { + type = string + default = "westus2" + description = "Location of the resource group." +} + +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "cluster_name_prefix" { + type = string + default = "aks-automatic" + description = "Prefix of the AKS Automatic cluster name that's combined with a random ID so the name is unique in your Azure subscription." +} diff --git a/quickstart/101-aks-automatic/main.tf b/quickstart/101-aks-automatic/main.tf new file mode 100644 index 000000000..cbeb2e7af --- /dev/null +++ b/quickstart/101-aks-automatic/main.tf @@ -0,0 +1,26 @@ +# Create a random name for the resource group using random_pet +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +# Create a resource group using the generated random name +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id +} + +# Create a random name for the AKS Automatic cluster +resource "random_pet" "cluster_name" { + prefix = var.cluster_name_prefix +} + +# Create the AKS Automatic cluster +resource "azurerm_kubernetes_automatic_cluster" "aks_automatic" { + name = random_pet.cluster_name.id + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + identity { + type = "SystemAssigned" + } +} diff --git a/quickstart/101-aks-automatic/outputs.tf b/quickstart/101-aks-automatic/outputs.tf new file mode 100644 index 000000000..9bec44003 --- /dev/null +++ b/quickstart/101-aks-automatic/outputs.tf @@ -0,0 +1,19 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "cluster_name" { + value = azurerm_kubernetes_automatic_cluster.aks_automatic.name +} + +output "cluster_id" { + value = azurerm_kubernetes_automatic_cluster.aks_automatic.id +} + +output "node_resource_group_id" { + value = azurerm_kubernetes_automatic_cluster.aks_automatic.node_resource_group_id +} + +output "fully_qualified_domain_name" { + value = azurerm_kubernetes_automatic_cluster.aks_automatic.fully_qualified_domain_name +} diff --git a/quickstart/101-aks-automatic/providers.tf b/quickstart/101-aks-automatic/providers.tf new file mode 100644 index 000000000..9e76a7ea8 --- /dev/null +++ b/quickstart/101-aks-automatic/providers.tf @@ -0,0 +1,17 @@ +terraform { + required_version = ">= 1.0" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>5.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} + +provider "azurerm" { + features {} +} diff --git a/quickstart/101-aks-automatic/readme.md b/quickstart/101-aks-automatic/readme.md new file mode 100644 index 000000000..2639fe99d --- /dev/null +++ b/quickstart/101-aks-automatic/readme.md @@ -0,0 +1,30 @@ +# Azure Kubernetes Service (AKS) Automatic cluster (AzureRM provider) + +This template deploys an AKS Automatic cluster with a system-assigned managed identity into a resource group with a random name beginning with "rg-". + +The cluster is created with the AzureRM provider's [`azurerm_kubernetes_automatic_cluster`](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_automatic_cluster) resource, which is the recommended way to declare an AKS Automatic cluster. This resource requires AzureRM provider `v4.81` or later. + +For an equivalent sample that declares the same cluster with the AzAPI provider, see [101-aks-automatic-azapi](../101-aks-automatic-azapi/). + +## Terraform resource types + +- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +- [azurerm_kubernetes_automatic_cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_automatic_cluster) + +## Variables + +| Name | Description | Default | +|-|-|-| +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | westus2 | +| `cluster_name_prefix` | Prefix of the AKS Automatic cluster name that's combined with a random ID so the name is unique in your Azure subscription. | aks-automatic | + +## Example + +```console +terraform init -upgrade +terraform plan -out main.tfplan +terraform apply main.tfplan +``` + diff --git a/quickstart/101-aks-automatic/variables.tf b/quickstart/101-aks-automatic/variables.tf new file mode 100644 index 000000000..9bbb8f888 --- /dev/null +++ b/quickstart/101-aks-automatic/variables.tf @@ -0,0 +1,17 @@ +variable "resource_group_location" { + type = string + default = "westus2" + description = "Location of the resource group." +} + +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "cluster_name_prefix" { + type = string + default = "aks-automatic" + description = "Prefix of the AKS Automatic cluster name that's combined with a random ID so the name is unique in your Azure subscription." +}