Skip to content

Commit e3c3bc2

Browse files
authored
Merge pull request #92 from pluralsh/marcin/prod-3389-azure-cluster-pr-automation
feat: AKS module
2 parents c715cfb + 3d28bbb commit e3c3bc2

File tree

8 files changed

+215
-1
lines changed

8 files changed

+215
-1
lines changed

setup/pr-automation/cluster-creator.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ spec:
4242
documentation: what tier to place this cluster in
4343
values:
4444
- dev
45-
- prd
45+
- prod
46+
- name: resourceGroup
47+
type: STRING
48+
documentation: Azure resource group that you would like to use.
49+
condition:
50+
field: cloud
51+
operation: EQ
52+
value: 'azure'

templates/clusters/stack.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ spec:
2121
cluster: {{ context.name }}
2222
fleet: {{ context.fleet }}
2323
tier: {{ context.tier }}
24+
{% if context.cloud == 'azure' %}
25+
resource_group_name: {{ context.resourceGroup }}
26+
jobSpec:
27+
namespace: plrl-deploy-operator
28+
labels:
29+
azure.workload.identity/use: "true"
30+
serviceAccount: "stacks"
31+
{% endif %}
2432
git:
2533
ref: main
2634
folder: terraform/modules/clusters/{{ context.cloud }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module "aks" {
2+
source = "Azure/aks/azurerm"
3+
version = "9.2.0"
4+
5+
kubernetes_version = var.kubernetes_version
6+
cluster_name = var.cluster
7+
resource_group_name = data.azurerm_resource_group.default.name
8+
prefix = var.cluster
9+
os_disk_size_gb = 60
10+
sku_tier = "Standard"
11+
rbac_aad = false
12+
vnet_subnet_id = local.network.sn_subnet_id
13+
node_pools = {for name, pool in var.node_pools : name => merge(pool, {name = name, vnet_subnet_id = local.network.sn_subnet_id})}
14+
15+
ebpf_data_plane = "cilium"
16+
network_plugin_mode = "overlay"
17+
network_plugin = "azure"
18+
19+
role_based_access_control_enabled = true
20+
21+
workload_identity_enabled = var.workload_identity_enabled
22+
oidc_issuer_enabled = var.workload_identity_enabled
23+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
data "azurerm_resource_group" "default" {
2+
name = var.resource_group_name
3+
}
4+
5+
resource "azurerm_user_assigned_identity" "dns" {
6+
name = "${var.cluster}-dns"
7+
resource_group_name = data.azurerm_resource_group.default.name
8+
location = data.azurerm_resource_group.default.location
9+
}
10+
11+
resource "azurerm_role_assignment" "dns-reader" {
12+
scope = data.azurerm_resource_group.default.id
13+
role_definition_name = "Reader"
14+
principal_id = azurerm_user_assigned_identity.dns.principal_id
15+
}
16+
17+
resource "azurerm_role_assignment" "dns-zone-contributor" {
18+
scope = data.azurerm_resource_group.default.id
19+
role_definition_name = "DNS Zone Contributor"
20+
principal_id = azurerm_user_assigned_identity.dns.principal_id
21+
}
22+
23+
resource "azurerm_federated_identity_credential" "plural-runtime" {
24+
name = "${var.cluster}-plural-runtime"
25+
resource_group_name = data.azurerm_resource_group.default.name
26+
audience = ["api://AzureADTokenExchange"]
27+
issuer = module.aks.oidc_issuer_url
28+
parent_id = azurerm_user_assigned_identity.dns.id
29+
subject = "system:serviceaccount:plural-runtime:external-dns"
30+
}
31+
32+
resource "azurerm_federated_identity_credential" "external-dns" {
33+
name = "${var.cluster}-external-dns"
34+
resource_group_name = data.azurerm_resource_group.default.name
35+
audience = ["api://AzureADTokenExchange"]
36+
issuer = module.aks.oidc_issuer_url
37+
parent_id = azurerm_user_assigned_identity.dns.id
38+
subject = "system:serviceaccount:external-dns:external-dns"
39+
}
40+
41+
resource "azurerm_federated_identity_credential" "cert-manager" {
42+
name = "${var.cluster}-cert-manager"
43+
resource_group_name = data.azurerm_resource_group.default.name
44+
audience = ["api://AzureADTokenExchange"]
45+
issuer = module.aks.oidc_issuer_url
46+
parent_id = azurerm_user_assigned_identity.dns.id
47+
subject = "system:serviceaccount:cert-manager:cert-manager"
48+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
locals {
2+
identity = jsondecode(data.plural_service_context.identity.configuration)
3+
network = jsondecode(data.plural_service_context.network.configuration)
4+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
data "plural_service_context" "identity" {
2+
name = "plrl/azure/identity"
3+
}
4+
5+
data "plural_service_context" "network" {
6+
name = "plrl/network/${var.tier}"
7+
}
8+
9+
resource "plural_service_context" "cluster" {
10+
name = "plrl/clusters/${var.cluster}"
11+
12+
configuration = jsonencode({
13+
cluster_name = var.cluster
14+
})
15+
}
16+
17+
resource "plural_cluster" "cluster" {
18+
handle = var.cluster
19+
name = var.cluster
20+
21+
tags = {
22+
tier = var.tier
23+
fleet = var.fleet
24+
role = "workload"
25+
}
26+
27+
kubeconfig = {
28+
host = module.aks.cluster_fqdn
29+
cluster_ca_certificate = base64decode(module.aks.cluster_ca_certificate)
30+
client_certificate = base64decode(module.aks.client_certificate)
31+
client_key = base64decode(module.aks.client_key)
32+
}
33+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
variable "cluster" {
2+
type = string
3+
default = "plural"
4+
}
5+
6+
variable "fleet" {
7+
type = string
8+
}
9+
10+
variable "tier" {
11+
type = string
12+
}
13+
14+
variable "kubernetes_version" {
15+
type = string
16+
default = "1.30.9"
17+
}
18+
19+
variable "resource_group_name" {
20+
type = string
21+
default = "plural"
22+
}
23+
24+
variable "workload_identity_enabled" {
25+
type = bool
26+
default = true
27+
}
28+
29+
variable "node_pools" {
30+
type = map(any)
31+
default = {
32+
plural = {
33+
vm_size = "Standard_D2s_v3"
34+
node_count = 3
35+
min_count = 1
36+
max_count = 20
37+
enable_auto_scaling = true
38+
}
39+
}
40+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
terraform {
2+
required_version = ">= 1.3"
3+
4+
required_providers {
5+
azurerm = {
6+
source = "hashicorp/azurerm"
7+
version = ">=3.51.0, < 4.0"
8+
}
9+
azapi = {
10+
source = "azure/azapi"
11+
version = ">= 1.4.0, < 2.0"
12+
}
13+
kubernetes = {
14+
source = "hashicorp/kubernetes"
15+
version = ">= 2.10"
16+
}
17+
plural = {
18+
source = "pluralsh/plural"
19+
version = ">= 0.2.9"
20+
}
21+
local = {
22+
source = "hashicorp/local"
23+
}
24+
}
25+
}
26+
27+
provider "azurerm" {
28+
features {
29+
resource_group {
30+
prevent_deletion_if_contains_resources = false
31+
}
32+
}
33+
34+
use_cli = false
35+
use_oidc = true
36+
oidc_token_file_path = "/var/run/secrets/azure/tokens/azure-identity-token"
37+
subscription_id = local.identity["subscription_id"]
38+
tenant_id = local.identity["tenant_id"]
39+
client_id = local.identity["client_id"]
40+
}
41+
42+
provider "azapi" {
43+
use_cli = false
44+
use_oidc = true
45+
oidc_token_file_path = "/var/run/secrets/azure/tokens/azure-identity-token"
46+
subscription_id = local.identity["subscription_id"]
47+
tenant_id = local.identity["tenant_id"]
48+
client_id = local.identity["client_id"]
49+
}
50+
51+
provider "plural" {}

0 commit comments

Comments
 (0)