Skip to main content

Command Palette

Search for a command to run...

Web Application Deployment on AWS Using Terraform, NGINX and Bash Scripting

Updated
β€’6 min read
Web Application Deployment on AWS Using Terraform, NGINX and Bash Scripting
J

My name is Joseph Mbatchou, and I am grateful for the opportunity to introduce myself to you.

I have been in the Tech industry for about 8 years, and I am currently performing as Cloud Engineer at CloudSpace Consulting, LLC Manassas, VA.

My journey began as a Computer Science Teacher and Computer Technician at Biopharcam, a computer sales company in my home country. Upon relocating to the United States, I joined Allied Universal, gradually advancing from an officer to a shift lead position. In this role, I oversaw various applications for training and operational tasks, collaborating closely with engineers and developers from Digital Realty, a data center provider.

Observing these professionals at work sparked my interest in cloud computing, leading me to pursue cloud classes, attend boot camps, and conduct in-depth research across various domains, including training at CloudSpace Academy. This exposure deepened my passion for IT and motivated me to transition into the industry to further my personal growth and contribute to organizational success.

As a Cloud Consultant, I have been privileged to collaborate with Cloud Solution Architects and DevOps teams on numerous projects, consistently exceeding customer expectations through our dedication and innovative solutions. My tenure in this role has enriched my skill set and broadened my professional experience.

Now, equipped with a wealth of knowledge in cloud computing and DevOps practices, I am eager to apply my expertise to new challenges and opportunities. I am confident in my ability to contribute effectively to your knowledge

Thank you for considering my hard work. I look forward to have you on board of the learning process.

Web Application Deployment on AWS Using Terraform, NGINX and Bash Scripting

πŸš€ Overview:

The building of the infrastructure and deploy of a web page on AWS using Terraform aims to create a scalable and resilient infrastructure that leverages the power of Amazon Web Services (AWS) cloud platform. This project utilizes Terraform, an Infrastructure as Code (IaC) tool, to provision and manage the infrastructure components, enabling automation, repeatability, and scalability. This project demonstrates how to provision, deploy and destroy infrastructure on AWS using Terraform and automate the deployment with bash Scripting. A deployment script (deploy.sh) and a destroy script (destroy.sh) are use for the automation process. It’s a hands-on DevOps project showing Infrastructure as Code (IaC) and automation.

πŸ”§ Problem Statement

Terraform is an IaC software tool that provides a consistent command line interface (CLI) workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files. In this specific case you need to create foundation Networking(VPC, Subnets, route table, IGW, NAT Gateway...), Terraform will automatically use the configuration files to provide the infrastructure resources where we can run application needed. Terraform will use his deployment to provide all AWS needed elements avoiding us to use the console and it will automate the setup, ensuring consistency and reducing human error. The bash scripting and the other hands will facilitate the deploy by simply automating the process.

πŸ’½ Techonology Stack

The architecture consists of the following three tiers:

  • AWS VPC: AWS VPC

  • Subnets: AWS Subnets

  • Route table: AWS route table

  • NACL: AWS NACL

  • Internet Gateway: AWS IGW

  • Elastic Load Balancer: AWS ELB

πŸ“Œ Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Developers β”‚ β”‚ Push Code to GitHub β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Terraform Configuration files β”‚

- main.tf

- providers.tf

- variables.tf

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Bash Scripting β”‚

- Deploy.sh

- Destroy.sh

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ NGINX β”‚

- Install and configuration

- Copy index.html

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Elastic Load Balancerβ”‚

- Distributes traffic

- Performs health checks

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ End Users β”‚ β”‚ Access via ELB DNS NAME β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🌟 Project Requirements

Before you get started, make sure you have the following prerequisites in place:

  • Terraform installed on your local machine.

  • AWS IAM credentials configured in your text editor. In this case we will use VSCODE.

  • Git installed on your local machine and Github account set up Github

  • Git for cloning the repository.

