-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
301 lines (246 loc) · 8.93 KB
/
Copy pathmain.tf
File metadata and controls
301 lines (246 loc) · 8.93 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
locals {
# Create a purely alphanumeric identifier from the display name
# Remove special characters, convert to lowercase, and replace spaces/hyphens with nothing
identifier = lower(replace(replace(var.name, "/[^a-zA-Z0-9\\s\\-\\_]/", ""), "/[\\s\\-\\_]+/", "-"))
}
resource "meshstack_project" "dev" {
metadata = {
name = "${local.identifier}-dev"
owned_by_workspace = var.workspace_identifier
}
spec = {
display_name = "${var.name} Dev"
tags = {}
}
}
resource "meshstack_project" "prod" {
metadata = {
name = "${local.identifier}-prod"
owned_by_workspace = var.workspace_identifier
}
spec = {
display_name = "${var.name} Prod"
tags = {}
}
}
resource "meshstack_project_user_binding" "creator_dev_admin" {
count = var.creator.type == "User" && var.creator.username != null ? 1 : 0
metadata = {
name = uuid()
}
role_ref = {
name = "Project Admin"
}
target_ref = {
owned_by_workspace = var.workspace_identifier
name = meshstack_project.dev.metadata.name
}
subject = {
name = var.creator.username
}
}
resource "meshstack_project_user_binding" "creator_prod_admin" {
count = var.creator.type == "User" && var.creator.username != null ? 1 : 0
metadata = {
name = uuid()
}
role_ref = {
name = "Project Admin"
}
target_ref = {
owned_by_workspace = var.workspace_identifier
name = meshstack_project.prod.metadata.name
}
subject = {
name = var.creator.username
}
}
resource "meshstack_tenant_v4" "dev" {
metadata = {
owned_by_workspace = var.workspace_identifier
owned_by_project = meshstack_project.dev.metadata.name
}
spec = {
platform_identifier = var.full_platform_identifier
landing_zone_identifier = var.landing_zone_dev_identifier
}
}
resource "meshstack_tenant_v4" "prod" {
metadata = {
owned_by_workspace = var.workspace_identifier
owned_by_project = meshstack_project.prod.metadata.name
}
spec = {
platform_identifier = var.full_platform_identifier
landing_zone_identifier = var.landing_zone_prod_identifier
}
}
resource "meshstack_building_block_v2" "repo" {
spec = {
building_block_definition_version_ref = {
uuid = var.github_repo_definition_version_uuid
}
display_name = "${var.github_org}/${local.identifier}"
target_ref = {
kind = "meshWorkspace"
identifier = var.workspace_identifier
}
inputs = {
repo_name = {
value_string = local.identifier
}
repo_owner = {
value_string = var.repo_admin != null ? var.repo_admin : ""
}
repo_visibility = {
value_string = var.github_repo_input_repo_visibility != null ? var.github_repo_input_repo_visibility : "private"
}
use_template = {
value_bool = true
}
template_owner = {
value_string = "likvid-bank"
}
template_repo = {
value_string = "aks-starterkit-template"
}
}
}
}
# takes a while until github repo and aks namespace are ready
resource "time_sleep" "wait_45_seconds" {
depends_on = [meshstack_building_block_v2.repo]
create_duration = "45s"
}
# Fetch the GitHub building block after creation to get outputs
data "meshstack_building_block_v2" "repo_data" {
depends_on = [time_sleep.wait_45_seconds]
metadata = {
uuid = meshstack_building_block_v2.repo.metadata.uuid
}
}
# We need to fetch both dev&prod tenant data after creation to get the platform tenant ID
data "meshstack_tenant_v4" "aks-dev" {
depends_on = [time_sleep.wait_45_seconds]
metadata = {
uuid = meshstack_tenant_v4.dev.metadata.uuid
}
}
data "meshstack_tenant_v4" "aks-prod" {
depends_on = [time_sleep.wait_45_seconds]
metadata = {
uuid = meshstack_tenant_v4.prod.metadata.uuid
}
}
resource "meshstack_building_block_v2" "github_actions_dev" {
depends_on = [meshstack_building_block_v2.repo, meshstack_tenant_v4.dev]
spec = {
building_block_definition_version_ref = {
uuid = var.github_actions_connector_definition_version_uuid
}
target_ref = {
kind = "meshTenant"
uuid = meshstack_tenant_v4.dev.metadata.uuid
}
display_name = "GHA Connector Dev"
parent_building_blocks = [{
buildingblock_uuid = meshstack_building_block_v2.repo.metadata.uuid
definition_uuid = var.github_repo_definition_uuid
}]
inputs = {
github_environment_name = {
value_string = "development"
}
additional_environment_variables = {
value_code = jsonencode({
"DOMAIN_NAME" = "${local.identifier}-dev"
"AKS_NAMESPACE_NAME" = data.meshstack_tenant_v4.aks-dev.spec.platform_tenant_id
})
}
}
}
}
resource "meshstack_building_block_v2" "github_actions_prod" {
depends_on = [meshstack_building_block_v2.repo, meshstack_building_block_v2.github_actions_dev]
spec = {
display_name = "GHA Connector Prod"
building_block_definition_version_ref = {
uuid = var.github_actions_connector_definition_version_uuid
}
target_ref = {
kind = "meshTenant"
uuid = meshstack_tenant_v4.prod.metadata.uuid
}
parent_building_blocks = [{
buildingblock_uuid = meshstack_building_block_v2.repo.metadata.uuid
definition_uuid = var.github_repo_definition_uuid
}]
inputs = {
github_environment_name = {
value_string = "production"
}
additional_environment_variables = {
value_code = jsonencode({
"DOMAIN_NAME" = local.identifier
"AKS_NAMESPACE_NAME" = data.meshstack_tenant_v4.aks-prod.spec.platform_tenant_id
})
}
}
}
}
output "dev-link" {
description = "Link to the dev environment Angular app"
value = "https://${local.identifier}-dev.likvid-k8s.msh.host"
}
output "prod-link" {
description = "Link to the prod environment Angular app"
value = "https://${local.identifier}.likvid-k8s.msh.host"
}
output "github_repo_url" {
description = "URL of the created GitHub repository"
value = data.meshstack_building_block_v2.repo_data.status.outputs.repo_html_url.value_string
}
output "summary" {
description = "Summary with next steps and insights into created resources"
value = <<-EOT
# AKS Starter Kit
✅ **Your environment is ready!**
This starter kit has set up the following resources in workspace `${var.workspace_identifier}`:
- **GitHub Repository**: [${local.identifier}](<${data.meshstack_building_block_v2.repo_data.status.outputs.repo_html_url.value_string}>)
- **Development Project**: [${meshstack_project.dev.spec.display_name}](/#/w/${var.workspace_identifier}/p/${meshstack_project.dev.metadata.name}/tenants)
- **AKS Namespace**: [${data.meshstack_tenant_v4.aks-dev.spec.platform_tenant_id}](/#/w/${var.workspace_identifier}/p/${meshstack_project.dev.metadata.name}/i/aks.eu-de-central/overview/azure_kubernetes_service)
- **Production Project**: [${meshstack_project.prod.spec.display_name}](/#/w/${var.workspace_identifier}/p/${meshstack_project.prod.metadata.name}/tenants)
- **AKS Namespace**: [${data.meshstack_tenant_v4.aks-prod.spec.platform_tenant_id}](/#/w/${var.workspace_identifier}/p/${meshstack_project.prod.metadata.name}/i/aks.eu-de-central/overview/azure_kubernetes_service)
---
## What's Included
Your GitHub repository contains:
- Angular frontend & Node.js backend
- Dockerfiles for both apps
- Kubernetes deployment files
- GitHub Actions CI/CD workflows for AKS
---
## Deployments
Trigger a deployment by:
- Pushing to the **main** branch (deploys to **dev**)
- Merging **main** into **release** via PR (deploys to **prod**)
View deployment status: [GitHub Actions](${data.meshstack_building_block_v2.repo_data.status.outputs.repo_html_url.value_string}/actions/workflows/k8s-deploy.yml)
- **Dev**: [${local.identifier}-dev.likvid-k8s.msh.host](https://${local.identifier}-dev.likvid-k8s.msh.host)
- **Prod**: [${local.identifier}.likvid-k8s.msh.host](https://${local.identifier}.likvid-k8s.msh.host)
---
## Next Steps
### 1. Develop
- Push changes to **main** → deploys to **dev**
- Merge PR from **main → release** → deploys to **prod**
### 2. Monitor
- Check workflow status in the [Actions tab](<${data.meshstack_building_block_v2.repo_data.status.outputs.repo_html_url.value_string}/actions>)
### 3. Access AKS Namespaces
- [Dev Namespace](/#/w/${var.workspace_identifier}/p/${meshstack_project.dev.metadata.name}/i/aks.eu-de-central/overview/azure_kubernetes_service)
- [Prod Namespace](/#/w/${var.workspace_identifier}/p/${meshstack_project.prod.metadata.name}/i/aks.eu-de-central/overview/azure_kubernetes_service)
### 4. Manage Access
- Invite team members via meshStack:
- [Dev Access](#/w/${var.workspace_identifier}/p/${meshstack_project.dev.metadata.name}/access-management/role-mapping/overview)
- [Prod Access](#/w/${var.workspace_identifier}/p/${meshstack_project.prod.metadata.name}/access-management/role-mapping/overview)
---
🎉 Happy coding!
EOT
}