CloudFormation YAML to Terraform Converter

Convert a CloudFormation YAML template, short-form tags and all, into Terraform HCL resources, variables and outputs.

Your codeCloudFormation (YAML)
Drop the file to load it
Tab indents · Esc, Tab exits
ResultTerraform (HCL)
Your Terraform (HCL) will appear hereClick Convert to Terraform or press Ctrl Enter
main.tf
Don't paste secrets

How to convert a CloudFormation YAML template to Terraform

  1. Add your codePaste it into the CloudFormation (YAML) editor, drag in a file, or keep the sample to see how it works.
  2. Convert to TerraformClick the button or press Ctrl + Enter. The result streams into the right-hand editor.
  3. Review and use itCopy or download the result, then test it before you rely on it. AI output is a strong first draft, not a guarantee.

From YAML tags to HCL expressions

YAML templates usually use the short form of intrinsic functions: !Ref, !GetAtt SessionsTable.Arn and !Sub "sessions-${Stage}". The converter rewrites them as Terraform references and interpolation, such as aws_dynamodb_table.sessions.arn and "sessions-${var.stage}". Parameters become variables, and AllowedValues can carry over as a validation block.

Resource properties map to provider arguments, with some structural changes. A DynamoDB TimeToLiveSpecification becomes a ttl block, KeySchema and AttributeDefinitions become hash_key plus attribute blocks, and an IAM role's inline Policies often become separate aws_iam_role_policy resources.

The converted code creates new resources unless you import the existing ones. Retain them in the stack, then adopt them with Terraform import blocks.

Before deleting the old stack, set DeletionPolicy: Retain on its resources and update the stack. Deleting a stack without it removes the resources too.

Tips for better results

  • Paste valid CloudFormation YAML. Short-form tags like !Ref are fine. Tabs for indentation aren't valid YAML and confuse the conversion.
  • Expand SAM first. For Transform: AWS::Serverless-2016-10-31 templates, download the processed template with aws cloudformation get-template --template-stage Processed and convert that.
  • Check ARN construction. !Sub arn:aws:... strings often have a direct Terraform attribute, such as .arn, which is cleaner than rebuilding the string.
  • Convert conditions with care. Conditions and !If usually become count or conditional expressions. Test each branch with different variable values.
  • Run a plan after import. terraform plan should show no changes for resources you imported.

Frequently asked questions

What happens to !Ref, !Sub and !GetAtt?

They become Terraform expressions. !GetAtt Table.Arn becomes aws_dynamodb_table.table.arn, !Sub becomes string interpolation, and !Ref becomes whichever attribute that resource type returns for Ref, such as an ID, name or ARN.

Can I move deployed resources without recreating them?

Yes. Retain the resources in the CloudFormation stack, delete the stack, then import each resource into Terraform with import blocks. Check that terraform plan shows no changes afterwards.

What about SAM and Serverless templates?

SAM resources such as AWS::Serverless::Function expand into several CloudFormation resources at deploy time. Convert the processed template to see the real resources you need in Terraform.

Is there a JSON version of this converter?

Yes. For JSON templates, use the CloudFormation JSON to Terraform converter.