Merge pull request #9642 from hashicorp/b-var-bool
command: FlagTypedKV parses bool as string
This commit is contained in:
commit
9c2014d5b6
|
@ -166,6 +166,7 @@ func parseVarFlagAsHCL(input string) (string, interface{}, error) {
|
||||||
if _, err := strconv.ParseFloat(trimmed, 64); err == nil {
|
if _, err := strconv.ParseFloat(trimmed, 64); err == nil {
|
||||||
return probablyName, value, nil
|
return probablyName, value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HCL will also parse hex as a number
|
// HCL will also parse hex as a number
|
||||||
if strings.HasPrefix(trimmed, "0x") {
|
if strings.HasPrefix(trimmed, "0x") {
|
||||||
if _, err := strconv.ParseInt(trimmed[2:], 16, 64); err == nil {
|
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)
|
parsed, err := hcl.Parse(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If it didn't parse as HCL, we check if it doesn't match our
|
// If it didn't parse as HCL, we check if it doesn't match our
|
||||||
|
|
|
@ -98,6 +98,12 @@ func TestFlagTypedKV(t *testing.T) {
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"key=false",
|
||||||
|
map[string]interface{}{"key": "false"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map.key=foo",
|
"map.key=foo",
|
||||||
map[string]interface{}{"map.key": "foo"},
|
map[string]interface{}{"map.key": "foo"},
|
||||||
|
|
Loading…
Reference in New Issue