cf2tf icon indicating copy to clipboard operation
cf2tf copied to clipboard

!Importvalue function conversation to Relevant terraform code

Open dezzertfox opened this issue 2 years ago • 4 comments

I am trying to use this source code ato convert cfn template to tf . issue am facing is while converting !Import value fun which is intrinsic to Cfn and No parallel in Terraform.. is this issue resolved or we are still following up please suggest way out.

dezzertfox avatar Sep 06 '22 17:09 dezzertfox

@shadycuz can you please suggets on this

dezzertfox avatar Sep 06 '22 17:09 dezzertfox

@dezzertfox Can you post the exact error you are getting?

I don't think we ever implemented the logic to handle !Import function, because as you mentioned, there is no equivalent in Terraform.

I think we could fix this in a couple different ways:

  1. Instead of throwing an error, we could replace foo: !ImportValue bar with some value. Maybe foo = !importValue bar, which will cause an error in Terraform and remind you that you need to replace it with something. Maybe a Terraform variable or a Terraform datasource block.

  2. We could replace foo: !ImportValue bar with a variable like: foo = var.bar. This would be similar to #1 but a much better user experience. When you first go to deploy your template it will ask you for the value of foo variable. We wont know any of the typing information but we can add a description about where this variable came from.

For now you can do a find and replace on your templates to turn !ImportValue into ImportValue. This should turn it into a string (at least in YAML). Which would allow the conversion to continue, but would still need to be changed manually before your cloudformation is able to be deployed.

shadycuz avatar Sep 06 '22 17:09 shadycuz

@xentripetal your input was very valuable last time, can you think of a better way to handle the Cloudformation !ImportValue intrinsic function?

shadycuz avatar Sep 06 '22 17:09 shadycuz

relevant code here... in case someone wants to take a crack at it. I wont be able to look at it until friday? or so.

https://github.com/DontShaveTheYak/cf2tf/blob/5ab3137563c6287b7e7c334225afa84bd17dfeba/src/cf2tf/conversion/expressions.py#L483-L491

shadycuz avatar Sep 06 '22 17:09 shadycuz

This was completed in #132

shadycuz avatar Jun 17 '23 14:06 shadycuz