Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions quickstart/101-aks-automatic-azapi/main.tf
Original file line number Diff line number Diff line change
@@ -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"]
}
15 changes: 15 additions & 0 deletions quickstart/101-aks-automatic-azapi/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions quickstart/101-aks-automatic-azapi/providers.tf
Original file line number Diff line number Diff line change
@@ -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" {
}
30 changes: 30 additions & 0 deletions quickstart/101-aks-automatic-azapi/readme.md
Original file line number Diff line number Diff line change
@@ -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
```

17 changes: 17 additions & 0 deletions quickstart/101-aks-automatic-azapi/variables.tf
Original file line number Diff line number Diff line change
@@ -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."
}
26 changes: 26 additions & 0 deletions quickstart/101-aks-automatic/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
19 changes: 19 additions & 0 deletions quickstart/101-aks-automatic/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions quickstart/101-aks-automatic/providers.tf
Original file line number Diff line number Diff line change
@@ -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 {}
}
30 changes: 30 additions & 0 deletions quickstart/101-aks-automatic/readme.md
Original file line number Diff line number Diff line change
@@ -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
```

17 changes: 17 additions & 0 deletions quickstart/101-aks-automatic/variables.tf
Original file line number Diff line number Diff line change
@@ -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."
}