├── README.md └── Static Webiste Hosting Using Terraform ├── error.html ├── index.html ├── output.tf ├── provider.tf └── resource.tf /README.md: -------------------------------------------------------------------------------- 1 | # Terraform AWS S3 Static Website Hosting 2 | 3 | ## Project Description: 4 | In this project, I developed a streamlined infrastructure for hosting a static website using Terraform and Amazon Web Services (AWS) S3. The primary goal of this project is to demonstrate the automated provisioning and deployment of a web hosting solution for static websites. 5 | 6 | ## Overview: 7 | 8 | ![s3](https://github.com/mathesh-me/static-website-host-1/assets/144098846/ab68ff80-7841-4674-9b3c-ceac0710a39b) 9 | 10 | 11 | ## Key Components and Features: 12 | 13 | ### Terraform Infrastructure as Code (IaC): 14 | I utilized Terraform, an IaC tool, to define and provision the AWS resources required for my static website hosting solution. This allows for version-controlled, repeatable infrastructure deployments. 15 | 16 | ### AWS S3 Bucket: 17 | I created an S3 bucket to store and serve the static website files. This bucket is configured for website hosting, allowing for easy content delivery. 18 | 19 | ### Content Upload and Management: 20 | I provided instructions and scripts for uploading and managing my website content within the S3 bucket. 21 | 22 | ## Prerequisites: 23 | 24 | 1. Basic knowledge of AWS services and concepts. 25 | 2. Familiarity with Terraform and infrastructure as code principles. 26 | 3. An AWS account with appropriate permissions. 27 | 4. An IDE of your Choice , I would suggest VS Code Editor . 28 | 5. This project serves as an excellent foundation for hosting various types of static websites, including personal blogs, portfolio sites, or small business websites. 29 | 30 | 31 | ## Steps : 32 | 33 | ### Step 1: Set Up Your Development Environment 34 | 35 | Install Terraform and the AWS Command Line Interface (CLI) on your local machine. 36 | Configure your AWS credentials by running ```aws configure``` and providing your AWS access key and secret key. 37 | 38 | ### Step 2: Define Your Website Content 39 | 40 | To prepare static website files (HTML), place them in the directory where your Terraform configuration files are located. Name the main HTML file "index.html," and optionally, you can also include an "error.html" file. If you prefer, you can reference my repository for the static website HTML files. 41 | 42 | ### Step 3: Terraform Configuration File Syntax 43 | 44 | If we want to Create a terraform configuration file we have to use .tf (e.g., main.tf) to define the infrastructure as code using terraform. 45 | 46 | ### Step 4: Define your Configuration Files in your IDE 47 | ### Define the AWS provider and required resources like S3 buckets, IAM roles, and policies 48 | 1. Define ```provider.tf``` file using the below code : 49 | 50 | ``` 51 | provider "aws" { 52 | region = "ap-south-1" 53 | } 54 | ``` 55 | 2. In your Integrated Development Environment (IDE), open the terminal and navigate to the directory where you have created these configuration files. 56 | 3. After navigating to the directory where your configuration files are located in your IDE's terminal, you can run the following command to initialize Terraform and prepare it for use with AWS: 57 | 58 | ```shell 59 | terraform init 60 | ``` 61 | 62 | Running `terraform init` will install the necessary plugins and modules required for connecting to AWS and managing your infrastructure.
63 | 4. And then define __resource.tf__ file for creating bucket by using the below code : 64 | 65 | ``` 66 | resource "aws_s3_bucket" "bucket1" { 67 | bucket = "web-bucket-mathesh" 68 | 69 | } 70 | ``` 71 | 5. Then below command for creating the bucket : 72 | 73 | ``` 74 | terraform apply -auto-approve 75 | ``` 76 | 6. And then add the below codes in __resource.tf__ file : 77 | ``` 78 | resource "aws_s3_bucket_public_access_block" "bucket1" { 79 | bucket = aws_s3_bucket.bucket1.id 80 | 81 | block_public_acls = false 82 | block_public_policy = false 83 | ignore_public_acls = false 84 | restrict_public_buckets = false 85 | } 86 | 87 | resource "aws_s3_object" "index" { 88 | bucket = "web-bucket-mathesh" 89 | key = "index.html" 90 | source = "index.html" 91 | content_type = "text/html" 92 | } 93 | 94 | resource "aws_s3_object" "error" { 95 | bucket = "web-bucket-mathesh" 96 | key = "error.html" 97 | source = "error.html" 98 | content_type = "text/html" 99 | } 100 | 101 | 102 | resource "aws_s3_bucket_website_configuration" "bucket1" { 103 | bucket = aws_s3_bucket.bucket1.id 104 | 105 | index_document { 106 | suffix = "index.html" 107 | } 108 | 109 | error_document { 110 | key = "error.html" 111 | } 112 | 113 | } 114 | 115 | resource "aws_s3_bucket_policy" "public_read_access" { 116 | bucket = aws_s3_bucket.bucket1.id 117 | policy = < 2 | 3 | 4 | 5 | 6 | Error - Best Books for Cloud and DevOps 7 | 48 | 49 | 50 |
51 |

Error - Best Books for Cloud and DevOps

52 |
53 |
54 |

Oops! Something went wrong. We apologize for the inconvenience.

55 |

Please return to the homepage and try again.

56 |
57 | 58 | 59 | -------------------------------------------------------------------------------- /Static Webiste Hosting Using Terraform/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Best Books for Cloud and DevOps 7 | 66 | 67 | 68 |
69 |

Best Books for Cloud and DevOps

70 |
71 |
72 |
73 |

The DevOps Handbook

74 |

Authors: Gene Kim, Jez Humble, Patrick Debois, John Allspaw and John Willis
75 | 76 | The DevOps Handbook: How to Create World-Class Agility, Reliability and Security in Technology Organizations book is considered as the DevOps bible by many readers. The authors talk about the importance of implementing DevOps into any organization and how it helps to gain a competitive advantage from the rest. It also talks about the core benefits of DevOps and practical applications of how to adopt DevOps. There are a number of case studies on companies that have done it successfully and how you can implement them into your own organization.

77 | Buy the Book 78 |
79 | 80 |
81 |

The Phoenix Project

82 |

Authors: Gene Kim
83 | 84 | The Phoenix Project book explains the concept of DevOps using a fictional company and fictional employees. The story revolves around Bill, a VP at Parts Unlimited, who has been assigned to fix all of the company’s problems. The company is in a fix and nothing works, including their payment system. Bill starts to identify all of these issues and implement solutions for them. We see throughout the book that these solutions are in fact, DevOps practices. It is an excellent way to understand complex DevOps subject matters in a fun way.

85 | Buy the Book 86 |
87 | 88 |
89 |

The Unicorn Project

90 |

Authors: Gene Kim
91 | 92 | The Unicorn Project: A Novel about Developers, Digital Disruption, and Thriving in the Age of Data book is like a sequel to the Phoenix Project book, but with a different point of view. This time, the main protagonist is Maxine, a developer in the Phoenix Project team. She finds a mentor in Erick who guides her with the five ideals of problem-solving in DevOps.

93 | Buy the Book 94 |
95 | 96 |
97 | 98 | 99 | -------------------------------------------------------------------------------- /Static Webiste Hosting Using Terraform/output.tf: -------------------------------------------------------------------------------- 1 | output "websiteendpoint" { 2 | value = aws_s3_bucket.bucket1.website_endpoint 3 | 4 | } -------------------------------------------------------------------------------- /Static Webiste Hosting Using Terraform/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "ap-south-1" 3 | } -------------------------------------------------------------------------------- /Static Webiste Hosting Using Terraform/resource.tf: -------------------------------------------------------------------------------- 1 | resource "aws_s3_bucket" "bucket1" { 2 | bucket = "web-bucket-mathesh" 3 | 4 | } 5 | resource "aws_s3_bucket_public_access_block" "bucket1" { 6 | bucket = aws_s3_bucket.bucket1.id 7 | 8 | block_public_acls = false 9 | block_public_policy = false 10 | ignore_public_acls = false 11 | restrict_public_buckets = false 12 | } 13 | 14 | resource "aws_s3_object" "index" { 15 | bucket = "web-bucket-mathesh" 16 | key = "index.html" 17 | source = "index.html" 18 | content_type = "text/html" 19 | } 20 | 21 | resource "aws_s3_object" "error" { 22 | bucket = "web-bucket-mathesh" 23 | key = "error.html" 24 | source = "error.html" 25 | content_type = "text/html" 26 | } 27 | 28 | 29 | resource "aws_s3_bucket_website_configuration" "bucket1" { 30 | bucket = aws_s3_bucket.bucket1.id 31 | 32 | index_document { 33 | suffix = "index.html" 34 | } 35 | 36 | error_document { 37 | key = "error.html" 38 | } 39 | 40 | } 41 | 42 | resource "aws_s3_bucket_policy" "public_read_access" { 43 | bucket = aws_s3_bucket.bucket1.id 44 | policy = <