You must also know Terraform workflow

πŸ“‹ Table of Contents

I - Terraform Configuration files

Step 1: Provider Configuration

Step 2: Variables Configuration

Step 3: Main Configuration

Step 4: Output Configuration

Step 5: User-data

II - Scripting files

Step 6: Deploy file

Step 7: Destroy file

III - Instructions of Deployment

Step 8: Clone Repository

Step 9: Run Deployment

Step 10: Destroy Infrastructure

✨Terraform Configuration files

You need to write different files generating resources

Step 1: Provider Configuration

Here we declare our cloud provider and we specify the region where we will be launching resources

Step 2: Variables Configuration

This is where we declare all variables and their value. It includes

  • Variables: List of element that can vary or change. They can be reuse values throughout our code without repeating ourselves and help make the code dynamic

  • values: values attributed to each variables.

We have

Step 3: Main Configuration

This is where you create the basement, foundation and networking where all the resources will be launch. It includes VPC, Subnets, IGW, Route tables, Security groups, EC2 instances, Targets group and Elastic load balancer

Step 4: Output Configuration

Know as Output Value : it is a convenient way to get useful information about your infrastructure printed on the CLI. It is showing the DNS name of the load balancer and public IP of the instances.

Step 5: User-data

user data is a script or custom data that you provide to an EC2 instance to be executed automatically on its first launch. It's used to automate the initial setup of an instance, such as installing software, configuring settings, or running commands needed to make the instance ready for use. In our case the user data will update the server, install Nginx and copy the index.html file to the correspondant folder.

✨Bash Scripting files

You need to write different bash script files generating and destroying resources. The file will contains all step by step meaning all terraform command for the execution of the process.

Step 6: Deploy file

Here we declare the initialization of the folder, the validation of the configuration, the plan of resources to be create and apply of the execution where we will be launching resources.

Step 7: Destroy file

This is where we declare the terraform command to destroy all the resources created.

πŸ’Ό Instructions of Deployment

Follow these steps to deploy the architecture:

Step 8: Clone Repository:

Clone the repository in your local machine using the command "git clone" then enter the folder

git clone https://github.com/Joebaho/Flipkart-Deploy.git

cd Flipkart-Deploy

Step 9: Run Deployment

Initialize the folder containing configuration files that were clone to Terraform and apply the configuration by typing the following command

chmod +x deploy.sh

./deploy.sh

The process will execute all terraform command and display the following steps. You must see this image

Terraform init: Initialize the folder

Terraform fmt & validate: Check for any syntax error and valid the status of the configuration files

Terraform plan: confirm the numbers of resources that will be create

Terraform apply: confirm all resources created

Terraform output: show all the output information to be use by user.

After copy the ELB dns name in the output section you can go paste that in a new window on the browser and the web page will display.

Step 10: Destroy infrastructure

After you are done with the infrastructure and you are ready to destroy you can run the command. First you make the file executable then you apply execution.

chmod +x destroy.sh

./destroy.sh

After typing or pasting the command you will get images

You will need to confirm the destruction of the deployment. Then all the 16 resources created before will be destroyed.

πŸ“Œ Learning Outcomes

  • Understand Terraform basics (providers, resources, state management)

  • Automate deployments with Shell scripting

  • Hands-on AWS infrastructure provisioning


πŸ”— Resources

🀝 Contributing

Your perspective is valuable! Whether you see potential for improvement or appreciate what's already here, your contributions are welcomed and appreciated. Thank you for considering joining us in making this project even better. Feel free to follow me for updates on this project and others, and to explore opportunities for collaboration. Together, we can create something amazing!

πŸ“„ License

This project is licensed under the JoebahoCloud License

More from this blog

Joseph Mbatchou Cloud Platform

13 posts

My name is Joseph Mbatchou, and I am grateful for the opportunity to introduce myself to you. I have been in the Tech industry for about 8 years, and I am currently performing as Cloud Engineer.