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: add default for stack #83

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions spacemk/commands/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"), ""),
}
}

Expand Down
4 changes: 4 additions & 0 deletions spacemk/templates/base.tf.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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([])) }}
Expand Down