Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Fix if implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
xrn authored and rubenfonseca committed Aug 17, 2022
1 parent f5ea2d1 commit 82f234e
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions cloudformation/intrinsics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 82f234e

Please sign in to comment.