DataDog / datadog-cloudformation-macro

CloudFormation Macros by Datadog
Apache License 2.0
14 stars 22 forks source link

Handle conditionals in Layers definition #93

Closed sfirrin closed 1 year ago

sfirrin commented 1 year ago

What does this PR do?

Fixes a bug where the macro would get an error when the Layers definition was not an array, e.g. when it's a CFN conditional. This PR updates the code to handle this situation and add the expected layers to all possible outputs of the conditional

Motivation

Bug

Testing Guidelines

Additional Notes

Types of changes

Check all that apply

codecov-commenter commented 1 year ago

Codecov Report

Merging #93 (8ee00d3) into master (e897275) will decrease coverage by 0.94%. The diff coverage is 65.21%.

:exclamation: Current head 8ee00d3 differs from pull request most recent head b0176c5. Consider uploading reports for the commit b0176c5 to get more accurate results

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
- Coverage   87.39%   86.46%   -0.94%     
==========================================
  Files           8        8              
  Lines         595      613      +18     
  Branches      151      154       +3     
==========================================
+ Hits          520      530      +10     
- Misses         64       72       +8     
  Partials       11       11              
Impacted Files Coverage Δ
serverless/src/layer.ts 91.34% <63.63%> (-7.51%) :arrow_down:
serverless/src/index.ts 91.54% <100.00%> (+0.12%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

sfirrin commented 1 year ago

That's a good question @duncanista. AFAIK array and "Fn::If" objects are the only two possible values for Layers in the code, did you have a situation in particular in mind? The CFN doc on the Lambda resource https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-layers says Layers is always a string[] by which I guess it means Layers always has to evaluate to a string[] after being transformed and functions are evaluated. Looking at the doc for intrinsic CFN functions https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html AFAICT the only one that could be an object at the root (rather than an array item) is Fn::If