Ensure amazon-private-ip fixes string values
The "ssh_private_ip" key works with either boolean values or string representations of booleans. The fixer errors when the value is defined as, for example, "true" (with quotation marks). This commit will attempt to convert the string into a bool when necessary to ensure this case is handled. Signed-off-by: Brendan Devenney <brendan.devenney@cloudreach.com>
This commit is contained in:
parent
4b1f96b527
commit
73c532e772
|
@ -2,6 +2,7 @@ package fix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
@ -49,8 +50,12 @@ func (FixerAmazonPrivateIP) Fix(input map[string]interface{}) (map[string]interf
|
||||||
}
|
}
|
||||||
privateIP, ok := privateIPi.(bool)
|
privateIP, ok := privateIPi.(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatalf("Wrong type for ssh_private_ip")
|
var err error
|
||||||
continue
|
privateIP, err = strconv.ParseBool(privateIPi.(string))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Wrong type for ssh_private_ip")
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(builder, "ssh_private_ip")
|
delete(builder, "ssh_private_ip")
|
||||||
|
|
|
@ -39,6 +39,19 @@ func TestFixerAmazonPrivateIP(t *testing.T) {
|
||||||
"ssh_interface": "private_ip",
|
"ssh_interface": "private_ip",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ssh_private_ip specified as string
|
||||||
|
{
|
||||||
|
Input: map[string]interface{}{
|
||||||
|
"type": "amazon-ebs",
|
||||||
|
"ssh_private_ip": "true",
|
||||||
|
},
|
||||||
|
|
||||||
|
Expected: map[string]interface{}{
|
||||||
|
"type": "amazon-ebs",
|
||||||
|
"ssh_interface": "private_ip",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
|
Loading…
Reference in New Issue