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

add support for CommaDelimitedList in cloudformation macro #10836

Merged
merged 3 commits into from
May 17, 2024

Conversation

sannya-singal
Copy link
Contributor

@sannya-singal sannya-singal commented May 16, 2024

Motivation

When creating resource from AWS::CloudFormation::Macro, there was a missing support of parameter type CommaDelimitedList. This was reported in #10794 where user is trying to create a nested template with the following parameter:

Subnets:
   Type: CommaDelimitedList
   Description: The IDs of the public DMZ subnets

using PyPlate Macros: https://github.com/aws-cloudformation/aws-cloudformation-macros/tree/master/PyPlate.

Sample template:

AWSTemplateFormatVersion: "2010-09-09"
Description: tests String macro functions
Parameters:
  Tags:
    Default: "Env=Prod,Application=MyApp,BU=ModernisationTeam"
    Type: "CommaDelimitedList"
Resources:
  S3Bucket:
    Type: "AWS::S3::Bucket"
    Properties:
      Tags: |
        #!PyPlate
        output = []
        for tag in params['Tags']:
           key, value = tag.split('=')
           output.append({"Key": key, "Value": value})
Transform: [PyPlate]

This resulted in the following error:

2024-05-16T16:22:39.599 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e] Traceback (most recent call last):
2024-05-16T16:22:39.599 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]   File "/var/task/index.py", line 34, in handler
2024-05-16T16:22:39.599 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]     macro_response["fragment"] = obj_iterate(response, params)
2024-05-16T16:22:39.599 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-16T16:22:39.599 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]   File "/var/task/index.py", line 10, in obj_iterate
2024-05-16T16:22:39.599 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]     obj[k] = obj_iterate(obj[k], params)
2024-05-16T16:22:39.599 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-16T16:22:39.599 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]   File "/var/task/index.py", line 10, in obj_iterate
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]     obj[k] = obj_iterate(obj[k], params)
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]   File "/var/task/index.py", line 10, in obj_iterate
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]     obj[k] = obj_iterate(obj[k], params)
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]   [Previous line repeated 1 more time]
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]   File "/var/task/index.py", line 17, in obj_iterate
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]     exec(obj, params)
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e]   File "<string>", line 4, in <module>
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e] ValueError: not enough values to unpack (expected 2, got 1)
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e] END RequestId: 372f6a8b-d680-44ce-8787-32a9a06f9e7e
2024-05-16T16:22:39.600 DEBUG --- [et.reactor-0] l.s.l.i.version_manager    : [pyplate-macro-TransformFunction-cd8fc0aa-372f6a8b-d680-44ce-8787-32a9a06f9e7e] REPORT RequestId: 372f6a8b-d680-44ce-8787-32a9a06f9e7e    Duration: 12.25 ms      Billed Duration: 13 ms   Memory Size: 128 MB     Max Memory Used: 128 MB 

Changes

This PR:

  • adds support of CommaDelimitedList param type in cloudformation macro
  • adds AWS validated test using PyPlate template to check the results.

closes: #10794

@sannya-singal sannya-singal self-assigned this May 16, 2024
@sannya-singal sannya-singal added semver: patch Non-breaking changes which can be included in patch releases aws:cloudformation AWS CloudFormation labels May 16, 2024
Copy link

github-actions bot commented May 16, 2024

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 36m 38s ⏱️ + 1m 39s
2 956 tests +1  2 656 ✅ +1  300 💤 ±0  0 ❌ ±0 
2 958 runs  +1  2 656 ✅ +1  302 💤 ±0  0 ❌ ±0 

Results for commit c51717d. ± Comparison against base commit 21bdd43.

♻️ This comment has been updated with latest results.

@sannya-singal sannya-singal marked this pull request as ready for review May 16, 2024 11:00
for tag in tags_s3:
if tag["Key"] in param_tags:
assert tag["Value"] == param_tags[tag["Key"]]
assert len(tags_s3) >= len(param_tags)
Copy link
Member

Choose a reason for hiding this comment

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

Small nit: This could be a snapshot

Copy link
Member

@pinzon pinzon left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this.

@sannya-singal sannya-singal added this to the 3.5 milestone May 17, 2024
@sannya-singal sannya-singal merged commit c3e9179 into master May 17, 2024
30 checks passed
@sannya-singal sannya-singal deleted the cfn_macro branch May 17, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:cloudformation AWS CloudFormation semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Parameter type ignored when passed to NestedStacks
2 participants