Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip null values from CloudFormation template resource properties #10304

Merged
merged 2 commits into from Dec 6, 2021

Conversation

GurmeharS
Copy link
Contributor

Previously, stripNullPropsFromTemplateResources stripped null from top-level resource properties in the compiled CFN template.

This PR:

  • adds functionality to traverse the properties deeply, and strips null from nested objects within the properties
  • allows for users to provide default value as null if they would like the variable to be removed from the template if the initial value is not available (see Allow for optional environment variables #10279)

Closes: #10279

@codecov
Copy link

codecov bot commented Dec 2, 2021

Codecov Report

Merging #10304 (71142cc) into master (d52526b) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10304      +/-   ##
==========================================
+ Coverage   85.40%   85.42%   +0.01%     
==========================================
  Files         339      339              
  Lines       13877    13910      +33     
==========================================
+ Hits        11852    11882      +30     
- Misses       2025     2028       +3     
Impacted Files Coverage Δ
...package/lib/stripNullPropsFromTemplateResources.js 100.00% <100.00%> (ø)
lib/configuration/variables/resolve.js 97.72% <0.00%> (-0.87%) ⬇️
lib/plugins/aws/provider.js 94.97% <0.00%> (ø)
lib/plugins/aws/package/compile/events/sqs.js 100.00% <0.00%> (ø)
lib/plugins/aws/utils/getS3EndpointForRegion.js 100.00% <0.00%> (ø)
lib/plugins/aws/package/compile/events/stream.js 98.23% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d52526b...71142cc. Read the comment docs.

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GurmeharS that looks great ! I've just propose one minor simplification, and it's good to go

Object.entries(obj).forEach(([propName, propVal]) => {
if (propVal === null) {
delete obj[propName];
} else if (propVal && typeof propVal === 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify to if (typeof === 'object')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Pushed out an update 👍

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @GurmeharS !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for optional environment variables
2 participants