This repository contains various examples of integrating Terraform with Ansible for infrastructure provisioning and configuration management. The examples demonstrate different approaches to using these tools together in AWS environments.
The repository is organized into several directories, each containing a different example or configuration:
- terraform-ansible-provider
- terraform-ansible-seperate-orchectrator
- terraform-ansible-ssh
- terraform-ansible-ssh-amz-linux
- terraform-ansible-ssm
- terraform-ansible-ssm-ubuntu-amz-linux-role
Each directory contains Terraform configurations, Ansible playbooks, and other necessary files for the specific integration approach.
- AWS EC2 instance provisioning using Terraform
- Ansible playbook execution for configuration management
- Various methods of connecting Ansible to EC2 instances:
- SSH
- AWS Systems Manager (SSM)
- Ansible AWS provider
- Support for both Ubuntu and Amazon Linux 2 AMIs
- IAM role and instance profile creation for EC2 instances
- S3 bucket creation for Ansible SSM integration
- Terraform (version 1.7.5 or later)
- Ansible (latest version recommended)
- AWS CLI configured with appropriate credentials
- Basic knowledge of Terraform, Ansible, and AWS services
To use any of the examples:
- Navigate to the desired example directory
- Initialize Terraform:
terraform init
- Review and modify the
main.tf
file as needed - Apply the Terraform configuration:
terraform apply
- For examples using separate Ansible execution, run the Ansible playbook after Terraform completes:
ansible-playbook -i <inventory> <playbook.yml>
-
terraform-ansible-provider: Uses the Terraform Ansible provider to execute Ansible playbooks directly from Terraform.
-
terraform-ansible-seperate-orchectrator: Demonstrates using Terraform for provisioning and Ansible as a separate orchestrator for configuration.
-
terraform-ansible-ssh: Configures EC2 instances for SSH access and uses Ansible over SSH for configuration.
-
terraform-ansible-ssh-amz-linux: Similar to the SSH example, but specifically for Amazon Linux 2 instances.
-
terraform-ansible-ssm: Utilizes AWS Systems Manager (SSM) for executing Ansible playbooks on EC2 instances.
-
terraform-ansible-ssm-ubuntu-amz-linux-role: Extends the SSM example to support both Ubuntu and Amazon Linux 2, with role-based configurations.
- Ensure proper AWS credentials are set up before running the examples.
- Review and adjust security group settings in the Terraform configurations as needed.
- Some examples use local-exec provisioners, which may require additional setup on your local machine.
Contributions to improve the examples or add new integration methods are welcome. Please submit a pull request with your changes.
This project is licensed under the terms of the license included in the repository.