Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

AWS Terraform Ansible Playbook and Docker Compose Sample Application

License

Notifications You must be signed in to change notification settings

saidsef/aws-terraform-ansible-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Terraform Help

Prerequisite:

Make sure the following applications are installed and are set in the enviromental path:

  • AWS CLI >= 1.10
  • Terraform >= 0.7.5
  • Ansible >= 2.1.2.0

Export your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables, and run aws configure to complete setup:

export AWS_ACCESS_KEY_ID=<access-key>
export AWS_SECRET_ACCESS_KEY=<secret-key>

Also, update public_key variable with your public ssh key, the file is located at terraform-aws/variables.tf

Assumptions

This will run in Amazon AWS region eu-west-1, and you will only need AZA and AZB ;)

AWS resources

This application will create the following resources:

  • VPC
  • Routing
  • Subnets
  • Internet Gateway
  • Security Groups
  • Elatic Loadbalance
  • Launch Configuration
  • Autoscaling Groups
  • EC2 Key
  • EC2 Instance(s)

Note: Some of these resource will incur a charge

Files and Directories:

├── ansible
│   ├── hosts.template
│   ├── playbook.retry
│   └── playbook.yml
├── cloud-automation.sh
├── docker
│   └── docker-compose.yml
├── ips_to_file.py
├── LICENSE.md
├── nginx
│   ├── nginx.conf
│   └── proxy.conf
├── README.md
└── terraform-aws
    ├── modules
    │   ├── app_sg
    │   │   ├── main.tf
    │   │   └── variables.tf
    │   ├── asg
    │   │   ├── main.tf
    │   │   └── variables.tf
    │   ├── ec2key
    │   │   ├── main.tf
    │   │   └── variables.tf
    │   ├── elb
    │   │   ├── main.tf
    │   │   └── variables.tf
    │   ├── elb_sg
    │   │   ├── main.tf
    │   │   └── variables.tf
    │   ├── ssh_sg
    │   │   ├── main.tf
    │   │   └── variables.tf
    │   └── vpc_subnets
    │       ├── main.tf
    │       └── variables.tf
    ├── outputs.tf
    ├── site.tf
    ├── userdata.sh
    └── variables.tf

Getting started

To run the application, simply execute the following command:

./cloud-automation.sh web dev 1 t2.nano

Tools Used:

Terraform: To compile, test, run and destroy,

terraform validate
terraform get
terraform plan
terraform graph
terraform apply
terraform show
terraform destroy

Terraform will create all the resources in AWS, you can then use ansible-playbook to deploy applications and docker compose.

Ansible playbook: To run:

ansible-playbook -i hosts playbook.yml

Note: Terraform stores the state of the managed infrastructure from the last time Terraform was run. Terraform uses the state to create plans and make changes to the infrastructure.