From c5c34b0f3a04f350876e630f22458515f73fc734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Greinhofer?= Date: Tue, 31 Mar 2020 17:28:29 -0500 Subject: [PATCH] Add support for multiple varfiles Fixes rgreinho/tfe-cli#25 --- CHANGELOG.md | 5 +++++ cmd/variable.go | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c54ca6..1f34f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +* Support multiple varfiles when create/updating variables. [#] + ### Fixed * Incorrect enconding of HCL lists. [#27] @@ -51,3 +55,4 @@ Initial version with support for managing: [#20]: https://github.com/rgreinho/tfe-cli/pull/20 [#23]: https://github.com/rgreinho/tfe-cli/pull/23 [#27]: https://github.com/rgreinho/tfe-cli/pull/27 +[#]: https://github.com/rgreinho/tfe-cli/pull/ diff --git a/cmd/variable.go b/cmd/variable.go index dea4553..c714651 100644 --- a/cmd/variable.go +++ b/cmd/variable.go @@ -35,7 +35,7 @@ var variableCreateCmd = &cobra.Command{ EnvVars, _ := cmd.Flags().GetStringArray("evar") sEnvVars, _ := cmd.Flags().GetStringArray("sevar") force, _ := cmd.Flags().GetBool("force") - varFile, _ := cmd.Flags().GetString("var-file") + varFiles, _ := cmd.Flags().GetStringArray("var-file") // Setup the command. organization, client, err := setup(cmd) @@ -59,7 +59,7 @@ var variableCreateCmd = &cobra.Command{ varOptions = append(varOptions, createVariableOptions(sEnvVars, tfe.CategoryEnv, false, true)...) // Read variables from file. - if varFile != "" { + for _, varFile := range varFiles { // Read the content of the file. FileContent, err := ioutil.ReadFile(varFile) if err != nil { @@ -233,7 +233,7 @@ func init() { variableCreateCmd.Flags().StringArray("shvar", []string{}, "Create a sensitive HCL variable") variableCreateCmd.Flags().StringArray("evar", []string{}, "Create an environment variable") variableCreateCmd.Flags().StringArray("sevar", []string{}, "Create a sensitive environment variable") - variableCreateCmd.Flags().String("var-file", "", "Create non-sensitive regular and HCL variables from a file") + variableCreateCmd.Flags().StringArray("var-file", []string{}, "Create non-sensitive regular and HCL variables from a file") variableCreateCmd.Flags().BoolP("force", "f", false, "Overwrite a variable if it exists") }