Skip to content

Commit

Permalink
feat(intrinsics): Add cloudformation.TransformFn() (awslabs#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrn committed Mar 8, 2021
1 parent f7bd1e8 commit 9a1e331
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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

0 comments on commit 9a1e331

Please sign in to comment.