Skip to content

Commit 3aadae6

Browse files
authored
Merge branch 'main' into feature/runtime-overrides
2 parents 32b679f + 1bbb74f commit 3aadae6

File tree

9 files changed

+123
-58
lines changed

9 files changed

+123
-58
lines changed

README.md

+53-53
Large diffs are not rendered by default.

aqua.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ packages:
1313
- name: terraform-docs/[email protected]
1414
- name: hashicorp/[email protected]
1515
tags: [terraform]
16-
- name: opentofu/opentofu@v1.8.7
16+
- name: opentofu/opentofu@v1.9.0
1717
tags: [tofu]
1818
- name: spacelift-io/[email protected]

main.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ resource "spacelift_stack" "default" {
320320
before_perform = compact(coalesce(try(local.stack_configs[each.key].before_perform, []), var.before_perform))
321321
before_plan = compact(coalesce(try(local.stack_configs[each.key].before_plan, []), var.before_plan))
322322
branch = try(local.stack_configs[each.key].branch, var.branch)
323-
description = coalesce(try(local.stack_configs[each.key].description, null), var.description)
324323
enable_local_preview = try(local.stack_configs[each.key].enable_local_preview, var.enable_local_preview)
325324
enable_well_known_secret_masking = try(local.stack_configs[each.key].enable_well_known_secret_masking, var.enable_well_known_secret_masking)
326325
github_action_deploy = try(local.stack_configs[each.key].github_action_deploy, var.github_action_deploy)
@@ -338,6 +337,13 @@ resource "spacelift_stack" "default" {
338337
terraform_workspace = local.configs[each.key].terraform_workspace
339338
worker_pool_id = try(local.stack_configs[each.key].worker_pool_id, var.worker_pool_id)
340339

340+
# Usage of `templatestring` requires OpenTofu 1.7 and Terraform 1.9 or later.
341+
description = coalesce(
342+
try(local.stack_configs[each.key].description, null),
343+
try(templatestring(var.description, local.configs[each.key]), null),
344+
"Managed by spacelift-automation Terraform root module."
345+
)
346+
341347
dynamic "github_enterprise" {
342348
for_each = var.github_enterprise != null ? [var.github_enterprise] : []
343349
content {

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
kind: StackConfigV1
22
stack_settings:
33
administrative: true
4+
description: This is a test of the emergency broadcast system
45
additional_project_globs: [glob/*]
56
after_apply: [echo 'after_apply']
67
after_destroy: [echo 'after_destroy']
@@ -37,6 +38,7 @@ stack_settings:
3738
drift_detection_reconcile: true
3839
drift_detection_schedule: [0 0 * * *]
3940
drift_detection_timezone: America/Denver
41+
4042
labels:
4143
- default_example_label
4244
automation_settings:
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
kind: StackConfigV1
22
stack_settings:
3+
space_id: 123
34
labels:
45
- test_label

tests/main.tftest.hcl

+42
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,16 @@ run "test_stacks_include_expected" {
496496
}
497497
}
498498

499+
# Test that the stack resource is created with the correct name
500+
run "test_stack_resource_is_created_with_correct_name" {
501+
command = plan
502+
503+
assert {
504+
condition = spacelift_stack.default["root-module-a-test"].name == "root-module-a-test"
505+
error_message = "Stack resource was not created correctly: ${jsonencode(spacelift_stack.default)}"
506+
}
507+
}
508+
499509
# Test that the folder labels get created with correct format
500510
run "test_folder_labels_are_correct_format" {
501511
command = plan
@@ -585,3 +595,35 @@ run "test_before_init_includes_the_default_before_init_and_stack_before_init" {
585595
error_message = "Before_init was not created correctly: ${jsonencode(local.before_init)}"
586596
}
587597
}
598+
599+
# Test that the description is created correctly
600+
run "test_description_is_created_correctly" {
601+
command = plan
602+
603+
assert {
604+
condition = spacelift_stack.default["root-module-a-test"].description == "Root Module: root-module-a\nProject Root: ./tests/fixtures/multi-instance/root-module-a\nWorkspace: test\nManaged by spacelift-automation Terraform root module."
605+
error_message = "Description was not created correctly: ${jsonencode(local.configs)}"
606+
}
607+
}
608+
609+
# Test that the description is created correctly when non-default template string is used
610+
run "test_description_is_created_correctly_when_non_default_template_string_is_used" {
611+
command = plan
612+
variables {
613+
description = "Space ID: $${stack_settings.space_id}"
614+
}
615+
616+
assert {
617+
condition = spacelift_stack.default["root-module-a-test"].description == "Space ID: 123"
618+
error_message = "Description was not created correctly: ${jsonencode(local.configs)}"
619+
}
620+
}
621+
622+
run "test_description_is_created_correctly_when_passed_from_stack_config" {
623+
command = plan
624+
625+
assert {
626+
condition = spacelift_stack.default["root-module-a-default-example"].description == "This is a test of the emergency broadcast system"
627+
error_message = "Description was not created correctly: ${jsonencode(local.configs)}"
628+
}
629+
}

variables.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@ variable "default_tf_workspace_enabled" {
220220

221221
variable "description" {
222222
type = string
223-
description = "Description of the stack"
224-
default = "Managed by spacelift-automation Terraform root module."
223+
description = <<EOT
224+
A description for the created Stacks. This is a template string that will be rendered with the final config object for the stack.
225+
See the main.tf for full internals of that object and the documentation on templatestring for usage.
226+
https://opentofu.org/docs/language/functions/templatestring/
227+
EOT
228+
default = "Root Module: $${root_module}\nProject Root: $${project_root}\nWorkspace: $${terraform_workspace}\nManaged by spacelift-automation Terraform root module."
225229
}
226230

227231
variable "destructor_enabled" {

versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.6"
2+
required_version = ">= 1.9"
33

44
required_providers {
55
spacelift = {

versions.tofu

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.7"
3+
4+
required_providers {
5+
spacelift = {
6+
source = "spacelift-io/spacelift"
7+
version = ">= 1.14"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)