2019-03-30 18:47:03 -04:00
|
|
|
package fix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2020-02-14 11:42:29 -05:00
|
|
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
2019-03-30 18:47:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type FixerAmazonTemporarySecurityCIDRs struct{}
|
|
|
|
|
2020-10-09 20:01:55 -04:00
|
|
|
func (FixerAmazonTemporarySecurityCIDRs) DeprecatedOptions() map[string][]string {
|
|
|
|
return map[string][]string{
|
|
|
|
"*amazon*": []string{"temporary_security_group_source_cidr"},
|
|
|
|
}
|
2020-05-28 17:37:29 -04:00
|
|
|
}
|
|
|
|
|
2019-03-30 18:47:03 -04:00
|
|
|
func (FixerAmazonTemporarySecurityCIDRs) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
|
|
|
// Our template type we'll use for this fixer only
|
|
|
|
type template struct {
|
|
|
|
Builders []map[string]interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the input into our structure, if we can
|
|
|
|
var tpl template
|
|
|
|
if err := mapstructure.Decode(input, &tpl); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-04-02 02:42:31 -04:00
|
|
|
// Go through each builder and replace the temporary_security_group_source_cidr if we can
|
2019-03-30 18:47:03 -04:00
|
|
|
for _, builder := range tpl.Builders {
|
|
|
|
builderTypeRaw, ok := builder["type"]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
builderType, ok := builderTypeRaw.(string)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasPrefix(builderType, "amazon-") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-04-02 02:42:31 -04:00
|
|
|
temporarySecurityGroupCIDR, ok := builder["temporary_security_group_source_cidr"].(string)
|
2019-03-30 18:47:03 -04:00
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-04-02 02:42:31 -04:00
|
|
|
delete(builder, "temporary_security_group_source_cidr")
|
|
|
|
builder["temporary_security_group_source_cidrs"] = []string{temporarySecurityGroupCIDR}
|
2019-03-30 18:47:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
input["builders"] = tpl.Builders
|
|
|
|
return input, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (FixerAmazonTemporarySecurityCIDRs) Synopsis() string {
|
2019-04-02 02:42:31 -04:00
|
|
|
return `Replaces "temporary_security_group_source_cidr" (string) with "temporary_security_group_source_cidrs" (list of strings)`
|
2019-03-30 18:47:03 -04:00
|
|
|
}
|