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

IndexError: list index out of range (Convert CloudFormation Template to Terraform) #325

Open
shawnhankim opened this issue Jul 20, 2024 · 5 comments

Comments

@shawnhankim
Copy link

Issues:

$ cf2tf cloudformation-template.yaml -o tf

// Converting cloudformation-template.yaml to Terraform!
// Existing Terraform src code found at /var/folders/jj/2yn5ym4j2wj892zt7r_9z6q00000gn/T/terraform_src.
Traceback (most recent call last):
  File "/Users/dev/.pyenv/versions/3.12.4/bin/cf2tf", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/dev/.local/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/.local/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/dev/.local/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/.local/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cf2tf/app.py", line 44, in cli
    config = TemplateConverter(tmpl_path.stem, cf_template, search_manger).convert()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cf2tf/convert.py", line 97, in convert
    tf_resources = self.convert_to_tf(self.manifest)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cf2tf/convert.py", line 144, in convert_to_tf
    tf_resources.extend(converter(resources))
                        ^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cf2tf/convert.py", line 352, in convert_resources
    overrided_values = perform_global_overrides(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cf2tf/convert.py", line 645, in perform_global_overrides
    params = override(tc, params)
             ^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cf2tf/conversion/overrides.py", line 55, in tag_conversion
    first_item = original_tags[0]
                 ~~~~~~~~~~~~~^^^
IndexError: list index out of range
@rowlinsonmike
Copy link

@shawnhankim this traceback is related to your cloudformation yaml having a Tags property with an empty list. You could omit the Tags property altogether from your cloudformation, change the Tags property to be a dictionary {}, or add at least one key value pair to the empty list.

this is bad

Tags: []

these work

Tags:{}  # this works bc of line 50 in overrides.py

# OR

Tags:
  - Key: Name
    Value: mytable

@shawnhankim
Copy link
Author

@rowlinsonmike :

  • Thanks for your feedback.
  • The template is generated by CloudFormation so I am wondering if it is a bug from AWS.

@shadycuz
Copy link
Member

@shawnhankim Thanks for reporting this. Did you get this template from an official AWS source? If so, we could support this. But I agree with @rowlinsonmike, that tags are usually done with a list with -.

@shawnhankim
Copy link
Author

@shadycuz Thanks for your feedback and question. Yes, I directly generated the template in the AWS CloudFormation Console.

@shahruk
Copy link
Contributor

shahruk commented Nov 6, 2024

I was also encountering this issue on a brand new AWS account where I am using AWS Organizations. I've opened #345 to resolve this issue.

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

No branches or pull requests

4 participants