✨ This repository is created to learn and deploy a 3-tier application on aws cloud through Terraform.
Create one file with the name terraform.tfvars
vim terraform.tfvars
To use ACM certificate, go to AWS management console --> AWS Certificate Manager (ACM) and make sure you have a valid certificate in Issued status, if not, feel free to create one and use the domain name on which you are planning to host your application (Not Mandatory).
To user Route 53 hosted zone, go to AWS management console --> Route53 --> Hosted Zones and ensure you have a public hosted zone available, if not create one (Not Mandatory).
In order to initiate AWS EC2 instance you need to have a key pair (public and private key). So remove any key (my-key.pem
, my-key.pub
) in following directory ./modules/key/*
then recreate your own keys using following command:
$ cd ./modules/key
$ ssh-keygen -t rsa -b 4096 -f ./my-key.pem
$ mv my-key.pem.pub my-key.pub
Add the below content into the terraform.tfvars
file and add the values of each variable.
region = ""
project_name = ""
vpc_cidr = ""
pub_sub_1a_cidr = ""
pub_sub_2b_cidr = ""
pri_sub_3a_cidr = ""
pri_sub_4b_cidr = ""
pri_sub_5a_cidr = ""
pri_sub_6b_cidr = ""
db_username = ""
db_password = ""
certificate_domain_name = ""
additional_domain_name = ""
bucket_name = ""
After completing above steps make sure you have enable route53 resource ./modules/route53/main.tf
, cloudfront acm certificate and aliases ./modules/cloudfront/main.tf
. Finally, make changes to auto scaling group ./modules/asg/config.sh
accordingly to deploy your application on following aws 3 tier architecture.
👉 Let install dependency to deploy the application
terraform init
Type the below command to see the plan of the execution
terraform plan
✨ Finally, HIT the below command to deploy the application
terraform apply
Type yes
, and it will prompt you for approval.
In order to automate the task and start the CI/CD pipeline, you will need a dedicated EC2 instance configured as a self-hosted runner in GitHub Actions. Set it up by registering the instance as a new self-hosted runner in your repository's GitHub Actions settings then name the runner as git-workflow
as shown below. Please make sure to attach a suitable role with necessory permission to this instance while laungching or through Instances --> Actions --> Security --> Modify IAM role.
Note
If you not aware or doing this type of work in first time, please refer my terraform-aws-2-tier-architecture --> Steps to setup CICD Pipeline
To receive pipeline deployment notifications, configure your Slack channel's webhook URL. Add this webhook URL as a repository secret in GitHub Actions --> Secrets and Variables --> Repository secrets, and name it SLACK_WEBHOOK_URL
.
Upon successful execution, the pipeline will deploy a fully functional application in a 3-Tier Architecture on AWS Cloud.