Skip to content

Commit

Permalink
feat: allow project root to be customized for stack
Browse files Browse the repository at this point in the history
  • Loading branch information
oycyc committed Dec 27, 2024
1 parent cf86242 commit 17b1d9d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ locals {
local._multi_instance_structure ? "${module}-${trimsuffix(file, ".yaml")}" : module =>
merge(
{
"project_root" = replace(format("%s/%s", var.root_modules_path, module), "../", "")
# Use specified project_root, if not, build it using the root_modules_path and module name
"project_root" = try(content.project_root, replace(format("%s/%s", var.root_modules_path, module), "../", ""))
"root_module" = module,

# If default_tf_workspace_enabled is true, use "default" workspace, otherwise our file name is the workspace name
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/single-instance/root-module-b/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
stack_settings:
administrative: false
before_init:
- echo 'World'
labels:
- stack_label
project_root: "" # root directory of the project
10 changes: 10 additions & 0 deletions tests/single-instance.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ run "test_single_instance_stack_configs_project_root_is_correct" {
}
}

run "test_single_instance_stack_configs_custom_project_root_is_used_when_specified" {
command = plan

assert {
# root-module-b's stack.yaml specifies `project_root` as "" to indicate root directory of project as source
condition = local._root_module_stack_configs["root-module-b"].project_root == ""
error_message = "Custom project_root not used: ${jsonencode(local._root_module_stack_configs)}"
}
}

# Test that the administrative label is not added to the stack when the stack is not set to administrative
run "test_single_instance_administrative_label_is_not_added_to_stack_when_not_administrative" {
command = plan
Expand Down

0 comments on commit 17b1d9d

Please sign in to comment.