This Terraform project creates a static website hosted on AWS S3 Bucket.
Before you begin, ensure you have the following:
- Terraform installed.
- AWS credentials configured.
-
Clone this repository.
-
Initialize Terraform:
terraform init
-
Create a Terraform execution plan:
terraform plan -var-file=vars/dev.tfvars
-
Apply the Terraform configuration:
terraform apply -var-file=vars/dev.tfvars
-
Access your website using the provided endpoint:
terraform output s3_website_endpoint
To remove all resources created by this Terraform configuration, run:
terraform destroy -var-file=vars/dev.tfvars
- Purpose: Configures the AWS provider.
- Provider: AWS.
- Region: us-east-1.
- Tags: Default tags for resources.
- Purpose: Defines input variables for the project.
- Variables:
bucket_name
: Name of the S3 bucket.env
: Environment name (e.g., dev, prod).
- Purpose: Creates the S3 bucket and configures static website hosting.
- Steps:
- Create a bucket with a formatted name (
bucket_name-env
). - Enable static website hosting with index and error documents.
- Edit Block Public Access settings.
- Add a bucket policy to make bucket content publicly accessible.
- Configure index document.
- Configure error document.
- Create a bucket with a formatted name (
- Purpose: Outputs the URL of the static website.
- Output:
s3_website_endpoint
: Endpoint URL of the static website.
- Purpose: Defines variable values for the
dev
environment. - Variables:
bucket_name
: "venkatesh-s3-30032024"env
: "dev"
https://docs.aws.amazon.com/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object