Skip to content

Latest commit

 

History

History

simple_static_website

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Simple static website

The purpose of this module is to create a simple static website using S3 and CloudFront. Access to the S3 bucket is restricted to CloudFront using an Origin Access Identity (OAI).

Usage

module "website" {
 source  = "github.com/cds-snc/terraform-modules//simple_static_website"

 domain_name_source = "example.com"
 billing_tag_value  = "simple-static-website"

 providers = {
   aws           = aws
   aws.dns       = aws.dns # For scenarios where there is a dedicated DNS provider.  You can also just use the default.
   aws.us-east-1 = aws.us-east-1
 }
}

Requirements

Name Version
aws >= 4.9

Providers

Name Version
aws >= 4.9
aws.dns >= 4.9
aws.us-east-1 >= 4.9
random n/a

Modules

No modules.

Resources

Name Type
aws_acm_certificate.cloudfront resource
aws_acm_certificate_validation.cloudfront resource
aws_cloudfront_distribution.simple_static_website resource
aws_cloudfront_origin_access_identity.simple_static_website resource
aws_route53_record.cloudfront_alias resource
aws_route53_record.cloudfront_certificate_validation resource
aws_route53_zone.hosted_zone resource
aws_s3_bucket.this resource
aws_s3_bucket_policy.oai_policy resource
aws_s3_bucket_public_access_block.this resource
aws_s3_bucket_website_configuration.this resource
random_string.suffix resource
aws_iam_policy_document.s3_policy data source

Inputs

Name Description Type Default Required
acm_certificate_arn (Optional, default '') ARN of the us-east-1 region certificate used by CloudFront. If not specified, a new certificate will be created. string "" no
billing_tag_key (Optional, default 'CostCentre') The name of the billing tag. string "CostCentre" no
billing_tag_value (Required) The value of the billing tag. string n/a yes
cloudfront_price_class (Optional, default 'PriceClass_100') The price class of the CloudFront distribution. string "PriceClass_100" no
cloudfront_query_string_forwarding (Optional, default 'false') If true, query strings will be forwarded to the origin. bool false no
custom_error_responses (Optional) Map containing custom error responses. The key is the HTTP error code and the value is the response page.
list(object({
error_code = number
response_page_path = optional(string)
error_caching_min_ttl = optional(number)
response_code = optional(number) }))
[] no
domain_name_source (Required) Domain name that will be initially entered by the user. It should be in the form 'example.com'. string n/a yes
error_document (Optional, default 'error.html') The name of the error document. string "error.html" no
force_destroy_s3_bucket (Optional, default 'false') If true, the s3 bucket will be deleted even if it's full. Not advised for production use. bool false no
function_association (Optional) Map containing function association configuration, that trigers a cloudfront function with specific actions. A maximum of 2 can be specified. list(map(string)) [] no
hosted_zone_id (Optional, default '') Hosted zone ID used to create the domain name source ALIAS record pointing to Cloudfront. If not specified, a new hosted zone will be created. string "" no
index_document (Optional, default 'index.html') The name of the index document. string "index.html" no
lambda_function_association (Optional) Map containing lambda function association configuration. A maximum of 4 can be specified. list(map(string)) [] no
s3_bucket_name (Optional, default '') Name of the S3 bucket. If not specified the domain_name_source + a random number will be used. string "" no
single_page_app (Optional, default 'false') If true, the index document will be returned for all 403 requests to the origin. bool false no
web_acl_arn (Optional, default null) ARN of the WAF Web ACL to associate with the CloudFront distribution (using version WAFv2). string null no

Outputs

Name Description
s3_bucket_arn The ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
s3_bucket_id The name of the bucket.
s3_bucket_region The AWS region this bucket resides in.