Skip to content

bendbennett/aws-ansible-cloudformation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible - AWS CloudFormation

This repo contains Ansible code and AWS CloudFormation templates for the provisioning of AWS resources.

A Symfony 3 API is used to illustrate how a web application which can be run within a Docker-based local development environment can be set-up to run on AWS.

Requirements

S3

Register domain name

HTTPS

Key name

  • Uncomment key_name in group_vars/site/main.yml and insert the name of the EC2 key pair that you want to use to connect to the EC2 instances.

Provision network and site

git clone git@github.com:bendbennett/ansible-aws.git
cd ansible-aws/cloud-formation
ansible-playbook basic-network.yml
ansible-playbook site.yml 

Remove network and site

cd ansible-aws/cloud-formation
ansible-playbook site-down.yml
ansible-playbook basic-network-down.yml

Basic Network

Running ansible-playbook basic-network.yml runs each of the roles specified in the basic-network playbook using the variables defined in group_vars/basic-network/main.yml and will provision:

VPC

  • Creates a Virtual Private Cloud (VPC) / virtual network with the CIDR block specified.
  • Creates an Internet Gateway and attaches it to the VPC using an Internet Gateway Attachment to allow communication with the internet.

Network ACL

  • Creates a Network Access Control List (ACL) and Network ACL Entries for ingress and egress as an optional security layer for controlling traffic into and out of subnets.

Route Table - public

  • Creates a Route Table and Route linked to the Internet Gateway.

Subnet - public

  • Creates 3 public Subnet(s) using the specified CIDR blocks, Network ACL and Route Table (public), placing 1 in each of 3 availability zones.

Route Table - private

  • Creates 3 Route Table(s), 3 Elastic IP(s) and 3 NAT Gateway(s)

Subnet - private

  • Creates 3 private Subnet(s) using the specified CIDR blocks, Network ACL and Route Table (private) placing 1 in each of 3 availability zones.

Hosted Zone - private

  • Creates a private Hosted Zone for holding record sets.

Site

Running ansible-playbook site.yml runs each of the roles specified in the site playbook using the variables defined in group_vars/site/main.yml and will provision:

Security Group - load balancer

  • Creates a Security Group for use with the Load Balancer.

Load Balancer

  • Creates a Load Balancer for HTTP requests directed at the API.

Security Group - web (nginx / php-fpm)

  • Creates a Security Group for use with EC2 instances that will be running nginx and php-fpm containers.

Security Group - mongo

  • Creates a Security Group for use with EC2 instances that will be running mongo containers.

IAM Role - Launch Configuration

  • Creates an IAM Role for use with Launch Configurations used in the set-up of EC2 instances that host containers (web + mongo).

IAM Instance Profile

  • Creates an IAM Instance Profile for associating IAM Role with a Launch Configuration.

IAM Role

  • Creates an IAM Role to provide privileges to an ECS Service associated with the Load Balancer.

Log Group

  • Creates a Log Group for use by containers defined in Task Definitions.

ECS Cluster - mongo

  • Creates an ECS Cluster for associating with ECS Service for EC2 instances running MongoDB containers.

Launch Configuration + Auto Scaling Group - mongo

  • Creates Launch Configuration to define EC2 instances used for hosting MongoDB containers and an Auto Scaling Group to define instance number.

Task Definition + Service - mongo

  • Creates an ECS Task Definition which defines the container and configuration that will be deployed and an ECS Service which defines the desired number of containers and the cluster that they will be deployed on.

ECS Cluster - web (nginx / php-fpm)

  • Creates an ECS Cluster for associating with ECS Service for EC2 instances running nginx and php-fpm containers.

Launch Configuration + Auto Scaling Group - web (nginx / php-fpm)

  • Creates Launch Configuration to define EC2 instances used for hosting nginx and php-fpm containers and an Auto Scaling Group to define instance number.

Task Definition + Service - web (nginx / php-fpm)

  • Creates an ECS Task Definition which defines the containers and configuration that will be deployed and an ECS Service which defines the desired number of containers and the cluster that they will be deployed on.

Record Set

  • Creates a DNS entry within Route 53 for the API.