-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
metadata.terraform_workspace_pattern
(#138)
* updates * updates * updates * Add `metadata.terraform_workspace_pattern` * Add `metadata.terraform_workspace_pattern` * Add `metadata.terraform_workspace_pattern`
- Loading branch information
Showing
6 changed files
with
99 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 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,37 @@ | ||
package exec | ||
|
||
import ( | ||
"fmt" | ||
c "github.com/cloudposse/atmos/pkg/config" | ||
"strings" | ||
) | ||
|
||
// BuildTerraformWorkspace builds Terraform workspace | ||
func BuildTerraformWorkspace( | ||
stack string, | ||
stackNamePattern string, | ||
componentMetadata map[interface{}]interface{}, | ||
context c.Context, | ||
) (string, error) { | ||
|
||
contextPrefix, err := c.GetContextPrefix(stack, context, stackNamePattern) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var workspace string | ||
|
||
if terraformWorkspacePattern, terraformWorkspacePatternExist := componentMetadata["terraform_workspace_pattern"].(string); terraformWorkspacePatternExist { | ||
// Terraform workspace can be overridden per component in YAML config `metadata.terraform_workspace_pattern` | ||
workspace = c.ReplaceContextTokens(context, terraformWorkspacePattern) | ||
} else if terraformWorkspace, terraformWorkspaceExist := componentMetadata["terraform_workspace"].(string); terraformWorkspaceExist { | ||
// Terraform workspace can be overridden per component in YAML config `metadata.terraform_workspace` | ||
workspace = terraformWorkspace | ||
} else if context.BaseComponent == "" { | ||
workspace = contextPrefix | ||
} else { | ||
workspace = fmt.Sprintf("%s-%s", contextPrefix, context.Component) | ||
} | ||
|
||
return strings.Replace(workspace, "/", "-", -1), nil | ||
} |
This file contains 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 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 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 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