-
Notifications
You must be signed in to change notification settings - Fork 513
Expand file tree
/
Copy pathmain.tf
More file actions
92 lines (80 loc) · 3.28 KB
/
main.tf
File metadata and controls
92 lines (80 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
data "azapi_client_config" "current" {}
resource "azapi_resource_action" "register_encryption_at_host" {
type = "Microsoft.Compute/features@2021-07-01"
resource_id = "/subscriptions/${data.azapi_client_config.current.subscription_id}/providers/Microsoft.Features/providers/Microsoft.Compute/features/EncryptionAtHost"
action = "register"
method = "POST"
}
resource "random_id" "prefix" {
byte_length = 8
}
resource "azurerm_resource_group" "main" {
count = var.create_resource_group ? 1 : 0
location = var.location
name = coalesce(var.resource_group_name, "${random_id.prefix.hex}-rg")
}
locals {
resource_group = {
name = var.create_resource_group ? azurerm_resource_group.main[0].name : var.resource_group_name
location = var.location
}
}
resource "azurerm_virtual_network" "test" {
address_space = ["10.52.0.0/16"]
location = local.resource_group.location
name = "${random_id.prefix.hex}-vn"
resource_group_name = local.resource_group.name
}
resource "azurerm_subnet" "default_node_pool_subnet" {
address_prefixes = ["10.52.0.0/24"]
name = "${random_id.prefix.hex}-defaultsn"
resource_group_name = local.resource_group.name
virtual_network_name = azurerm_virtual_network.test.name
private_endpoint_network_policies = "Disabled"
private_link_service_network_policies_enabled = true
}
resource "azurerm_subnet" "node_pool_subnet" {
count = 3
address_prefixes = ["10.52.${count.index + 1}.0/24"]
name = "${random_id.prefix.hex}-sn${count.index}"
resource_group_name = local.resource_group.name
virtual_network_name = azurerm_virtual_network.test.name
private_endpoint_network_policies = "Disabled"
private_link_service_network_policies_enabled = true
}
locals {
nodes = {
for i in range(3) : "worker${i}" => {
name = substr("worker${i}${random_id.prefix.hex}", 0, 8)
vm_size = "Standard_D2s_v3"
node_count = 1
vnet_subnet = { id = azurerm_subnet.node_pool_subnet[i].id }
create_before_destroy = i % 2 == 0
upgrade_settings = {
drain_timeout_in_minutes = 0
node_soak_duration_in_minutes = 0
max_surge = "10%"
}
}
}
}
module "aks" {
source = "../.."
prefix = "prefix-${random_id.prefix.hex}"
resource_group_name = local.resource_group.name
location = local.resource_group.location
os_disk_size_gb = 60
sku_tier = "Standard"
oidc_issuer_enabled = true
private_cluster_enabled = false
vnet_subnet = {
id = azurerm_subnet.default_node_pool_subnet.id
}
node_pools = local.nodes
kubernetes_version = var.kubernetes_version
orchestrator_version = var.orchestrator_version
create_role_assignment_network_contributor = true
depends_on = [
azapi_resource_action.register_encryption_at_host,
]
}