# Virtual Private Cloud Architecture on AWS using Terraform

# Virtual Private Cloud Architecture on AWS using Terraform

## 🚀 Overview:

The VPC Architecture project 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. The primary objective of this project is to design and deploy a virtual Private Cloud or Networking architecture on AWS that consists of multiple components, including basement, networking, traffic flow. All components will be deployed across two Availability Zones (AZs) for high availability and fault tolerance.

## 🔧 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.

## 💽 Techonology Stack

The architecture consists of the following three tiers:

* **VPC**: AWS VPC
    
* **Subnets**: AWS Subnets
    
* **Route table**: AWS route table
    
* **NACL**: AWS NACL
    
* **Internet Gateway**: AWS IGW
    

## 📌 Architecture Diagram

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055442112/e3dde262-6f54-4a4f-ab3f-333fd65519c2.png align="center")

## 🌟 Project Requirements

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

* [Terraform](https://www.terraform.io/) 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](https://www.github.com/)
    
* Git for cloning the repository.
    

You must also know Terraform workflow

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055468795/5726d060-0df2-404e-a0b1-3ce1889018ac.jpeg align="center")

## 📋 Table of Contents

I - **Terraform Configuration files**

[Step 1: Provider Configuration](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Provider-configuration)

[Step 2: Variables Configuration](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-variables-configuration)

[Step 3: VPC Configuration](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-VPC-configuration)

[Step 4: Output Configuration](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Output-configuration)

II - **Instructions of Deployment**

[Step 5: Clone Repository](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Clone-Repository)

[Step 6: Initialize Folder](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Initialize-Folder)

[Step 7: Format Files](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Format-Files)

[Step 8: Validate Files](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Validate-Files)

[Step 9: Plan](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Plan)

[Step 10: Apply](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Apply)

[Step 11: Review of Resources](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Review-Of-Resources)

[Step 12: Destroy](http://127.0.0.1:8000/vpc-foundation-terraform-on-aws/#-Destroy)

## ✨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

* [provider Configuration](https://github.com/Joebaho/Joebaho-Cloud-Platform/blob/main/site/vpc-foundation-terraform-on-aws/providers.tf)
    

##### 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

* [variables Configuration](https://github.com/Joebaho/Joebaho-Cloud-Platform/blob/main/site/vpc-foundation-terraform-on-aws/variables.tf)
    
* [value Configuration](https://github.com/Joebaho/Joebaho-Cloud-Platform/blob/main/site/vpc-foundation-terraform-on-aws/terraform.tfvars)
    

##### Step 3: ***VPC Configuration***

This is where you create the basement, foundation and networking where all the resources will be launch. It includes VPC, Subnets, IGW, NatGateway, EIP and Route tables

* [VPC Configuration](https://github.com/Joebaho/Joebaho-Cloud-Platform/blob/main/site/vpc-foundation-terraform-on-aws/main.tf)
    

We have here

* **VPC**: Virtual Private Cloud the main and private environment where all resources will be launch
    
* **Subnets**: is a segmented portion of a virtual private cloud (VPC) that allows you to partition your network resources. Subnets are used to organize and manage your cloud resources more effectively by providing isolation and control over network traffic.
    
* **Internet Gateway**: it plays a crucial role in enabling internet connectivity for resources within a VPC, allowing instances to access services, applications, and data hosted on the public internet while providing scalability, redundancy, and security features.
    
* **Route Tables**: is a fundamental networking component that controls the routing of network traffic within a Virtual Private Cloud (VPC). Route tables define the rules for directing traffic from one subnet to another or to external networks, such as the internet or on-premises networks.
    
* **NCAL**: Network Access Control Lists (NACLs) are a security layer in AWS that act as a firewall for controlling traffic in and out of one or more subnets within a Virtual Private Cloud (VPC).
    
* **Security Groups**: a security group acts as a virtual firewall for controlling inbound and outbound traffic to AWS resources, such as EC2 instances, RDS databases, and other services within a Virtual Private Cloud (VPC). Security groups allow you to define rules that specify the type of traffic allowed or denied based on protocols, ports, and IP addresses.
    

##### 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 ARN, name or ID of a resource. In this case we are bringing out the DNS name of the web application Load balancer.

* [Output Configuration](https://github.com/Joebaho/Joebaho-Cloud-Platform/blob/main/site/vpc-foundation-terraform-on-aws/outputs.tf)
    

## 💼 Instructions of Deployment

Follow these steps to deploy the architecture:

##### Step 5: ***Clone Repository:***

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

> git clone https://github.com/Joebaho/Joebaho-Cloud-Platform/tree/main/site/vpc-foundation-terraform-on-aws

##### Step 6: ***Initialize Folder***

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

> terraform init

You must see this image

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055540427/852269b8-34b2-425b-9d9b-7648a56da1ed.jpeg align="center")

##### Step 7: ***Format Files***

Apply any changes on files and Review the changes and confirm the good format with command:

> terraform fmt

##### Step 8: ***Validate Files***

Ensure that every files are syntactically valid and ready to go with the command:

> terraform validate

If everything is good you will have something like this

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055565642/c49c36e5-2914-4bdf-9243-f04edd658445.jpeg align="center")

##### Step 9: ***Plan***

Create an execution plan to provide the achievement of the desired state. It Check and confirm the numbers of resources that will be create. Use command:

> terraform plan

The list of all resources in stage of creation will appear and you can see all properties(arguments and attributs) of each resources

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055597147/1cb0fc0e-ad72-4c4e-8804-0582d9af8c5b.jpeg align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055611261/449a461a-13e2-46b4-a672-09f196e63b48.jpeg align="center")

##### Step 10: ***Apply***

Bring all desired state resources on life. It Launch and create all resources listed in the configuration files. The command to perform the task is:

> terraform apply -auto-approve

Now, the creation will start and you will be able to see which resources is on the way to be create and the time it taking to create.

At the end you will receive a prompt message showing all resources status: created, changed and the numbers of them.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055649673/365f8b98-675a-4c6a-bb23-5af4a48c1680.jpeg align="center")

Here are the outputs :

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055882756/9f471f80-9478-4d89-a3d6-7dac593efe48.jpeg align="center")

##### Step 11: ***Review of resources***

Go back on the console and check all actual state resources one by one to see. You will have

* **VPC**
    

* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055683892/fd1d2833-ff24-4f45-9f87-0732952d8f03.jpeg align="center")
    
    **Subnets**
    

* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055711140/a4eeda54-9584-405a-8f92-7ba16de017f8.jpeg align="center")
    
* **IGW**
    

* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055730741/44710587-f727-4849-b845-937167481869.jpeg align="center")
    
* **Route Tables**
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055760199/0df6c37c-87e0-4037-968c-9aa284760dce.jpeg align="center")
    
* **NCAL**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055781416/013d9279-d6a3-4461-bee4-020d6abbc537.jpeg align="center")

##### Step 12: ***Destroy***

Destroy the terraform managed infrastructure meaning all resources created will be shut down. This action can be done with the command "terraform destroy"

> terraform destroy -auto-approve

At the end you will receive a prompt message showing all resources has been destroyed

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055802172/6848c990-64a8-4842-85b4-e29f67c800c6.jpeg align="center")

## 🤝 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
