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. Copy the contents of your playbook.

Infrastructure focus: The converter works best with infrastructure provisioning tasks, not configuration management
Cloud providers: Supports AWS, Azure, and GCP Ansible modules for creating compute, network, and storage resources
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 converter parses Ansible tasks and maps cloud provider modules to equivalent Terraform resources. Click "Convert to Terraform" to generate HCL code. Ansible variables are converted to Terraform variables, and task parameters become resource arguments.

Module mapping: Ansible modules like amazon.aws.ec2 are converted to aws_instance resources
Variables: Ansible variables are converted to Terraform input variables with appropriate types
Loops: Simple Ansible loops are converted to Terraform count or for_each expressions where possible
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