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

Unable to use CommaDelimitedList Parameters as inputs to intrinsic functions #353

Open
jamesmcminn96 opened this issue Sep 23, 2024 · 0 comments · May be fixed by #354
Open

Unable to use CommaDelimitedList Parameters as inputs to intrinsic functions #353

jamesmcminn96 opened this issue Sep 23, 2024 · 0 comments · May be fixed by #354
Assignees
Labels
bug Something isn't working

Comments

@jamesmcminn96
Copy link

Hi! Thanks for the great tool.

Versions
Python: 3.11
cloud-radar: https://github.com/DontShaveTheYak/cloud-radar/tree/0.12.0

Issue
With the following simplified template I'm unable to make use of CommaDelimitedList effectively when passing parameters of that type into other functions.

Parameters:
  AllowedWriters:
    Type: CommaDelimitedList
    Description: Principals allowed to write

Conditions:
  EmptyList:
    !Equals
      - !Join ["", !Ref AllowedWriters]
      - ""

The following code:

from cloud_radar.cf.unit import Template

cloudformation_template = Template.from_yaml('template.yaml')

stack_cdl = cloudformation_template.create_stack({
    'AllowedWriters': 'abc,123'
})

stack_list = cloudformation_template.create_stack({
    'AllowedWriters': ['abc','123']
})
`stack_cdl` results in the error:
Traceback (most recent call last):
  File "/Users/james/code/scratch/cloud-radar-patch/main.py", line 4, in <module>
    stack = cloudformation_template.create_stack({
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 322, in create_stack
    self.render(params, parameters_file=parameters_file)
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 158, in render
    self.template = self.render_all_sections(self.template)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 254, in render_all_sections
    template["Conditions"] = self.resolve_values(
                             ^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 354, in resolve_values
    data[key] = self.resolve_values(
                ^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 384, in resolve_values
    value = self.resolve_values(
            ^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 400, in resolve_values
    return [
           ^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 401, in <listcomp>
    self.resolve_values(
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 384, in resolve_values
    value = self.resolve_values(
            ^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 400, in resolve_values
    return [
           ^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 401, in <listcomp>
    self.resolve_values(
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 389, in resolve_values
    funct_result = allowed_func[key](self, value)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/functions.py", line 555, in join
    raise TypeError(
TypeError: Fn::Join-- The first value must be a String and the second a List.
`stack_list` results in the error:
Traceback (most recent call last):
  File "/Users/james/code/scratch/cloud-radar-patch/main.py", line 4, in <module>
    stack = cloudformation_template.create_stack({
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 322, in create_stack
    self.render(params, parameters_file=parameters_file)
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 154, in render
    self.set_parameters(params)
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 520, in set_parameters
    validate_parameter_constraints(
  File "/Users/james/.local/share/virtualenvs/cloud-radar-patch-LSQMlmdS/lib/python3.11/site-packages/cloud_radar/cf/unit/_template.py", line 557, in validate_parameter_constraints
    for part in parameter_value.split(","):
                ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'split'

It appears that functions like Join and Select within the template are unable to handle the case where the parameter is a CommaDelimitedList. It expects it to be both a list and a string it can split on.

@dhutchison dhutchison added the bug Something isn't working label Sep 23, 2024
@dhutchison dhutchison self-assigned this Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants