Skip to content

Commit

Permalink
Support empty values (#8)
Browse files Browse the repository at this point in the history
* Support empty values

* fix logic

* Update example
  • Loading branch information
osterman authored Jan 15, 2019
1 parent adc4ce1 commit 962bbca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Example `.envrc`:
source <(tfenv)
```

or...
```sh
# Export terraform environment
eval "$(tfenv)"
```

### Bash

Load the terraform environment into your shell.
Expand Down
6 changes: 6 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ usage: |-
source <(tfenv)
```
or...
```sh
# Export terraform environment
eval "$(tfenv)"
```
### Bash
Load the terraform environment into your shell.
Expand Down
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ func main() {
arg := strings.ToLower(match[1])

// Combine parameters into something like `-backend-config=role_arn=xxx`
arg = "-backend-config=" + arg + "=" + pair[1]
arg = "-backend-config=" + arg
if len(pair[1]) > 0 && pair[1] != "true" {
arg += "=" + pair[1]
}
tfCliArgsInit = append(tfCliArgsInit, arg)
} else if reTfCliCommand.MatchString(pair[0]) {
// `TF_CLI_ARGS_plan`: Map `TF_CLI_PLAN_SOMETHING=value` to `-something=value`
Expand All @@ -89,7 +92,11 @@ func main() {

param := reUnderscores.ReplaceAllString(match[2], "-")
param = strings.ToLower(param)
arg := "-" + param + "=" + pair[1]
arg := "-" + param
// Append non-empty parameters or non-true values.
if len(pair[1]) > 0 && pair[1] != "true" {
arg += "=" + pair[1]
}
switch cmd {
case "init":
tfCliArgsInit = append(tfCliArgsInit, arg)
Expand All @@ -105,7 +112,10 @@ func main() {
match := reTfCliDefault.FindStringSubmatch(pair[0])
param := reUnderscores.ReplaceAllString(match[1], "-")
param = strings.ToLower(param)
arg := "-" + param + "=" + pair[1]
arg := "-" + param
if len(pair[1]) > 0 && pair[1] != "true" {
arg += "=" + pair[1]
}
tfCliArgs = append(tfCliArgs, arg)
} else if !reBlacklist.MatchString(pair[0]) && reWhitelist.MatchString(pair[0]) {
// Process the blacklist for exclusions, then the whitelist for inclusions
Expand Down

0 comments on commit 962bbca

Please sign in to comment.