locals {
prefix="aks4devops" location="eastasia"}
variable"client_id" {
description="Client ID for the Azure provider" type=string}
variable"client_secret" {
description="Client Secret for the Azure provider" type=string}
variable"subscription_id" {
description="Subscription ID for the Azure provider" type=string}
variable"tenant_id" {
description="Tenant ID for the Azure provider" type=string}
resource"azurerm_kubernetes_cluster" "example" { # AKS cluster basic information
name="${local.prefix}-k8s" location=azurerm_resource_group.example.location resource_group_name=azurerm_resource_group.example.name dns_prefix="${local.prefix}-k8s" # node pool settings
default_node_pool {
name="default" node_count=2 min_count=1 max_count=10 vm_size="Standard_DS2_v2" enable_auto_scaling=true } # AKS use system auto created identity
identity {
type="SystemAssigned" }
}
以上集群基本上使用了所有的系统默认配置,除了设定了一个 node pool,这个 node pool 使用了自动扩展,最小节点数为 1,最大节点数为 10。
在阅读了这些文件之后,就可以在本地执行 Terraform 的计划和应用了。
1
2
3
terraform init
terraform plan
terraform apply
在执行以上命令的过程中,我们可以在 Terraform Cloud 的 Web 界面中,看到 Terraform 的执行过程。