From 82f234e3ef7d49557ad2feb7c48891047021e6ef Mon Sep 17 00:00:00 2001 From: Marcin Rabenda Date: Mon, 11 Jul 2022 15:15:48 +0200 Subject: [PATCH] Fix if implementation --- cloudformation/intrinsics.go | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/cloudformation/intrinsics.go b/cloudformation/intrinsics.go index 65a24da918..0c1cb7b38e 100644 --- a/cloudformation/intrinsics.go +++ b/cloudformation/intrinsics.go @@ -236,32 +236,17 @@ func FindInMapPtr(mapName, topLevelKey, secondLevelKey interface{}) *string { // If returns one value if the specified condition evaluates to true and another value if the specified condition evaluates to false. Currently, AWS CloudFormation supports the Fn::If intrinsic function in the metadata attribute, update policy attribute, and property values in the Resources section and Outputs sections of a template. You can use the AWS::NoValue pseudo parameter as a return value to remove the corresponding property. func If(value, ifEqual interface{}, ifNotEqual interface{}) string { - var equal string - - switch v := ifEqual.(type) { - case map[string]string, []string, string: - out, err := json.Marshal(ifEqual) - if err != nil { - panic(err) - } - equal = string(out) - default: - fmt.Printf("Unsupported type for ifEqual: %T\n", v) - return encode(fmt.Sprintf(`{ "Fn::If" : [ %q, %q, %q ] }`, value, ifEqual, ifNotEqual)) + out, err := json.Marshal(ifEqual) + if err != nil { + panic(err) } + equal := string(out) - var notEqual string - switch v := ifNotEqual.(type) { - case map[string]string, []string, string: - out, err := json.Marshal(ifNotEqual) - if err != nil { - panic(err) - } - notEqual = string(out) - default: - fmt.Printf("Unsupported type for ifNotEqual: %T\n", v) - return encode(fmt.Sprintf(`{ "Fn::If" : [ %q, %q, %q ] }`, value, ifEqual, ifNotEqual)) + out, err = json.Marshal(ifNotEqual) + if err != nil { + panic(err) } + notEqual := string(out) if isBase64(equal) { if isBase64(notEqual) {