Skip to content

Commit 1a73277

Browse files
committed
Initial commit
0 parents  commit 1a73277

19 files changed

+287
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.terraform
2+
.idea

.terraform.docs.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: ">= 0.13.0, < 1.0.0"
2+
formatter: "markdown table"
3+
output:
4+
file: README.md
5+
mode: replace
6+
header-from: "docs/.header.md"
7+
footer-from: "docs/.footer.md"

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 SmartAssist Tech Private Limited
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
# AWS Static Website Terraform Module
3+
4+
## What does it do?
5+
6+
Creates a static website with all the necessary dependencies:
7+
8+
- S3 Bucket
9+
- S3 Bucket Website Configuration
10+
- IAM user with deploy permissions
11+
- Validated ACM cert (in us-east-1)
12+
- CloudFront distribution
13+
- DNS record for domain name
14+
15+
**Currently, only supports Cloudflare for DNS records**
16+
17+
## Requirements
18+
19+
| Name | Version |
20+
|------|---------|
21+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.15, < 5.0 |
22+
| <a name="requirement_cloudflare"></a> [cloudflare](#requirement\_cloudflare) | >= 3.15, < 4.0 |
23+
24+
## Providers
25+
26+
| Name | Version |
27+
|------|---------|
28+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.15, < 5.0 |
29+
| <a name="provider_cloudflare"></a> [cloudflare](#provider\_cloudflare) | >= 3.15, < 4.0 |
30+
31+
## Modules
32+
33+
| Name | Source | Version |
34+
|------|--------|---------|
35+
| <a name="module_certificate"></a> [certificate](#module\_certificate) | smartassistco/cloudflare-validated-acm/aws | n/a |
36+
| <a name="module_s3website"></a> [s3website](#module\_s3website) | smartassistco/s3website/aws | n/a |
37+
38+
## Resources
39+
40+
| Name | Type |
41+
|------|------|
42+
| [aws_cloudfront_distribution.cloudfront_distribution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution) | resource |
43+
| [cloudflare_record.dns_record](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/record) | resource |
44+
45+
## Inputs
46+
47+
| Name | Description | Type | Default | Required |
48+
|------|-------------|------|---------|:--------:|
49+
| <a name="input_cloudflare_zone_id"></a> [cloudflare\_zone\_id](#input\_cloudflare\_zone\_id) | The Zone ID for the DNS provider | `string` | n/a | yes |
50+
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | The domain name for the website, e.g. demo.example.com | `string` | n/a | yes |
51+
| <a name="input_error_file"></a> [error\_file](#input\_error\_file) | The name of the error file in the S3 bucket | `string` | `"404.html"` | no |
52+
| <a name="input_index_file"></a> [index\_file](#input\_index\_file) | The name of the error file in the S3 bucket | `string` | `"index.html"` | no |
53+
| <a name="input_project_name"></a> [project\_name](#input\_project\_name) | The name of the project, which will be used to create the S3 bucket and deploy user. e.g. demo-website | `string` | n/a | yes |
54+
55+
## Outputs
56+
57+
| Name | Description |
58+
|------|-------------|
59+
| <a name="output_deploy_bucket"></a> [deploy\_bucket](#output\_deploy\_bucket) | The S3 bucket to deploy the website files |
60+
| <a name="output_deploy_user_creds"></a> [deploy\_user\_creds](#output\_deploy\_user\_creds) | The AWS credentials for the deploy user |
61+
<!-- END_TF_DOCS -->

docs/.footer.md

Whitespace-only changes.

docs/.header.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AWS Static Website Terraform Module
2+
3+
## What does it do?
4+
5+
Creates a static website with all the necessary dependencies:
6+
7+
- S3 Bucket
8+
- S3 Bucket Website Configuration
9+
- IAM user with deploy permissions
10+
- Validated ACM cert (in us-east-1)
11+
- CloudFront distribution
12+
- DNS record for domain name
13+
14+
**Currently, only supports Cloudflare for DNS records**

examples/complete/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AWS Static Website
2+
3+
Standard configuration

examples/complete/main.tf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module "sample_website" {
2+
source = "smartassistco/staticwebsite/aws"
3+
4+
project_name = "sample-website"
5+
domain_name = "testing.example.com"
6+
cloudflare_zone_id = "xxxxxxxxxxxxxxxxxx"
7+
8+
providers = {
9+
aws.bucket-region = aws,
10+
aws.us-east-1 = aws.useast1
11+
}
12+
}

examples/complete/outputs.tf

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "sample_website_deploy_info" {
2+
value = {
3+
bucket = module.sample_website.deploy_bucket,
4+
creds = module.sample_website.deploy_user_creds
5+
}
6+
sensitive = true
7+
}

examples/complete/provider_aws.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
provider "aws" {
6+
alias = "useast1"
7+
8+
region = "us-east-1"
9+
}

examples/complete/variables.tf

Whitespace-only changes.

examples/complete/versions.tf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = ">= 4.15, < 5.0"
6+
}
7+
8+
cloudflare = {
9+
source = "cloudflare/cloudflare"
10+
version = ">= 3.15, < 4.0"
11+
}
12+
}
13+
}

main-acm.tf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Certificate
2+
module "certificate" {
3+
source = "smartassistco/cloudflare-validated-acm/aws"
4+
5+
cloudflare_zone_id = var.cloudflare_zone_id
6+
domain_name = var.domain_name
7+
8+
providers = {
9+
aws = aws.us-east-1
10+
}
11+
}

main-cdn.tf

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# CloudFront Distribution
2+
resource "aws_cloudfront_distribution" "cloudfront_distribution" {
3+
enabled = true
4+
is_ipv6_enabled = true
5+
6+
viewer_certificate {
7+
cloudfront_default_certificate = false
8+
acm_certificate_arn = module.certificate.validated_certificate.certificate_arn
9+
minimum_protocol_version = "TLSv1.2_2021"
10+
ssl_support_method = "sni-only"
11+
}
12+
13+
aliases = [var.domain_name]
14+
15+
restrictions {
16+
geo_restriction {
17+
restriction_type = "none"
18+
}
19+
}
20+
21+
origin {
22+
domain_name = module.s3website.website_endpoint
23+
origin_id = "S3StaticWebsiteOrigin"
24+
25+
custom_origin_config {
26+
origin_protocol_policy = "http-only"
27+
http_port = 80
28+
https_port = 443
29+
origin_ssl_protocols = ["TLSv1.2"]
30+
}
31+
}
32+
33+
default_cache_behavior {
34+
target_origin_id = "S3StaticWebsiteOrigin"
35+
compress = true
36+
viewer_protocol_policy = "redirect-to-https"
37+
38+
allowed_methods = ["GET", "HEAD"]
39+
cached_methods = ["GET", "HEAD"]
40+
41+
min_ttl = 0
42+
default_ttl = 600
43+
max_ttl = 600
44+
45+
forwarded_values {
46+
query_string = false
47+
48+
cookies {
49+
forward = "none"
50+
}
51+
}
52+
}
53+
}

main-cname.tf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
locals {
2+
root_domain = join(".", reverse(slice(reverse(split(".", var.domain_name)), 0, 2)))
3+
record_name = var.domain_name == local.root_domain ? var.domain_name : replace(var.domain_name, ".${local.root_domain}", "")
4+
}
5+
6+
resource "cloudflare_record" "dns_record" {
7+
zone_id = var.cloudflare_zone_id
8+
name = local.record_name
9+
value = aws_cloudfront_distribution.cloudfront_distribution.domain_name
10+
type = "CNAME"
11+
proxied = false
12+
}

main-s3website.tf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module "s3website" {
2+
source = "smartassistco/s3website/aws"
3+
4+
project_name = var.project_name
5+
index_file = var.index_file
6+
error_file = var.error_file
7+
8+
providers = {
9+
aws = aws.bucket-region
10+
}
11+
}

outputs.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
output "deploy_bucket" {
2+
description = "The S3 bucket to deploy the website files"
3+
value = module.s3website.deploy_bucket
4+
}
5+
6+
output "deploy_user_creds" {
7+
description = "The AWS credentials for the deploy user"
8+
value = module.s3website.deploy_user_creds
9+
sensitive = true
10+
}

providers.tf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = ">= 4.15, < 5.0"
6+
7+
configuration_aliases = [aws.bucket-region, aws.us-east-1]
8+
}
9+
10+
cloudflare = {
11+
source = "cloudflare/cloudflare"
12+
version = ">= 3.15, < 4.0"
13+
}
14+
}
15+
}

variables.tf

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
variable "project_name" {
2+
description = "The name of the project, which will be used to create the S3 bucket and deploy user. e.g. demo-website"
3+
type = string
4+
}
5+
6+
variable "index_file" {
7+
description = "The name of the error file in the S3 bucket"
8+
type = string
9+
default = "index.html"
10+
}
11+
12+
variable "error_file" {
13+
description = "The name of the error file in the S3 bucket"
14+
type = string
15+
default = "404.html"
16+
}
17+
18+
variable "domain_name" {
19+
description = "The domain name for the website, e.g. demo.example.com"
20+
type = string
21+
}
22+
23+
variable "cloudflare_zone_id" {
24+
description = "The Zone ID for the DNS provider"
25+
type = string
26+
}

0 commit comments

Comments
 (0)