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

Add cloudformation.TransformFn() #352

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cloudformation/intrinsics.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ func Or(conditions []string) string {
return encode(fmt.Sprintf(`{ "Fn::Or": [ %v ] }`, printList(conditions)))
}

// (str, map[str]str) -> str

func TransformFn(name string, parameters map[string]string) string {
var params []string
for key, value := range parameters {
params = append(params, fmt.Sprintf(`"%v" : "%v"`, key, value))
}

return encode(fmt.Sprintf(`{ "Fn::Transform" : { "Name" : "%v", "Parameters" : { "%v" } } }`, name, strings.Trim(strings.Join(params, `, `), `, "`)))
}

// encode takes a string representation of an intrinsic function, and base64 encodes it.
// This prevents the escaping issues when nesting multiple layers of intrinsic functions.
func encode(value string) string {
Expand Down
8 changes: 8 additions & 0 deletions intrinsics/fntransform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package intrinsics

func FnTransform(name string, input interface{}, template interface{}) interface{} {

// { "Fn::Transform" : { "Name" : "macro name", "Parameters" : {"key" : "value", ... } } }

return nil
}
1 change: 1 addition & 0 deletions intrinsics/intrinsics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var defaultIntrinsicHandlers = map[string]IntrinsicHandler{
"Fn::Sub": FnSub,
"Ref": Ref,
"Fn::Cidr": nonResolvingHandler,
"Fn::Transform": FnTransform,
}

// ProcessorOptions allows customisation of the intrinsic function processor behaviour.
Expand Down