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

feat(cloudformation): Support Fn::Sub in cases of using a pseudo parameter #6835

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

bo156
Copy link
Contributor

@bo156 bo156 commented Nov 13, 2024

User description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Pseudo Parameter in CFN is a parameter which is dynamically available (see reference).
As we do not render it on buildtime, we want to handle this case by keeping the reference itself without the
value, so we can at least build a semi-full resource.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

Generated description

Below is a concise technical summary of the changes proposed in this PR:

Introduce support for handling Fn::Sub with pseudo parameters in AWS CloudFormation templates. The CloudformationVariableRenderer class now includes a method _handle_sub_with_pseudo_param to manage these cases by retaining the reference without the value, ensuring a semi-complete resource build. The PseudoParameters enum is added to cfn_keywords.py to define available pseudo parameters. Test cases in test_render.py and new JSON/YAML resources validate the changes, ensuring that pseudo parameters are correctly processed and that the Fn::Sub function behaves as expected.

TopicDetails
New Test Resources Introduce new JSON/YAML resources and test cases to validate the Fn::Sub function and pseudo parameter handling in CloudFormation templates.
Modified files (5)
  • tests/cloudformation/graph/graph_runner/test_running_graph_checks.py
  • tests/cloudformation/graph/graph_runner/external_graph_checks/jsonpath_policy.yaml
  • tests/cloudformation/graph/graph_runner/resources/jsonpath_policy/pass_str.json
  • tests/cloudformation/graph/graph_runner/resources/jsonpath_policy/fail_dict.json
  • tests/cloudformation/graph/graph_runner/resources/jsonpath_policy/fail_str.json
Latest Contributors(2)
UserCommitDate
nimrodkor@gmail.comMove-test-yamls-for-k8...January 24, 2022
@gruebeladd-pre-commit-flake8December 12, 2021
PseudoParameters Enum Add PseudoParameters enum to define available pseudo parameters in CloudFormation templates.
Modified files (1)
  • checkov/cloudformation/parser/cfn_keywords.py
Latest Contributors(2)
UserCommitDate
@gruebeladd-AWS-SAM-support-2013November 30, 2021
@Saarettchanged-a-few-enms-to-...August 17, 2021
Renderer Enhancement Enhance the CloudformationVariableRenderer to handle Fn::Sub with pseudo parameters, ensuring references are maintained without values for semi-complete resource builds.
Modified files (1)
  • checkov/cloudformation/graph_builder/variable_rendering/renderer.py
Latest Contributors(2)
UserCommitDate
@gruebelbreak-general-remove-P...October 04, 2023
maxam@post.bgu.ac.iladd-exception-for-dict...June 09, 2022
Test Updates Update test cases to validate the handling of Fn::Sub with pseudo parameters, ensuring correct processing and expected behavior.
Modified files (3)
  • tests/cloudformation/graph/graph_builder/test_render.py
  • tests/cloudformation/graph/graph_builder/resources/variable_rendering/render_sub/yaml/test.yaml
  • tests/cloudformation/graph/graph_builder/resources/variable_rendering/render_sub/json/test.json
Latest Contributors(2)
UserCommitDate
@gruebelchore-use-mock.patch-f...January 17, 2023
@SaarettCFN-Func-is-not-evalua...October 07, 2021
This pull request is reviewed by Baz. Join @bo156 and the rest of your team on (Baz).

@bo156 bo156 force-pushed the feature/cfn-support-sub-special-cases branch from 620f964 to feaf7e2 Compare November 13, 2024 15:43
Copy link
Contributor

@SteveVaknin SteveVaknin left a comment

Choose a reason for hiding this comment

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

Nice 👌

@bo156 bo156 merged commit 33abf40 into main Nov 14, 2024
42 checks passed
@bo156 bo156 deleted the feature/cfn-support-sub-special-cases branch November 14, 2024 12:43
Saarett pushed a commit that referenced this pull request Nov 14, 2024
…meter (#6835)

* Added calculation of Fn::Sub in case of using Pseudo Parameter as it is a default one from cloudformation and shouldn't exist in the code

* Only do sub in case of pseudo parameter usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants