Static web site hosting on S3 using Terraform

Static web site hosting on S3 using Terraform

ยท

5 min read

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 neccessary copoments 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

๐ŸŒŸ 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

alt text

๐Ÿ“‹ Table of Contents

I - Terraform Configuration files

Step 1: Provider Configuration

Step 2: S3 Configuration

Step 4: Output Configuration

II - Instructions of Deployment

Step 1: Clone Repository

Step 2: Initialize Folder

Step 3: Format Files

Step 4: Validate Files

Step 5: Plan

Step 6: Apply

Step 7: Review of Resources

Step 8: 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

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

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 infranstructure 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.

๐Ÿ’ผ 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 github.com/Joebaho/Joebaho-Cloud-Platform/t..

Step 6: Initialize Folder

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

terraform init

You must see this image

alt text

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

alt text

Step 9: Plan

Create an excution 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 resouces

alt text

alt text

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 recieve a prompt message showing all resources status: created, changed and the numbers of them.

alt text

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

alt text

  • Permissions

alt text

  • objects

alt text

  • properties

alt text

  • web page

alt text

  • error page

alt text

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 recieve a prompt message showing all resources has been destroyed

alt text

๐Ÿค 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

ย