generated from masterpointio/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 2
feat(stack_name_template): allow reformatting stack ids #101
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
Draft
dudymas
wants to merge
3
commits into
main
Choose a base branch
from
feat/stacks/add-name-template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Following source doesn't work in most setups | ||
| ignored: | ||
| - SC1090 | ||
| - SC1091 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,6 +115,46 @@ locals { | |
|
|
||
| _root_module_yaml_decoded = merge(local._multi_instance_root_module_yaml_decoded, local._single_instance_root_module_yaml_decoded) | ||
|
|
||
| ## Stack Name Template Resolution | ||
| # Determine the default template based on structure type | ||
| # MultiInstance: "${workspace}-${module_path}" (e.g., "dev-network") | ||
| # SingleInstance: "${module_name}" (e.g., "rds-cluster") | ||
| default_stack_name_template = local._multi_instance_structure ? "$${workspace}-$${module_path}" : "$${module_name}" | ||
|
|
||
| # Use provided template or fall back to default | ||
| stack_name_template = coalesce(var.stack_name_template, local.default_stack_name_template) | ||
|
|
||
| # Generate stack names using the template | ||
| # Iterates over all modules and their stack files, applying the template with available parameters | ||
| stack_names = { | ||
| for module, files in local._root_module_yaml_decoded : | ||
| module => { | ||
| for file, content in files : | ||
| file => ( | ||
| file == var.common_config_file ? null : | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need this check if you have the |
||
| templatestring( | ||
| local.stack_name_template, | ||
| { | ||
| module_name = basename(module) | ||
| workspace = trimsuffix(file, ".yaml") | ||
| module_path = module | ||
| } | ||
| ) | ||
| ) if file != var.common_config_file | ||
| } | ||
| } | ||
|
|
||
| # Clean up stack names to handle edge cases | ||
| # Removes double hyphens, leading/trailing hyphens, and applies trimspace | ||
| # This handles cases where template parameters may be empty (e.g., SingleInstance with ${workspace}) | ||
| cleaned_stack_names = { | ||
| for module, names in local.stack_names : | ||
| module => { | ||
| for file, name in names : | ||
| file => name != null ? trimspace(replace(replace(replace(name, "--", "-"), "/^-/", ""), "/-$/", "")) : null | ||
| } | ||
| } | ||
|
|
||
| ## Common Stack configurations | ||
| # Retrieve common Stack configurations for each root module. | ||
| # SingleInstance root_module_structure does not support common configs today. | ||
|
|
@@ -155,7 +195,7 @@ locals { | |
| # } | ||
| _root_module_stack_configs = merge([for module, files in local._root_module_yaml_decoded : { | ||
| for file, content in files : | ||
| local._multi_instance_structure ? "${module}-${trimsuffix(file, ".yaml")}" : module => | ||
| local.cleaned_stack_names[module][file] => | ||
| merge( | ||
| { | ||
| # Use specified project_root, if not, build it using the root_modules_path and module name | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was generated by trunk when I ran
trunk upgrade