awslabs / goformation

GoFormation is a Go library for working with CloudFormation templates.
Apache License 2.0
847 stars 195 forks source link

feat(intrinsics): support nested intrinsics #571

Closed jarreds closed 1 year ago

jarreds commented 1 year ago

Description of changes:

Currently, most intrinsics use string quoted encoded values. This prevents us from being able to nest intrinsics, although CloudFormation supports these statements natively.

This switches a few important intrinsics to use JSON encoding vs string quoting for encoded intrinsic values. This allows us to nest intrinsics.

Newly supported examples:

SelectPtr(0, GetAZs(""))

Select(2, Split("/", GetAtt("Bucket", "WebsiteURL")))

JoinPtr("", []string{
  Sub("arn:aws:nnnnn:${AWS::Region}:${AWS::AccountId}:identity/"),
  If(
    "SomeAccount",
    canonicalDomainName,
    cloudformation.ImportValue(someOtherDomain),
  ),
})

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

jarreds commented 1 year ago

@rubenfonseca WDYT about merging? Anything you'd like to see me address?

rubenfonseca commented 1 year ago

@jarreds apologies, looking at this today

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 58.33% and project coverage change: -0.04 :warning:

Comparison is base (961063c) 6.01% compared to head (9b28abf) 5.97%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #571 +/- ## ========================================= - Coverage 6.01% 5.97% -0.04% ========================================= Files 30 30 Lines 16869 16873 +4 ========================================= - Hits 1014 1009 -5 - Misses 15830 15839 +9 Partials 25 25 ``` | [Impacted Files](https://codecov.io/gh/awslabs/goformation/pull/571?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs) | Coverage Δ | | |---|---|---| | [cloudformation/intrinsics.go](https://codecov.io/gh/awslabs/goformation/pull/571?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs#diff-Y2xvdWRmb3JtYXRpb24vaW50cmluc2ljcy5nbw==) | `43.50% <58.33%> (-3.44%)` | :arrow_down: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

rubenfonseca commented 1 year ago

Looking at this now

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 7.4.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: