How to convert a CloudFormation JSON template to Terraform
- Add your codePaste it into the CloudFormation (JSON) editor, drag in a file, or keep the sample to see how it works.
- Convert to TerraformClick the button or press Ctrl + Enter. The result streams into the right-hand editor.
- 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.
Translating intrinsic functions to Terraform
The heart of this conversion is CloudFormation's intrinsic functions. {"Ref": "OrderQueue"} becomes a resource attribute such as aws_sqs_queue.order_queue.id, Fn::GetAtt becomes an attribute like .arn, and Fn::Sub becomes string interpolation: "order-events-${var.env}". Parameters become variable blocks and Outputs become output blocks.
What Ref returns depends on the resource type: an SNS topic's ARN, but an SQS queue's URL. The converter has to pick the matching Terraform attribute for each case, so these are the first lines to check. Conditions usually become count expressions, and Mappings become maps in locals.
Converting the template doesn't release the resources from their CloudFormation stack. Retain them in the stack first, then adopt them with Terraform import blocks.
Set "DeletionPolicy": "Retain" on every resource and update the stack before you delete it. Otherwise deleting the stack also deletes the resources you just imported into Terraform.
Tips for better results
- Expand transforms first. SAM templates (
AWS::Serverless-2016-10-31) and macros hide the real resources. Get the processed template withaws cloudformation get-template --template-stage Processedand convert that. - Check every
Ref. Confirm the Terraform attribute returns the same thing, for example.idfor a queue URL and.arnfor a topic ARN. - Custom resources don't convert directly.
Custom::types run a Lambda function during deployment. Replace them with a native Terraform resource or a separate step. - Convert nested stacks one at a time. Each nested template maps well to its own Terraform module.
- Plan after importing. Once resources are imported,
terraform planshould report no changes. Differences point to arguments the converter set differently.
Frequently asked questions
How do I move a stack's resources from CloudFormation to Terraform?
Set DeletionPolicy: Retain on each resource and update the stack, then delete the stack so CloudFormation lets go without deleting anything. Add import blocks for each resource and check that terraform plan shows no changes.
What happens to Parameters and Outputs?
Parameters become Terraform variable blocks, keeping defaults and allowed values where possible (as validation rules). Outputs become output blocks that reference the new resources.
Can it convert SAM templates?
The converter works best on plain CloudFormation. For SAM or other transforms, download the processed template, which contains the expanded resources, and convert that instead.
Does it support YAML templates?
This page expects JSON. For YAML templates with short-form tags like !Ref, use the CloudFormation YAML to Terraform converter.