Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Terraform Templates to Cloudformation Templates

I want to convert the existing terraform templates(hcl) to aws cloudformation templates(json/yaml).

I basically want to find security issues with these templates through CFN_NAG.

An approach that I have already tried was converting HCL to JSON and then passing the template to CFN_NAG but I received a failure since both the templates have different structure.

Can anyone please provide any suggestions here?

like image 683
H4X Avatar asked Nov 01 '17 23:11

H4X


People also ask

Does Terraform translate to CloudFormation?

Part 3: translation 1) Terraform accepts CF stack templates: By Stating Resource: aws_cloudformation_stack_set, you can manage a CloudFormation stack set, so this functionality allows you to deploy CloudFormation templates. It only accepts JSON templates.

Does Terraform create CloudFormation stack?

The Terraform philosophy is similar to CloudFormation, but the applied configuration is stored onto a “Terraform State” (a text file stored within a S3 bucket), instead of a CloudFormation stack.

How do I export a CloudFormation template?

To export a stack's output value, use the Export field in the Output section of the stack's template. To import those values, use the Fn::ImportValue function in the template for the other stacks. For a walkthrough and sample templates, see Walkthrough: Refer to resource outputs in another AWS CloudFormation stack.

Does Pulumi use CloudFormation?

The Pulumi AWS package provides a CloudFormation Stack resource type. Using this type, you can deploy an existing AWS CloudFormation template written in YAML or JSON.


1 Answers

A rather convoluted way of achieving this is to use Terraform to stand-up actual AWS environments, and then to use AWS’s CloudFormer to extract CloudFormation templates (JSON or YAML) from what Terraform has built. At which point you can use cfn-nag.

CloudFormer has some limitations, in that not all AWS resources are currently supported (RDS Security Groups for example) , but it will get you all the basic AWS resources.

Don't forget to remove all the environments, including CloudFormer's, to minimise the cost.

like image 159
P Burke Avatar answered Sep 28 '22 04:09

P Burke