Loading converter...

How to Convert Ansible Playbook to Terraform - Step by Step Guide

Step 1

Prepare Your Ansible Playbook

Open your Ansible playbook file (typically with .yml or .yaml extension). The converter focuses on infrastructure provisioning tasks using cloud provider modules like amazon.aws.ec2, azure.azcollection.azure_rm_virtualmachine, or google.cloud.gcp_compute_instance. Collection names are matched by their last part, so amazon.aws.ec2_instance and ec2_instance both work. Copy the contents of your playbook.

•
Infrastructure focus: The converter works best with infrastructure provisioning tasks, not configuration management
•
Cloud providers: A fixed set of AWS, Azure, and GCP modules for compute, network, storage, IAM and databases is recognised (the FAQ below lists them); other tasks are skipped
•
Try the sample: Click "Sample" to see how an EC2 provisioning playbook converts to Terraform
Step 2

Paste and Convert

Paste your Ansible playbook YAML into the left editor panel. The HCL shows up on the right a moment after you stop typing; there is no button to press. Ansible variables become Terraform variables, and the common arguments of each recognised module become resource arguments.

•
Module mapping: Ansible modules like amazon.aws.ec2_instance are converted to aws_instance resources
•
Variables: Ansible variables become Terraform input variables whose type is taken from the value (string, number, bool, list or map, or any for mixed data)
•
Templates and loops: Jinja expressions such as {{ region }} are kept as quoted text, and loops are not translated, so swap them for var.region, count or for_each yourself
Step 3

Review and Refine

Examine the generated Terraform HCL code in the right panel. The conversion is a starting point—you'll need to review and adjust for your specific use case. Ansible's imperative style and Terraform's declarative style differ significantly, so manual refinement is typically needed.

•
Conditionals: Ansible's when conditions may need manual conversion to Terraform's count or dynamic blocks
•
State management: Unlike Ansible, Terraform maintains state—plan your state backend configuration
•
Dependencies: Explicit resource dependencies may need to be added using depends_on
Step 4

Download and Initialize

Download the converted Terraform configuration and save it as main.tf. Run terraform init to initialize the working directory and download required providers. Use terraform plan to preview changes before applying.

•
Provider configuration: Add proper provider blocks with authentication credentials (use environment variables or AWS profiles)
•
Validate syntax: Run terraform validate to check for syntax errors
•
Test safely: Always use a dev/test environment first before running in production

Frequently Asked Questions

Which Ansible modules does it turn into Terraform resources?

A short, fixed list of cloud modules: ec2 and ec2_instance (aws_instance), ec2_security_group and ec2_group, ec2_vpc_net, ec2_vpc_subnet, s3_bucket and aws_s3, iam_role, iam_policy, iam_user, rds and rds_instance, lambda, the azure_rm virtual machine, resource group, storage account and virtual network modules, and gcp_compute_instance, gcp_compute_network and gcp_storage_bucket. Collection names such as amazon.aws.ec2_instance are matched by their last part. Only the common arguments are carried over, so expect to fill in the rest.

What happens to tasks like apt, copy, template or shell?

They are skipped. Those tasks configure a server rather than create infrastructure, and Terraform has no direct equivalent for them. If nothing in the playbook matches the list above, the output says that no convertible resources were found and only the variables are written.

Are Jinja expressions like {{ region }} turned into Terraform references?

No. They are copied into the HCL as ordinary quoted text, so "{{ region }}" stays a string. Replace each one with the matching reference, for example var.region, before you run terraform plan. Loops, when conditions and handlers are not translated either; the checklist at the end of the output reminds you of them.

Will long IDs, zip codes or prices change on the way through?

No. Numbers are written with the text you typed, so 8901240544102066246 and 14.50 come out exactly as they were, and a value with leading zeros such as 00501 is written as the string "00501". Quotes, backslashes and line breaks inside strings are escaped, and ${ or %{ is written as $${ or %%{ so Terraform does not try to interpolate it. Database passwords are never copied; you get a comment telling you to set them from a variable instead.

Can I paste a role tasks file or a vars file instead of a full playbook?

Yes. A list of tasks without hosts is read as tasks, and a plain map of keys and values is read as variables, so a role tasks/main.yml or a group_vars file both work. Roles listed inside a play are only named in a comment, because their tasks live in other files.

Is my playbook sent anywhere?

No. The conversion runs in your browser and nothing is uploaded or kept, so reloading the page starts you off with an empty editor.