Skip to content

Commit

Permalink
Merge pull request #329 from TomArcherMsft/UserStory275199
Browse files Browse the repository at this point in the history
User Story 275199
  • Loading branch information
stemaMSFT authored Jul 3, 2024
2 parents 64c9af2 + bf2f1f5 commit b355126
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 0 deletions.
25 changes: 25 additions & 0 deletions quickstart/101-aks-cluster-windows/README.md
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions quickstart/101-aks-cluster-windows/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
20 changes: 20 additions & 0 deletions quickstart/101-aks-cluster-windows/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions quickstart/101-aks-cluster-windows/providers.tf
Original file line number Diff line number Diff line change
@@ -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 {
}
}
35 changes: 35 additions & 0 deletions quickstart/101-aks-cluster-windows/variables.tf
Original file line number Diff line number Diff line change
@@ -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!"
}

0 comments on commit b355126

Please sign in to comment.