From 73c532e772c2994a1a0eb63a0572b65ee7e0f63d Mon Sep 17 00:00:00 2001 From: Brendan Devenney Date: Thu, 5 Jul 2018 16:57:54 +0100 Subject: [PATCH] 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 --- fix/fixer_amazon_private_ip.go | 9 +++++++-- fix/fixer_amazon_private_ip_test.go | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/fix/fixer_amazon_private_ip.go b/fix/fixer_amazon_private_ip.go index 7bfce1291..7b0189ca5 100644 --- a/fix/fixer_amazon_private_ip.go +++ b/fix/fixer_amazon_private_ip.go @@ -2,6 +2,7 @@ package fix import ( "log" + "strconv" "strings" "github.com/mitchellh/mapstructure" @@ -49,8 +50,12 @@ func (FixerAmazonPrivateIP) Fix(input map[string]interface{}) (map[string]interf } privateIP, ok := privateIPi.(bool) if !ok { - log.Fatalf("Wrong type for ssh_private_ip") - continue + var err error + privateIP, err = strconv.ParseBool(privateIPi.(string)) + if err != nil { + log.Fatalf("Wrong type for ssh_private_ip") + continue + } } delete(builder, "ssh_private_ip") diff --git a/fix/fixer_amazon_private_ip_test.go b/fix/fixer_amazon_private_ip_test.go index 554584ded..71961f2f8 100644 --- a/fix/fixer_amazon_private_ip_test.go +++ b/fix/fixer_amazon_private_ip_test.go @@ -39,6 +39,19 @@ func TestFixerAmazonPrivateIP(t *testing.T) { "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 {