This is example scenario shows web application running on 3 EC2 instances fronted by an Elastic LoadBalancer (ELB). Each instance is deployed in its own Availability Zone inside the same VPC. The application is simple python webserver serving a static page with some html elements. The purpose is focused on infrastructure as code. If a ec2 instance with the app goes down the application should still be available.
Required Tools
* [Git](https://git-scm.com/) - SCM
* [Python3](https://python.org/) - Python 3 for Deployment Script
* [Terraform](https://www.terraform.io/) - Write, Plan, and Create Infrastructure as Code
* [AWS](https://aws.amazon.com/) - Cloud Provider for Infrastructure
This terraform will build Infrastructure on AWS using terraform. Make sure to supply
correct credentials and correct variables in your own terraform.tfvars
file.
- Note: This Terraform project will create at the most 6 ec2 instances t2.micro, nat-gateway, Subnets, Volumes etc. I am not liable for any charges that may occur on your AWS account
Create a new User in AWS IAM dashboard. Unless you already have User with this access.
- Be sure to add 'Programmatic Access' to the user.
Add permissions to new user for.
- Select 'Attach Existing Policies Directly'
Add these:
- AmazonEC2FullAccess
- AmazonRoute53FullAccess
- AmazonIAMFullAccess
- Create a KeyPair, ApiKey in AWS.
- Clone this repo.
git clone https://github.com/mattnidz/IACPlatform.git
cd IACPlatform
- Create
terraform.tfvars
file of your own. This file can be used to override default settings. Fill out similar to this with your credentials.
ami = "ami-011b3ccf1bd6db744" key_name = "" region = "us-east-1" access_key = "" secret_key = ""
Initialize the Terraform AWS Provider.
terraform init
First Plan Terraform IAC (Infrastructure as Code).
terraform plan
Apply Terraform Infrastructure on AWS. This is the building part!
terraform apply
You may be prompted for region. You can enter us-east-1. Also another prompt if you would like to continue.
Once the terraform completes you should see some output.
App Console External URL = http://app-xxxx-console-xxxxx.elb.us-east-1.amazonaws.com:8443
The App Console External URL should be reliable in the case of one ec2 instance going down.
You can test by stopping an ec2 in the AWS ec2 dashboard.
If everything works correctly the application located at http://app-xxxx-console-xxxxx.elb.us-east-1.amazonaws.com:8443
will be loadbalanced and therefore should still reached.
The Python3 script in this project will change the AMI in the terraform.tfvars
file for you.
This script is just an example how Automation could be used to automate these deployments in CICD DevOps processes.
The script will look for ami-0394fe9914b475c53
in terraform.tfvars and switch it to ami-0394fe9914b475c53
.
- Note: Running this will and attempt to run
terraform apply
auto-approve in an automated fashion.
Example:
python deploy.py ami-0394fe9914b475c53 ami-011b3ccf1bd6db744
Here is the visual dependency graph of Terraform resources according to configuration files.
To destroy all resources created.
terraform destroy
- Git - SCM
- Python3 - Python 3 for Deployment Script
- Terraform - Write, Plan, and Create Infrastructure as Code
- AWS - Cloud Provider for Infrastructure
- RedHat - OS of choic for Ec2 instances
#TODO: Please read [CONTRIBUTING.md] for details on our code of conduct, and the process for submitting pull requests to us.
- Matthew Nidzgorski - Initial work - Github - Matt Nidzgorski
see the LICENSE.md file for details
- Inspired by work done here https://github.com/jkwong888/terraform-icp-aws
- Thanks