Skip to content

Commit

Permalink
Merge pull request #9642 from hashicorp/b-var-bool
Browse files Browse the repository at this point in the history
command: FlagTypedKV parses bool as string
  • Loading branch information
mitchellh authored Oct 27, 2016
2 parents 7d33d45 + f9b0207 commit 9c2014d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions command/flag_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,21 @@ func parseVarFlagAsHCL(input string) (string, interface{}, error) {
if _, err := strconv.ParseFloat(trimmed, 64); err == nil {
return probablyName, value, nil
}

// HCL will also parse hex as a number
if strings.HasPrefix(trimmed, "0x") {
if _, err := strconv.ParseInt(trimmed[2:], 16, 64); err == nil {
return probablyName, value, nil
}
}

// If the value is a boolean value, also convert it to a simple string
// since Terraform core doesn't accept primitives as anything other
// than string for now.
if _, err := strconv.ParseBool(trimmed); err == nil {
return probablyName, value, nil
}

parsed, err := hcl.Parse(input)
if err != nil {
// If it didn't parse as HCL, we check if it doesn't match our
Expand Down
6 changes: 6 additions & 0 deletions command/flag_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func TestFlagTypedKV(t *testing.T) {
false,
},

{
"key=false",
map[string]interface{}{"key": "false"},
false,
},

{
"map.key=foo",
map[string]interface{}{"map.key": "foo"},
Expand Down

0 comments on commit 9c2014d

Please sign in to comment.