raymondbutcher / pretf

Generate Terraform code with Python
https://pretf.readthedocs.io/
MIT License
104 stars 14 forks source link

When trying to do the equivalent of terraform plan -out a_plan, pretf throws an IndexError #54

Closed manniche closed 4 years ago

manniche commented 4 years ago

Running with terraform 0.12.24 and pretf 0.6.0

When trying to do the equivalent of terraform plan -out a_plan, pretf throws an IndexError:

$ pretf plan -out "planfile"
Traceback (most recent call last):
  File "/usr/bin/pretf", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.8/site-packages/pretf/cli.py", line 12, in main
    result = run()
  File "/usr/lib/python3.8/site-packages/pretf/cli.py", line 28, in run
    cmd, args, _, _ = util.parse_args()
  File "/usr/lib/python3.8/site-packages/pretf/util.py", line 274, in parse_args
    config_dir = args[1]
IndexError: list index out of range
manniche commented 4 years ago

The list args in the case of pretf plan -out a_plan contains only a single element; a_plan and the reference to the second element will cause an IndexError

The for loop in lines 241-252 will set cmd to plan, flags to ['-out'] and args to ['a_plan'], invalidating the assumption in line 274 that len(args)>1 since it holds that len(args)==1

raymondbutcher commented 4 years ago

Thanks for the bug report @manniche.

Obviously Pretf shouldn't crash like this but can you try terraform plan -out=a_plan as per the Terraform docs?

manniche commented 4 years ago

@raymondbutcher Thanks for the quick reply. I was unaware that I had successfully been using the plan -out a_plan successfully in terraform contrary to what their docs state! But I remember you yourself also mentioning somewhere else that their docs are inconsistent.

pretf plan -out=a_plan works as expected and as documented by terraform as well. Thanks for the pointer.

With the code currently in master, the logic has been changed to just consume all items of the args list, so that will fix the issue I have observed. Feel free to close this issue at your leisure.

And thanks for a fantastic piece of software. I have been wanting this for almost a year and have made my own hacks to provide some of the functionality that pretf implements, just not as good as you've done it. Please keep up the good work and feel free to ping me if I can help out with something in the codebase.