Merge pull request #9642 from hashicorp/b-var-bool

command: FlagTypedKV parses bool as string
This commit is contained in:
Mitchell Hashimoto 2016-10-27 11:17:16 -04:00 committed by GitHub
commit 9c2014d5b6
2 changed files with 14 additions and 0 deletions

View File

@ -166,6 +166,7 @@ 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 {
@ -173,6 +174,13 @@ func parseVarFlagAsHCL(input string) (string, interface{}, error) {
}
}
// 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

View File

@ -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"},