Skip to content

Commit 051288b

Browse files
author
Allen Kim
committed
feat: added aks resources
1 parent 3b2d800 commit 051288b

8 files changed

+266
-0
lines changed

examples/.terraform.lock.hcl

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/main.tf

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
data "azurerm_resource_group" "test_aks_rg" {
2+
name = var.aks_rg_name
3+
}
4+
5+
data "azurerm_virtual_network" "aks_vnet" {
6+
name = var.aks_vnet_name
7+
resource_group_name = data.azurerm_resource_group.test_aks_rg.name
8+
}
9+
10+
data "azurerm_subnet" "aks_subnet" {
11+
name = var.aks_subnet_name
12+
virtual_network_name = data.azurerm_virtual_network.aks_vnet.name
13+
resource_group_name = data.azurerm_resource_group.test_aks_rg.name
14+
}
15+
16+
module "test_rg" {
17+
source = "../"
18+
19+
name_prefix = var.name_prefix
20+
location = var.location
21+
22+
aks_rg = data.azurerm_resource_group.test_aks_rg
23+
24+
# Worker node pool
25+
worker_node_pool_name = var.worker_node_pool_name
26+
worker_node_count = var.worker_node_count
27+
worker_node_vm_size = var.worker_node_vm_size
28+
29+
# AKS Identity
30+
identity = var.identity
31+
32+
# Network
33+
aks_subnet = data.azurerm_subnet.ask_subnet
34+
}

examples/variables.tf

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
variable "location" {
2+
type = string
3+
description = "Azure Region name"
4+
default = "Canada Central"
5+
}
6+
7+
# AKS
8+
variable "kubernetes_version" {
9+
type = string
10+
default = "1.22.6"
11+
}
12+
13+
variable "aks_rg_name" {
14+
type = string
15+
description = "The aks resource group name"
16+
}
17+
18+
variable "worker_node_vm_size" {
19+
type = string
20+
default = "Standard_D2_v2"
21+
description = "The work node count"
22+
}
23+
24+
variable "worker_node_count" {
25+
type = number
26+
default = 1
27+
description = "The worker node count"
28+
}
29+
30+
variable "worker_node_pool_name" {
31+
type = string
32+
default = "work-node-pool"
33+
description = "The work node pool name"
34+
}
35+
36+
variable "identity" {
37+
type = string
38+
default = "SystemAssigned"
39+
}
40+
41+
# Network
42+
variable "aks_vnet_name" {
43+
type = string
44+
description = "The aks virtual network name"
45+
}
46+
47+
variable "aks_subnet_name" {
48+
type = string
49+
description = "The aks subnet name"
50+
default = "subnet1"
51+
}
52+
53+
variable "aks_network_plugin" {
54+
type = string
55+
description = "The network plugin for AKS"
56+
default = "kubenet"
57+
}

main.tf

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
resource "azurerm_kubernetes_cluster" "aks-rs" {
2+
name = "${var.name_prefix}-${random_string.name_postfix.result}"
3+
location = var.location
4+
resource_group_name = var.aks_rg.name
5+
dns_prefix = var.aks_dns_prefix
6+
7+
kubernetes_version = var.kubernetes_version
8+
role_based_access_control_enabled = true
9+
10+
default_node_pool {
11+
name = var.worker_node_pool_name
12+
node_count = var.worker_node_count
13+
vm_size = var.worker_node_vm_size
14+
15+
enable_node_public_ip = false
16+
17+
vnet_subnet_id = var.ask_subnet.id
18+
19+
tags = {
20+
createdBy = var.owner
21+
environment = "test"
22+
}
23+
}
24+
25+
identity {
26+
type = var.identity
27+
}
28+
29+
network_profile {
30+
network_plugin = var.aks_network_plugin
31+
load_balancer_sku = "standard"
32+
outbound_type = "userDefinedRouting"
33+
}
34+
35+
tags = {
36+
createdBy = var.owner
37+
environment = "test"
38+
}
39+
}

network.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "azurerm_role_assignment" "example" {
2+
scope = azurerm_resource_group.example.id
3+
role_definition_name = "Network Contributor"
4+
principal_id = azurerm_kubernetes_cluster.example.identity.0.principal_id
5+
}

outputs.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "client_certificate" {
2+
value = azurerm_kubernetes_cluster.aks-rs.kube_config.0.client_certificate
3+
sensitive = true
4+
}
5+
6+
output "kube_config" {
7+
value = azurerm_kubernetes_cluster.aks-rs.kube_config_raw
8+
sensitive = true
9+
}

providers.tf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
terraform {
2+
required_providers {
3+
azurerm = {
4+
source = "hashicorp/azurerm"
5+
version = "~> 3.20"
6+
}
7+
random = {
8+
source = "hashicorp/random"
9+
version = "3.4.2"
10+
}
11+
}
12+
}

variables.tf

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
variable "location" {
2+
type = string
3+
description = "Azure Region name"
4+
default = "Canada Central"
5+
}
6+
7+
variable "name_prefix" {
8+
type = string
9+
description = "The virtual machine name's prefix"
10+
default = "test-vm"
11+
}
12+
13+
variable "owner" {
14+
type = string
15+
description = "The owner name"
16+
default = "Allen"
17+
}
18+
19+
# Kubernetes
20+
variable "aks_rg" {
21+
type = any
22+
description = "The resource group object for the Kubernets resources"
23+
}
24+
25+
variable "worker_node_vm_size" {
26+
type = string
27+
default = "Standard_D2_v2"
28+
description = "The work node count"
29+
}
30+
31+
variable "worker_node_count" {
32+
type = number
33+
default = 1
34+
description = "The worker node count"
35+
}
36+
37+
variable "worker_node_pool_name" {
38+
type = string
39+
default = "work-node-pool1"
40+
description = "The work node pool name"
41+
}
42+
43+
variable "identity" {
44+
type = string
45+
default = "SystemAssigned"
46+
}
47+
48+
variable "aks_dns_prefix" {
49+
type = string
50+
default = "testaks1"
51+
}
52+
53+
variable "kubernetes_version" {
54+
type = string
55+
default = "1.22.6"
56+
}
57+
58+
# Network
59+
variable "aks_subnet" {
60+
type = any
61+
description = "The subnet object for AKS"
62+
}
63+
64+
variable "aks_network_plugin" {
65+
type = string
66+
description = "The network plugin for AKS"
67+
default = "kubenet"
68+
}

0 commit comments

Comments
 (0)