ValueError: Fn::Sub not allowed to be nested in None
anatanna opened this issue · 2 comments
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.
oh this is an interesting bug, thanks for reporting.
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.