-
-
Notifications
You must be signed in to change notification settings - Fork 953
/
terraform.go
61 lines (53 loc) · 2.03 KB
/
terraform.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
60
61
package terraform
import (
"github.com/gruntwork-io/go-commons/errors"
"github.com/hashicorp/terraform-config-inspect/tfconfig"
)
const (
CommandNameInit = "init"
CommandNameInitFromModule = "init-from-module"
CommandNameImport = "import"
CommandNamePlan = "plan"
CommandNameApply = "apply"
CommandNameDestroy = "destroy"
CommandNameValidate = "validate"
CommandNameOutput = "output"
CommandNameProviders = "providers"
CommandNameState = "state"
CommandNameLock = "lock"
CommandNameGet = "get"
CommandNameTaint = "taint"
CommandNameUntaint = "untaint"
CommandNameConsole = "console"
CommandNameForceUnlock = "force-unlock"
CommandNameShow = "show"
FlagNameNoColor = "-no-color"
// `apply -destroy` is alias for `destroy`
FlagNameDestroy = "-destroy"
EnvNameTFCLIConfigFile = "TF_CLI_CONFIG_FILE"
EnvNameTFPluginCacheDir = "TF_PLUGIN_CACHE_DIR"
EnvNameTFPluginCacheMayBreakDependencyLockFile = "TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE"
EnvNameTFTokenFmt = "TF_TOKEN_%s"
EnvNameTFVarFmt = "TF_VAR_%s"
TerraformLockFile = ".terraform.lock.hcl"
TerraformPlanFile = "tfplan.tfplan"
TerraformPlanJsonFile = "tfplan.json"
)
// ModuleVariables will return all the variables defined in the downloaded terraform modules, taking into
// account all the generated sources. This function will return the required and optional variables separately.
func ModuleVariables(modulePath string) ([]string, []string, error) {
module, diags := tfconfig.LoadModule(modulePath)
if diags.HasErrors() {
return nil, nil, errors.WithStackTrace(diags)
}
required := []string{}
optional := []string{}
for _, variable := range module.Variables {
if variable.Required {
required = append(required, variable.Name)
} else {
optional = append(optional, variable.Name)
}
}
return required, optional, nil
}