Skip to content
Draft
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 modules/terraform/azure/aks-cli/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,36 @@ locals {
"-n", var.aks_cli_config.aks_name,
"--yes",
])

# Build az rest commands for AKS REST API calls
aks_rest_config_map = {
for config in var.aks_rest_config_list :
config.aks_name => config
}

# Local to build headers string for az rest command
aks_rest_commands = {
for name, config in local.aks_rest_config_map :
name => {
command = join(" ", concat([
"az",
"rest",
"--method", config.method,
"--url", format(
"\"/subscriptions/{subscriptionId}/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s?api-version=%s\"",
var.resource_group_name,
config.aks_name,
config.api_version
),
length(config.headers) > 0 ? concat(
["--headers"],
[join(" ", [for key, value in config.headers : format("%s=%s", key, value)])],
) : [],
config.body != null ? ["--body", format("@%s", config.body)] : [],
]))
dry_run = config.dry_run
}
}
}

data "azurerm_client_config" "current" {}
Expand Down Expand Up @@ -288,6 +318,15 @@ resource "terraform_data" "aks_nodepool_cli" {
}
}

# Execute az rest commands for AKS REST API calls
resource "terraform_data" "aks_rest_cli" {
for_each = local.aks_rest_commands

provisioner "local-exec" {
command = each.value.dry_run ? "echo '${each.value.command}'" : each.value.command
}
}

# Grant AKS identity KMS-related Key Vault roles
resource "azurerm_role_assignment" "aks_identity_kms_roles" {
for_each = local.aks_kms_role_assignments
Expand Down
17 changes: 17 additions & 0 deletions modules/terraform/azure/aks-cli/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,20 @@ variable "aks_cli_config" {
})
}

variable "aks_rest_config_list" {
description = "List of AKS REST API configurations for direct REST API calls"
type = list(object({
role = string
aks_name = string
sku_tier = string
sku_name = optional(string, null)
kubernetes_version = optional(string, null)
method = string # HTTP method (GET, PUT, POST, PATCH, DELETE)
api_version = string # API version for the REST call
headers = optional(map(string), {}) # Custom headers for the REST call
body = optional(string, null) # Path to JSON body file for the REST call
dry_run = optional(bool, false) # If true, only print the command without executing it
}))
default = []
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"location": "westus2",
"identity": {
"type": "SystemAssigned"
},
"sku": {
"name": "Base",
"tier": "Standard"
},
"properties": {
"kubernetesVersion": "1.33.0",
"dnsPrefix": "cpsp-test",
"agentPoolProfiles": [
{
"name": "nodepool1",
"count": 3,
"vmSize": "Standard_DS2_v2",
"osType": "Linux",
"mode": "System"
}
],
"networkProfile": {
"networkPlugin": "azure",
"networkPluginMode": "overlay",
"podCidr": "10.244.0.0/16"
},
"controlPlaneScalingProfile": {
"scalingSize": "H2"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ aks_rest_config_list = [
aks_name = "ccp-provisioning-H2"
sku_tier = "Standard"
sku_name = "Base"
api_version = "2026-01-02-preview"
control_plane_scaling_size = "H2"
kubernetes_version = "1.33"
network_plugin = "azure"
network_plugin_mode = "overlay"
default_node_pool = {
name = "systempool"
mode = "System"
node_count = 3
vm_size = "Standard_D2s_v5"
os_type = "Linux"
method = "PUT"
api_version = "2026-01-02-preview" # to construct url
headers = {
"Content-Type" = "application/json"
}
body = "scenarios/perf-eval/ccp-provisioning/kubernetes/azure-H2-body.json"
# az rest --method PUT --url "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.ContainerService/managedClusters/{clusterName}?api-version=2026-01-02-preview" --headers "Content-Type=application/json" --body @scenarios/perf-eval/ccp-provisioning/kubernetes/azure-H2-body.json
}
]