Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: adds support for description as a templatestring #43

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 53 additions & 53 deletions README.md

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,12 @@ resource "spacelift_stack" "default" {
before_perform = compact(coalesce(try(local.stack_configs[each.key].before_perform, []), var.before_perform))
before_plan = compact(coalesce(try(local.stack_configs[each.key].before_plan, []), var.before_plan))
branch = try(local.stack_configs[each.key].branch, var.branch)
description = coalesce(try(local.stack_configs[each.key].description, null), var.description)
enable_local_preview = try(local.stack_configs[each.key].enable_local_preview, var.enable_local_preview)
enable_well_known_secret_masking = try(local.stack_configs[each.key].enable_well_known_secret_masking, var.enable_well_known_secret_masking)
github_action_deploy = try(local.stack_configs[each.key].github_action_deploy, var.github_action_deploy)
labels = local.labels[each.key]
manage_state = try(local.stack_configs[each.key].manage_state, var.manage_state)
name = each.key
name = local.configs[each.key].root_module
gberenice marked this conversation as resolved.
Show resolved Hide resolved
project_root = local.configs[each.key].project_root
protect_from_deletion = try(local.stack_configs[each.key].protect_from_deletion, var.protect_from_deletion)
repository = try(local.stack_configs[each.key].repository, var.repository)
Expand All @@ -316,6 +315,13 @@ resource "spacelift_stack" "default" {
terraform_workspace = local.configs[each.key].terraform_workspace
worker_pool_id = try(local.stack_configs[each.key].worker_pool_id, var.worker_pool_id)

# Usage of `templatestring` requires OpenTofu 1.7 and Terraform 1.9 or later.
description = coalesce(
try(local.stack_configs[each.key].description, null),
try(templatestring(var.description, local.configs[each.key]), null),
"Managed by spacelift-automation Terraform root module."
)

dynamic "github_enterprise" {
for_each = var.github_enterprise != null ? [var.github_enterprise] : []
content {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
stack_settings:
administrative: true
description: This is a test of the emergency broadcast system
before_init:
- echo 'World'
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
stack_settings:
space_id: 123
labels:
- test_label
32 changes: 32 additions & 0 deletions tests/main.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,35 @@ run "test_before_init_includes_the_default_before_init_and_stack_before_init" {
error_message = "Before_init was not created correctly: ${jsonencode(local.before_init)}"
}
}

# Test that the description is created correctly
run "test_description_is_created_correctly" {
command = plan

assert {
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."
error_message = "Description was not created correctly: ${jsonencode(local.configs)}"
}
}

# Test that the description is created correctly when non-default template string is used
run "test_description_is_created_correctly_when_non_default_template_string_is_used" {
command = plan
variables {
description = "Space ID: $${stack_settings.space_id}"
}

assert {
condition = spacelift_stack.default["root-module-a-test"].description == "Space ID: 123"
error_message = "Description was not created correctly: ${jsonencode(local.configs)}"
}
}

run "test_description_is_created_correctly_when_passed_from_stack_config" {
command = plan

assert {
condition = spacelift_stack.default["root-module-a-default-example"].description == "This is a test of the emergency broadcast system"
error_message = "Description was not created correctly: ${jsonencode(local.configs)}"
}
}
8 changes: 6 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,12 @@ variable "default_tf_workspace_enabled" {

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

variable "destructor_enabled" {
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.6"
required_version = ">= 1.9"

required_providers {
spacelift = {
Expand Down
10 changes: 10 additions & 0 deletions versions.tofu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.7"

required_providers {
spacelift = {
source = "spacelift-io/spacelift"
version = ">= 1.14"
}
}
}
Loading