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

ValueError: Fn::Sub not allowed to be nested in None #244

Open
anatanna opened this issue Dec 13, 2023 · 2 comments
Open

ValueError: Fn::Sub not allowed to be nested in None #244

anatanna opened this issue Dec 13, 2023 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@anatanna
Copy link

Template: https://aws-ia-us-east-1.s3.us-east-1.amazonaws.com/cfn-ps-darktrace-vsensor/templates/darktrace-vsensor-workload.template.yaml

Environment:
Python 3.11.5
pip 23.3.1 from /home/user/venv_3.11/lib64/python3.11/site-packages/pip (python 3.11)
cf2tf 0.6.2

Error:
// Converting darktrace-vsensor-workload.template.yaml to Terraform!
Traceback (most recent call last):
File "/home/localadmin/venv_3.11/bin/cf2tf", line 8, in
sys.exit(cli())
^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/click/core.py", line 1157, in call
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/app.py", line 44, in cli
config = TemplateConverter(tmpl_path.stem, cf_template, search_manger).convert()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 97, in convert
tf_resources = self.convert_to_tf(self.manifest)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 144, in convert_to_tf
tf_resources.extend(converter(resources))
^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 344, in convert_resources
resolved_values = self.resolve_values(
^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 176, in resolve_values
data[key] = self.resolve_values(
^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 176, in resolve_values
data[key] = self.resolve_values(
^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 206, in resolve_values
value = self.resolve_values(
^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 206, in resolve_values
value = self.resolve_values(
^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 217, in resolve_values
resolved_list_values = [
^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 218, in
self.resolve_values(item, allowed_func, prev_func) for item in data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 176, in resolve_values
data[key] = self.resolve_values(
^^^^^^^^^^^^^^^^^^^^
File "/home/localadmin/venv_3.11/lib64/python3.11/site-packages/cf2tf/convert.py", line 204, in resolve_values
raise ValueError(f"{key} not allowed to be nested in {prev_func}.")
ValueError: Fn::Sub not allowed to be nested in None.

@shadycuz
Copy link
Member

oh this is an interesting bug, thanks for reporting.

@shadycuz shadycuz added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Dec 14, 2023
@shadycuz
Copy link
Member

This indeed turned out to be interesting and tricky to fix.

The issue is that Cloudformation allows two forms of it's "Sub" function. There is the single version: !Sub some-${var} and then the list form:

!Sub:
 - some-${var}
 - var : foo

The issue is that I don't think !Sub some${!Sub ${var}} is valid, but this is:

!Sub:
 - some-${var}
 - var: !Sub "${var}"

I don't currently have an easy way to fix this, but its on my radar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants