Use AWS and Terraform to deploy a two-tier architecture and create a diagram.
Scenario: Your team needs you to diagram and deploy a two-tier architecture for your company. For the foundational project, you are allowed to have all your code in a single main.tf (known as a monolith) with hardcoded data. You may have just asked yourself: “What exactly is a monolith?” For this project, a monolith a type of architecture.
A monolith or monolithic architecture consists of all the dependencies in a single program. It comprises of several single platform components to properly function the complete server. {For additional information, please visit: https://www.geeksforgeeks.org/what-is-a-monolith-server/}
Tasks:
I. Deploy a VPC with CIDR 10.0.0.0/16 with 2 public subnets with CIDR 10.0.1.0/24 and 10.0.2.0/24. Each public subnet should be in a different AZ (Availability Zone) for high availability.
II. Create 2 private subnet with CIDR ’10.0.3.0/24 and ’10.0.4.0/24’ with an RDS MySQL instance (micro) in one of the subnets. Each private subnet should be in a different AZ.
III. A load balancer that will direct traffic to the public subnets.
IV. Deploy 1x EC2 t2.micro instance in each public subnet.
Must haves:
I. AWS account: Personal or Business
II. Infrastructure as Code {IaC} tool: I selected HashiCorp Terraform which lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share.
III. Code editor: Visual Studio Code (VS Code) is a streamlined code editor with support for development operations like debugging, task running, and version control.
IV. Terraform CLI (Command line interface)
V. AWS CLI (Command line interface)
Should have:
I. VS Code Extensions: VS Code extensions let you add languages, debuggers, and tools to your installation to support your development workflow. For example: AWS Toolkit, HashiCorp Terraform, Terraform Advanced Syntax Highlighting to name a few.
Now that we have the basic requirements, let us begin… oh and I used a computer running Windows 10, so the commands may be different if you are performing this project on a computer with a different OS (Operating System).
- Launch VS Code and open/create folder/directory to contain your project.
- Create a new file and name it main.tf this will be the primary file, which will contain the entire program and dependencies.
- The first entries will contain the Terraform configuration information: Required providers and the main provider.
4. Save the changes (Windows: Ctrl+S)
5. Confirm that the data is correct in the Terraform configuration block
6. Open a new terminal within VS Code (Ctrl+shift+` keys)
7. Enter Terraform init {Initializes the working directory to prepare usage and other commands}
8. If desired, enter Terraform plan otherwise begin entering the rest of your code.
a. Terraform plan (command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. By default, when Terraform creates a plan)
b. Terraform apply would be the next step, however, I decided to continue entering the remaining code. So, lets had back to the coding process
c. Next, is the coding for the VPC and its components:
- Create a VPC (Virtual Private Cloud) which provides AWS resources to launch a virtual network. Default IP CIDR block: 10.0.0.0/16
2. Create 2x Public Subnets: IP CIDR blocks: 10.0.1.0/24 and 10.0.2.0/24 and 2x Availability Zones (us-east-1a and us-east-1b
3. Create 2x Private Subnets, IP CIDR blocks: 10.0.3.0/24, 0.0.4.0/24 and two Availability Zones (us-east-1c and us-east-1d)
4. Create Internet Gateway
5. Create Route Table, Route, and Route Table association
6. Create Security Group, ingress, and egress
7. Create AWS AMI Ubuntu Server
8. Create EC2 and components
9. Create ALB (Application Load Balancer) and components
10. Create RDS MySQL Database and components
11. Enter: Terraform fmt {Terraform command to rewrite the configuration file(s) to a canonical format and style.
12. Enter: Terraform apply -auto-apply, you can enter -auto-apply during development testing, it sets a Yes indicator so that you will not be prompted during the processing.
Figure 5 Successfully spun up a two-tier architecture, consisting of 2x AWS EC2 instances, an application load balancer, a RDS MySQL database and all supporting components.
13. If you or your company utilize a version control system with repositories, then you may want to add it to a folder there for version control. I utilize GitHub, please reference one of these links for more information {GitHub — Wikipedia) or (https://github.com/)