Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# mhhsd-test — S3 Static Website (Terraform)

This Terraform config creates an **S3 bucket**, enables **S3 static website hosting**, uploads your local site files, and outputs the **website URL**.

> Note: The **S3 Website Endpoint is HTTP only**. If you want HTTPS + a locked-down bucket, use **CloudFront** in front of S3 instead.

---

## What it creates

- S3 bucket (optionally `force_destroy = true` for easy teardown)
- S3 Website hosting configuration (`index.html` / `error.html`)
- Public read access for objects (required for S3 website endpoint)
- Uploads files from a local directory to the bucket
- Outputs the website URL + bucket name

---

## Prerequisites

- Terraform installed (`terraform -version`)
- AWS credentials available to Terraform (pick one):
  - `AWS_PROFILE=default` (or your profile)
  - `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`
  - SSO or other supported auth
- Your website folder exists locally (example):
  - `C:/Users/okano/Downloads/mhhsd-test`
- Your site includes at least:
  - `index.html`
  - `style.css`
  - (optional but recommended) `error.html`

---

## Files

Typical layout:

```text
.
├── main.tf
├── variables.tf
├── outputs.tf
└── providers.tf

Configure

Variables

Variable Default Description
aws_region us-east-1 AWS region to deploy into
bucket_name mhhsd-test S3 bucket name (must be globally unique)
site_dir C:/Users/okano/Downloads/mhhsd-test Local path to your website folder
index_document index.html Website index file
error_document error.html Website error file

Bucket names are global. If mhhsd-test is taken, change bucket_name to something unique.


Deploy

From the Terraform folder:

terraform init
terraform plan
terraform apply

After apply, Terraform prints the outputs.


Outputs

  • bucket_name — the created bucket name
  • website_endpoint — S3 website endpoint
  • website_url — full HTTP URL you can open in a browser

Example:

website_url = "http://mhhsd-test.s3-website-us-east-1.amazonaws.com"

Update the site

  1. Edit files in your local site_dir
  2. Re-run:
terraform apply

Terraform will re-upload changed files using hashes/ETags.


Destroy

⚠️ This will delete the bucket and all uploaded objects (because force_destroy = true):

terraform destroy

Security notes (important)

This configuration intentionally allows public read to support the S3 Website Endpoint.

  • Public access block is disabled for this bucket
  • Bucket policy allows s3:GetObject to everyone
  • No bucket listing permission is granted

About

Terraform to create an s3 bucket and publish and s3 website for testing. Creates public website for simple site testing

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages