-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.tf
186 lines (154 loc) · 4.59 KB
/
main.tf
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# =====================
# Self Reference (Me)
# =====================
data "azurerm_client_config" "current" {}
# ================
# Resource Group
# ================
resource "azurerm_resource_group" "shared_rg" {
name = var.shared_rg_name
location = var.location
tags = var.default_tags
}
# ========================
# AKS Clusters Resources
# ========================
# Static IPs
data "azurerm_public_ip" "dev" {
name = "cloudkube-dev-aks-ingress-ip"
resource_group_name = "cloudkube-dev-networking-rg"
}
# data "azurerm_public_ip" "staging" {
# name = "cloudkube-staging-ingress-ip"
# resource_group_name = "cloudkube-staging-${var.staging_suffix}-rg"
# }
# ==============
# Shared Infra
# ==============
module "dns" {
source = "./modules/dns"
# Basics
# base_name = var.base_name
# location = var.location
resource_group_name = var.shared_rg_name
tags = var.default_tags
# DNS Records
dns_zone_name = "cloudkube.io"
cname_records = var.dns_cname_records
a_records = {
dev_cluster = {
name = "dev"
records = [data.azurerm_public_ip.dev.ip_address]
}
dev_cluster_wildcard = {
name = "*.dev"
records = [data.azurerm_public_ip.dev.ip_address]
}
# staging_cluster = {
# name = "staging"
# records = [data.azurerm_public_ip.staging.ip_address]
# }
# staging_cluster_wildcard = {
# name = "*.staging"
# records = [data.azurerm_public_ip.staging.ip_address]
# }
}
}
# ======================
# GitHub Workflows IDs
# ======================
module "github_identities" {
source = "./modules/github-federated-identity"
for_each = var.github_identities
base_name = each.value.base_name # SP & credential base name
github_org = each.value.github_org
github_repo = each.value.github_repo
github_env = each.value.github_env
# MSFT Internal requirement
service_management_reference = var.service_management_reference
}
# =========================
# Consolidated Identities
# =========================
# because can't use variable interpolation in .tfvars
locals {
dev_identtiies = {
kubelet = {
identity_name = "cloudkube-dev-${var.dev_suffix}-kubelet-mi"
resource_group = "cloudkube-dev-${var.dev_suffix}-rg"
}
ingress_mi = {
identity_name = "ingress-${var.dev_suffix}-workload-mi"
resource_group = "cloudkube-dev-${var.dev_suffix}-rg"
}
hello_world_mi = {
identity_name = "hello-world-${var.dev_suffix}-workload-mi"
resource_group = "cloudkube-dev-${var.dev_suffix}-rg"
}
aks_cheatsheets_mi = {
identity_name = "aks-cheatsheets-${var.dev_suffix}-workload-mi"
resource_group = "cloudkube-dev-${var.dev_suffix}-rg"
}
}
}
# ===========
# Key Vault
# ===========
# Make sure keys are always 'dev', 'staging', 'prod'
locals {
kv_certificates = {
dev = var.dev_certificates
staging = var.staging_certificates
prod = var.prod_certificates
}
kv_assignments = {
dev = local.dev_identtiies
staging = {}
prod = {}
}
}
module "key_vaults" {
source = "./modules/key-vault"
for_each = var.key_vault_names
name = each.value
resource_group = var.shared_rg_name
tags = var.default_tags
certificates = local.kv_certificates[each.key]
reader_assignments = local.kv_assignments[each.key]
}
# ====================
# Container Registry
# ====================
locals {
dev_pullers = {
for key, identity in local.dev_identtiies :
"dev-${key}" => identity
}
# add more later when we have more clusters
registry_pullers = merge({}, local.dev_pullers)
github_pushers = {
for k, identity in module.github_identities :
"${k}" => identity.service_principal
}
}
module "container_registry" {
source = "./modules/container-registry"
name = "cloudkubecr"
resource_group = var.shared_rg_name
managed_identity_pullers = local.registry_pullers
github_pushers = local.github_pushers
}
# =================
# Storage Account
# =================
resource "azurerm_storage_account" "cloudkube" {
name = "cloudkubestorage"
resource_group_name = azurerm_resource_group.shared_rg.name
location = azurerm_resource_group.shared_rg.location
account_tier = "Standard"
account_replication_type = "GRS"
tags = var.default_tags
# Per MSFT policy
allow_nested_items_to_be_public = false
shared_access_key_enabled = false
}