From 6d00226e0e99ae5e6c333eba9512e58820f46587 Mon Sep 17 00:00:00 2001 From: apollorion Date: Fri, 25 Oct 2024 14:32:11 -0400 Subject: [PATCH] feat: add default for stack --- config.yml.example | 5 +++++ spacemk/commands/generate.py | 3 +++ spacemk/templates/base.tf.jinja | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/config.yml.example b/config.yml.example index 5df2e9a..e069b7a 100644 --- a/config.yml.example +++ b/config.yml.example @@ -35,6 +35,11 @@ generator: # # The default branch for all modules. Only used if the module does not have a branch specified. # # Default: empty string # modules: +# default_branch: main + +# # The default branch for all stacks. Only used if the stack does not have a branch specified. +# # Default: empty string +# stacks: # default_branch: main extra_vars: diff --git a/spacemk/commands/generate.py b/spacemk/commands/generate.py index 5898406..8003ced 100644 --- a/spacemk/commands/generate.py +++ b/spacemk/commands/generate.py @@ -26,6 +26,9 @@ def set_default(value, _default): "SPACELIFT_DEFAULT_INVALID"), "modules": { "default_branch": set_default(config.get("generator.modules.default_branch"), ""), + }, + "stacks": { + "default_branch": set_default(config.get("generator.stacks.default_branch"), ""), } } diff --git a/spacemk/templates/base.tf.jinja b/spacemk/templates/base.tf.jinja index 09319c1..e437b8d 100644 --- a/spacemk/templates/base.tf.jinja +++ b/spacemk/templates/base.tf.jinja @@ -82,7 +82,11 @@ EOT {% if stack.vcs.repository %} resource "spacelift_stack" "{{ stack._relationships.space._migration_id }}_{{ stack._migration_id }}" { {{ argument("auto_deploy", stack.auto_deploy, default=False) }} + {% if stack.vcs.branch == ""%} + {{ argument("branch", generation_config.stacks.default_branch, required=True) }} + {% else %} {{ argument("branch", stack.vcs.branch, required=True) }} + {% endif %} {{ argument("description", stack.description) }} {{ argument("local_preview", stack.local_preview) }} {{ argument("labels", ["migration_class:" + class] + stack.labels|default([])) }}