Convert AWS CloudFormation to Terraform template

From a conceptual point of view, CFT and TF are not feature equivalent. You won't be able to express all things that CFT is able to deploy in TF.

From a practical perspective, it is somehow possible but you need to write a grammar converter ; and that is going very complex (almost impossible) if your CFT is using intrinsic functions https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html

In my opinion, you should use terraform aws_cloudformation_stack to deploy your existing CFT instead of trying to convert it (https://www.terraform.io/docs/providers/aws/r/cloudformation_stack.html).


So far I havent seen an easy way to convert CFN written in YAML or JSON to terraform code.

However you can try to deploy the resources via CFN, then use terraforming against the account you deployed CFN into. You can suck out most of the resources out in terraform code but not all. The code will need some refactoring and remaining resources (lambdas etc.) need to be rewritten in TF or "translated" from CFN into terraform.

Other option is to use terraform aws_cloudformation_stack to deploy CFN stack for you and manage it from there.


There isn't any tool to convert Cloudformation to Terraform, unless you're talking about simply managing Cloudformation templates via aws_cloudformation_stack.

And it's likely that you wouldn't even want to use such a tool anyway. Imagine a Cloudformation template which creates four subnets, probably written out using copy/pasted JSON or YAML with four separate resources ("PublicSubnet0", "PublicSubnet1", and so on). The way you'd likely do that in Terraform is with aws_subnet and count = 4. Any converter that you use should be smart enough to handle that. But it should also be smart enough to know that "PrivateSubnet0" would be a whole different aws_subnet with its own count. That's very hard for any software to do.

So if you care about code quality in your Terraform scripts, do it manually.