Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| `aws_instance` | [aws](aws/aws_instance) <p/> [simple](aws/aws_instance/simple) <p/> [simple_ssh_access](aws/aws_instance/simple_ssh_access) |
| `aws_lambda_function` | [aws](aws/aws_lambda_function) <p/> [simple](aws/aws_lambda_function/simple) |
| `aws_rds_cluster` | [aws](aws/aws_rds_cluster) <p/> [simple](aws/aws_rds_cluster/simple) |
| `aws_s3_bucket` | [aws, backends, s3](backends/s3/aws_s3_bucket) |
| `aws_s3_bucket` | [aws, backends, s3](backends/s3/aws_s3_bucket) <p/> [s3_static_website](aws/aws_s3_bucket/s3_static_website) |
| `aws_security_group` | [aws, ssh](aws/aws_security_group/ssh) <p/> [aws, open](aws/aws_security_group/open) |
| `aws_vpc` | [aws](aws/aws_vpc/simple) |
| `azuread_application` | [simple](azuread/azuread_application/simple) |
Expand Down
2 changes: 2 additions & 0 deletions aws/aws_s3_bucket/s3_static_website/destroy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
../../../bin/destroy.sh aws
61 changes: 61 additions & 0 deletions aws/aws_s3_bucket/s3_static_website/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Summary: Setup a static website inside the S3 Bucket

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.38"
}
}
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "aws" {
region = "us-east-1"
default_tags {
tags = {
cs_terraform_examples = "aws_s3_bucket/s3_static_website"
}
}
}



# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# See also: [aws/aws_s3_bucket/simple] (https://github.com/ContainerSolutions/terraform-examples/tree/main/aws/aws_s3_bucket/simple)
# Explanation: Sets a Bucket for Static Website Hosting
# Now you have to add your files to the bucket index.html and also acces with this naming scheme , dependig on your region:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding 2 s3_bucket_object referencing 2 files, index.html and error.html, which can also be added to this repo. A simple index.html file can be found here

# s3-website dash (-) Region ‐ http://bucket-name.s3-website-Region.amazonaws.com
# s3-website dot (.) Region ‐ http://bucket-name.s3-website.Region.amazonaws.com

resource "aws_s3_bucket" "changeme_aws_static_website" {
bucket = "s3-website-xftcs.example.com"
acl = "public-read"
policy = file("policy.json")
website {
index_document = "index.html"
error_document = "error.html"

routing_rules = <<EOF
[{
"Condition": {
"KeyPrefixEquals": "docs/"
},
"Redirect": {
"ReplaceKeyPrefixWith": "documents/"
}
}]
EOF
}
}


output "Website-Endpoint" {
value = aws_s3_bucket.changeme_aws_static_website.website_endpoint
}
output "Website-Domain" {
value = aws_s3_bucket.changeme_aws_static_website.website_domain
}

16 changes: 16 additions & 0 deletions aws/aws_s3_bucket/s3_static_website/policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::s3-website-xftcs.example.com/*"
]
}
]
}
2 changes: 2 additions & 0 deletions aws/aws_s3_bucket/s3_static_website/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
../../../bin/apply.sh aws