DontShaveTheYak / cf2tf

Convert Cloudformation templates to Terraform.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for SAM resource types like AWS::Serverless::Function

praveenrengarajan opened this issue · comments

https://github.com/awslabs/aws-api-gateway-developer-portal/blob/main/cloudformation/template.yaml

// Converting aws_cf_template.yaml to Terraform!
[####--------------------------------] 12% 00:03:03 code has been checked out.
Traceback (most recent call last):
File "c:\users\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "c:\users\appdata\local\programs\python\python37\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\AppData\Local\Programs\Python\Python37\Scripts\cf2tf.exe_main
.py", line 9, in
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 1130, in call
return self.main(*args, **kwargs)
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\cf2tf\app.py", line 44, in cli
config = TemplateConverter(tmpl_path.stem, cf_template, search_manger).convert()
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\cf2tf\convert.py", line 94, in convert
tf_resources = self.convert_to_tf(self.manifest)
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\cf2tf\convert.py", line 146, in convert_to_tf
tf_resources.extend(converter(resources))
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\cf2tf\convert.py", line 332, in convert_resources
properties, functions.ALL_FUNCTIONS
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\cf2tf\convert.py", line 182, in resolve_values
value, allowed_func, prev_func, inside_function=inside_function
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\cf2tf\convert.py", line 193, in resolve_values
return allowed_func[key](self, value)
File "c:\users\appdata\local\programs\python\python37\lib\site-packages\cf2tf\conversion\expressions.py", line 422, in get_att

commented

I think I started on this back in December but was distracted by the holidays. I'm taking a fresh look at this now and I have identified the issue.

When I turn on debug logging I see:

debug: Converting the intrinsic functions to Terraform expressions...
debug: Fn::GetAtt - Looking up resource "CatalogUpdaterLambdaFunction"
debug: Converted CF type AWS::Serverless::Function to search term serverless function.
debug: Searcing for serverless function in terraform docs...
debug: Best match was lambda function event invoke config at /tmp/terraform_src/website/docs/r/lambda_function_event_invoke_config.html.markdown with score of 86.

Which basically means the program converted AWS::Serverless::Function to aws_lambda_function_event_invoke_config. I'm not sure why it ranked aws_lambda_function_event_invoke_config higher than aws_lambda_function but that is the bug.

I will see what I can do to fix this. My worry is that by changing the search algorithm it could break lots of other working stuff. There is a new "override" system that I recently released. I could use it to change AWS::Serverless::Function to AWS::Lambda::Function and that might also fix it in this case.

commented

I actually understand this a lot better now... AWS::Serverless::Function is part of SAM and is not supported yet. I think this is similar to #42 but not quite the same thing.