Skip to content

Commit f7d4bf8

Browse files
authored
all shells: Pass env vars through a key value store (#98)
1 parent f98795f commit f7d4bf8

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.mdx

shell-local/config.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,6 @@ func Validate(config *Config) error {
9696
}
9797
}
9898

99-
// Clean up input
100-
if config.Inline != nil && len(config.Inline) == 0 {
101-
config.Inline = make([]string, 0)
102-
}
103-
104-
if config.Scripts == nil {
105-
config.Scripts = make([]string, 0)
106-
}
107-
108-
if config.Vars == nil {
109-
config.Vars = make([]string, 0)
110-
}
111-
11299
// Verify that the user has given us a command to run
113100
if config.Command == "" && len(config.Inline) == 0 &&
114101
len(config.Scripts) == 0 && config.Script == "" {

shell-local/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shell-local/run.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ func createFlattenedEnvVars(config *Config) (string, error) {
206206
envVars[keyValue[0]] = strings.Replace(keyValue[1], "'", `'"'"'`, -1)
207207
}
208208

209+
for k, v := range config.Env {
210+
// Store pair, replacing any single quotes in value so they parse
211+
// correctly with required environment variable format
212+
envVars[k] = strings.Replace(v, "'", `'"'"'`, -1)
213+
}
214+
209215
// Create a list of env var keys in sorted order
210216
var keys []string
211217
for k := range envVars {

shell/shell.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ type Provisioner struct {
3636
// for examples such as 3010 - "The requested operation is successful.
3737
ValidExitCodes []int `mapstructure:"valid_exit_codes"`
3838

39-
// An array of environment variables that will be injected before
40-
// your command(s) are executed.
39+
// An array of environment variables that will be injected before your
40+
// command(s) are executed. Any duplicate vars will be overridden by `env`.
4141
Vars []string `mapstructure:"environment_vars"`
4242

43+
// An map of environment variables that will be injected before your
44+
// command(s) are executed. Any duplicate `environment_vars` will be
45+
// overridden by `env`.
46+
Env map[string]string `mapstructure:"env"`
47+
4348
// This is used in the template generation to format environment variables
4449
// inside the `ExecuteCommand` template.
4550
EnvVarFormat string `mapstructure:"env_var_format"`

0 commit comments

Comments
 (0)