Skip to content

Commit 4babc73

Browse files
committed
feat: adds the runtime_overrides variable + tests
1 parent 28c4217 commit 4babc73

File tree

4 files changed

+554
-13
lines changed

4 files changed

+554
-13
lines changed

main.tf

+15-9
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ locals {
148148
# `yaml` is intentionally used here as we require Stack and `tfvars` config files to be named equally
149149
"tfvars_file_name" = trimsuffix(file, ".yaml"),
150150
},
151-
content
151+
content,
152+
try(var.runtime_overrides[module], {}),
152153
) if file != var.common_config_file
153154
}
154155
]...)
@@ -266,6 +267,16 @@ locals {
266267
try(local.stack_configs[stack].before_init, []),
267268
))
268269
}
270+
271+
aws_integration_stacks = {
272+
for stack, config in local.stack_configs :
273+
stack => config if try(config.aws_integration_enabled, var.aws_integration_enabled)
274+
}
275+
276+
drift_detection_stacks = {
277+
for stack, config in local.stack_configs :
278+
stack => config if try(config.drift_detection_enabled, var.drift_detection_enabled)
279+
}
269280
}
270281

271282
# Perform deep merge for common configurations and stack configurations
@@ -346,21 +357,16 @@ resource "spacelift_stack_destructor" "default" {
346357
}
347358

348359
resource "spacelift_aws_integration_attachment" "default" {
349-
for_each = {
350-
for stack, configs in local.stack_configs : stack => configs
351-
if try(configs.aws_integration_enabled, var.aws_integration_enabled)
352-
}
360+
for_each = local.aws_integration_stacks
361+
353362
integration_id = try(local.stack_configs[each.key].aws_integration_id, var.aws_integration_id)
354363
stack_id = spacelift_stack.default[each.key].id
355364
read = var.aws_integration_attachment_read
356365
write = var.aws_integration_attachment_write
357366
}
358367

359368
resource "spacelift_drift_detection" "default" {
360-
for_each = {
361-
for stack, configs in local.stack_configs : stack => configs
362-
if try(configs.drift_detection_enabled, var.drift_detection_enabled)
363-
}
369+
for_each = local.drift_detection_stacks
364370

365371
stack_id = spacelift_stack.default[each.key].id
366372
ignore_state = try(local.stack_configs[each.key].drift_detection_ignore_state, var.drift_detection_ignore_state)

tests/fixtures/multi-instance/root-module-a/stacks/default-example.yaml

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
stack_settings:
22
administrative: true
3-
before_init:
4-
- echo 'World'
3+
additional_project_globs: [glob/*]
4+
after_apply: [echo 'after_apply']
5+
after_destroy: [echo 'after_destroy']
6+
after_init: [echo 'after_init']
7+
after_perform: [echo 'after_perform']
8+
after_plan: [echo 'after_plan']
9+
autodeploy: false
10+
autoretry: true
11+
before_apply: [echo 'before_apply']
12+
before_destroy: [echo 'before_destroy']
13+
before_init: [echo 'before_init']
14+
before_perform: [echo 'before_perform']
15+
before_plan: [echo 'before_plan']
16+
branch: prod
17+
description: This is a test of the emergency broadcast system
18+
enable_local_preview: true
19+
enable_well_known_secret_masking: false
20+
github_action_deploy: false
21+
manage_state: true
22+
protect_from_deletion: true
23+
runner_image: masterpointio/spacelift-runner:latest
24+
space_id: "1234567890"
25+
terraform_smart_sanitization: true
26+
terraform_version: 1.9.0
27+
worker_pool_id: "1234567890"
28+
29+
destructor_enabled: true
30+
31+
aws_integration_enabled: true
32+
aws_integration_id: "1234567890"
33+
34+
drift_detection_enabled: true
35+
drift_detection_ignore_state: true
36+
drift_detection_reconcile: true
37+
drift_detection_schedule: [0 0 * * *]
38+
drift_detection_timezone: America/Denver
539
labels:
640
- default_example_label
741

0 commit comments

Comments
 (0)