-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
terraform_generate_varfiles.go
59 lines (50 loc) 路 2.79 KB
/
terraform_generate_varfiles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
e "github.com/cloudposse/atmos/internal/exec"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/spf13/cobra"
)
// terraformGenerateVarfilesCmd generates varfiles for all terraform components in all stacks
var terraformGenerateVarfilesCmd = &cobra.Command{
Use: "varfiles",
Short: "Execute 'terraform generate varfiles' command",
Long: `This command generates varfiles for all terraform components in all stacks`,
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Run: func(cmd *cobra.Command, args []string) {
err := e.ExecuteTerraformGenerateVarfilesCmd(cmd, args)
if err != nil {
u.PrintErrorToStdErrorAndExit(err)
}
},
}
func init() {
terraformGenerateVarfilesCmd.DisableFlagParsing = false
terraformGenerateVarfilesCmd.PersistentFlags().String("file-template", "",
"Varfile template (the file path, file name, and file extension).\n"+
"Supports absolute and relative paths.\n"+
"Supports context tokens: {namespace}, {tenant}, {environment}, {region}, {stage}, {component}, {component-path}.\n"+
"atmos terraform generate varfiles --file-template {component-path}/{environment}-{stage}.tfvars.json\n"+
"atmos terraform generate varfiles --file-template /configs/{tenant}/{environment}/{stage}/{component}.json\n"+
"atmos terraform generate varfiles --file-template /{tenant}/{stage}/{region}/{component}.yaml\n"+
"All subfolders in the path will be created automatically.",
)
terraformGenerateVarfilesCmd.PersistentFlags().String("stacks", "",
"Only process the specified stacks (comma-separated values).\n"+
"atmos terraform generate varfiles --file-template <file_template> --stacks <stack1>,<stack2>\n"+
"The filter can contain the names of the top-level stack config files and the logical stack names (derived from the context vars)\n"+
"atmos terraform generate varfiles --stacks orgs/cp/tenant1/staging/us-east-2,orgs/cp/tenant2/dev/us-east-2\n"+
"atmos terraform generate varfiles --stacks tenant1-ue2-staging,tenant1-ue2-prod\n"+
"atmos terraform generate varfiles --stacks orgs/cp/tenant1/staging/us-east-2,tenant1-ue2-prod",
)
terraformGenerateVarfilesCmd.PersistentFlags().String("components", "",
"Only process the specified components (comma-separated values).\n"+
"atmos terraform generate varfiles --file-template <file_template> --components <component1>,<component2>",
)
terraformGenerateVarfilesCmd.PersistentFlags().String("format", "json", "Output format.\n"+
"atmos terraform generate varfiles --file-template <file_template> --format=json/yaml ('json' is default)")
err := terraformGenerateVarfilesCmd.MarkPersistentFlagRequired("file-template")
if err != nil {
u.PrintErrorToStdErrorAndExit(err)
}
terraformGenerateCmd.AddCommand(terraformGenerateVarfilesCmd)
}