# Static web site hosting on S3 using Terraform

# Static web site hosting on S3 using Terraform

## 🚀 Overview:

The Static web site project on AWS using Terraform aims to create a scalable and resilient web static site hosted on S3 which is an Amazon Web Services (AWS) cloud platform. This project utilizes Terraform, an Infrastructure as Code (IaC) tool, to provision and manage the S3 bucket with all the parameters that will make it publicly accessible. The goal of this project is to design and deploy a web site host on S3 that will include all necessary components of the S3 bucket.

## 🔧 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 S3 bucket that will host a static web site. Terraform will use this deployment to provide all needed S3 elements that will make the web site to be accessible 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:

* **S3**: AWS VPC
    

## 📌 Architecture Diagram

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1711943383051/06404dbf-4a65-4b03-8037-c05433ca172d.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/v1715054684591/993c73f1-4ca4-45ec-a08a-7e59b9512db1.jpeg align="center")

## 📋 Table of Contents

I - **Terraform Configuration files**

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

[Step 2: S3 Configuration](http://127.0.0.1:8000/static-web-terraform-on-aws/#-VPC-configuration)

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

II - **Instructions of Deployment**

[Step 1: Clone Repository](http://127.0.0.1:8000/static-web-terraform-on-aws/#-Clone-Repository)

[Step 2: Initialize Folder](http://127.0.0.1:8000/static-web-terraform-on-aws/#-Initialize-Folder)

[Step 3: Format Files](http://127.0.0.1:8000/static-web-terraform-on-aws/#-Format-Files)

[Step 4: Validate Files](http://127.0.0.1:8000/static-web-terraform-on-aws/#-Validate-Files)

[Step 5: Plan](http://127.0.0.1:8000/static-web-terraform-on-aws/#-Plan)

[Step 6: Apply](http://127.0.0.1:8000/static-web-terraform-on-aws/#-Apply)

[Step 7: Review of Resources](http://127.0.0.1:8000/static-web-terraform-on-aws/#-Review-Of-Resources)

[Step 8: Destroy](http://127.0.0.1:8000/static-web-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/static-web-terraform-on-aws/providers.tf)
    

##### Step 3: ***S3 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

* [S3 Configuration](https://github.com/Joebaho/Joebaho-Cloud-Platform/blob/main/site/static-web-terraform-on-aws/main.tf)
    

We have here

* **Bucket name**:
    
* **Permissions**:
    
* **Objects**:
    
* **Properties**:
    

##### 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/static-web-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/docs/static-web-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/v1715054741743/ca4c37ac-bc19-4bea-b482-281ad80af272.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/v1715054781981/ef5295a1-6e9b-460f-bbe8-defd5b8658a1.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/v1715054819778/f1b9e04b-1e9e-4e83-b6a9-cde631325b73.jpeg align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715054840712/401acf60-e600-40b3-a3e5-c45d0ad673d7.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

The process of creation will start and you will be able to see which resourse 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/v1715054888811/d8c3436c-732a-4666-bd23-7cd3616fe209.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

* **S3**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715054930225/e474a5b5-f887-424e-81e7-bf5efa597a7e.jpeg align="center")
    
* **Permissions**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715054967611/91ee218f-b487-4a4f-b862-3dca59c88f23.jpeg align="center")
    
* **objects**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715054994427/b0e344e7-de33-476b-ba77-4bb090679721.jpeg align="center")
    
* **properties**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055018433/c4f56230-2788-4f26-a05e-8be2020d3d12.jpeg align="center")
    
* **web page**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055050798/e5e4d94d-0730-4d1d-85b4-7fc969e74e96.jpeg align="center")
    
* **error page**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1715055074188/4388bbff-526b-4f5d-a820-988ee1fd0ca9.jpeg align="center")

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

Destroy the terraform managed infrastructure meaning all resourcescreated 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/v1715055102370/6857ade3-4928-427c-8973-bea9a068ff10.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 Joebaho Cloud License
