diff --git a/quickstart/101-aks-cluster-windows/README.md b/quickstart/101-aks-cluster-windows/README.md new file mode 100644 index 000000000..071782ad1 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/README.md @@ -0,0 +1,25 @@ +# Windows-based Azure Kubernetes Service (AKS) cluster + +This template deploys an AKS cluster with Windows nodes. + +## 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) +- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) +- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) +- [azurerm_kubernetes_cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster) +- [azurerm_kubernetes_cluster_node_pool](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster_node_pool) + +## 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. | eastus | +| `node_count_linux` | Initial quantity of Linux nodes for the node pool. | 1 | +| `node_count_windows` | Initial quantity of Windows nodes for the node pool. | 1 | +| `admin_username` | Admin username for the Windows node pool. | azureuser | +| `admin_password` | Admin password for the Windows node pool. | Passw0rd1234Us! | + +## Example diff --git a/quickstart/101-aks-cluster-windows/main.tf b/quickstart/101-aks-cluster-windows/main.tf new file mode 100644 index 000000000..3795214c6 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/main.tf @@ -0,0 +1,73 @@ +# Generate random resource group name +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id +} + +resource "random_pet" "azurerm_kubernetes_cluster_name" { + prefix = "cluster" +} + +resource "random_pet" "azurerm_kubernetes_cluster_dns_prefix" { + prefix = "dns" +} + +resource "random_string" "azurerm_kubernetes_cluster_node_pool" { + length = 6 + special = false + numeric = false + lower = true + upper = false +} + +resource "azurerm_virtual_network" "vnet" { + name = "myvnet" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + address_space = ["10.1.0.0/16"] + + subnet { + name = "subnet1" + address_prefix = "10.1.1.0/24" + } +} + +resource "azurerm_kubernetes_cluster" "aks" { + name = random_pet.azurerm_kubernetes_cluster_name.id + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + dns_prefix = random_pet.azurerm_kubernetes_cluster_dns_prefix.id + + identity { + type = "SystemAssigned" + } + + default_node_pool { + name = "agentpool" + vm_size = "Standard_D2_v2" + node_count = var.node_count_linux + vnet_subnet_id = element(tolist(azurerm_virtual_network.vnet.subnet), 0).id + } + + windows_profile { + admin_username = var.admin_username + admin_password = var.admin_password + } + + network_profile { + network_plugin = "azure" + load_balancer_sku = "standard" + } +} + +resource "azurerm_kubernetes_cluster_node_pool" "win" { + name = random_string.azurerm_kubernetes_cluster_node_pool.result + kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id + vm_size = "Standard_D4s_v3" + node_count = var.node_count_windows + os_type = "Windows" +} diff --git a/quickstart/101-aks-cluster-windows/outputs.tf b/quickstart/101-aks-cluster-windows/outputs.tf new file mode 100644 index 000000000..7067a4304 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/outputs.tf @@ -0,0 +1,20 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "kubernetes_cluster_name" { + value = azurerm_kubernetes_cluster.aks.name +} + +output "kubernetes_cluster_dns_prefix" { + value = azurerm_kubernetes_cluster.aks.dns_prefix +} + +output "kubernetes_cluster_node_pool_name" { + value = azurerm_kubernetes_cluster_node_pool.win.name +} + +output "kubernetes_cluster_kube_config_raw" { + value = azurerm_kubernetes_cluster.aks.kube_config_raw + sensitive = true +} \ No newline at end of file diff --git a/quickstart/101-aks-cluster-windows/providers.tf b/quickstart/101-aks-cluster-windows/providers.tf new file mode 100644 index 000000000..a0155e168 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/providers.tf @@ -0,0 +1,19 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} + +provider "azurerm" { + features { + } +} diff --git a/quickstart/101-aks-cluster-windows/variables.tf b/quickstart/101-aks-cluster-windows/variables.tf new file mode 100644 index 000000000..2cf992b98 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/variables.tf @@ -0,0 +1,35 @@ +variable "resource_group_location" { + type = string + default = "eastus" + 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 "node_count_linux" { + type = number + description = "The initial quantity of Linux nodes for the node pool." + default = 1 +} + +variable "node_count_windows" { + type = number + description = "The initial quantity of Windows nodes for the node pool." + default = 1 +} + +variable "admin_username" { + type = string + description = "The admin username for the Windows node pool." + default = "azureuser" +} + +variable "admin_password" { + type = string + description = "The admin password for the Windows node pool." + default = "Passw0rd1234Us!" +} \ No newline at end of file