Skip to main content
Version: Next

AWS CLOUDFRONT-S3-CDN

Description

Terraform module to easily provision CloudFront CDN backed by an S3 origin

Specification

Properties

NameDescriptionTypeRequiredDefault
access_log_bucket_nameDEPRECATED. Use s3_access_log_bucket_name instead.stringfalse
acm_certificate_arnExisting ACM Certificate ARNstringfalse
additional_bucket_policyAdditional policies for the bucket. If included in the policies, the variables ${bucket_name}, ${origin_path} and ${cloudfront_origin_access_identity_iam_arn} will be substituted.\nIt is also possible to override the default policy statements by providing statements with S3GetObjectForCloudFront and S3ListBucketForCloudFront sid.\nstringfalse
aliasesList of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfrontlist(string)false
allow_ssl_requests_onlySet to true to require requests to use Secure Socket Layer (HTTPS/SSL). This will explicitly deny access to HTTP requestsboolfalse
allowed_methodsList of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFrontlist(string)false
block_origin_public_access_enabledWhen set to 'true' the s3 origin bucket will have public access block enabledboolfalse
cache_policy_idThe unique identifier of the existing cache policy to attach to the default cache behavior.\nIf not provided, this module will add a default cache policy using other provided inputs.\nstringfalse
cached_methodsList of cached methods (e.g. GET, PUT, POST, DELETE, HEAD)list(string)false
cloudfront_access_log_bucket_nameWhen cloudfront_access_log_create_bucket is false, this is the name of the existing S3 Bucket where Cloudfront Access Logs are to be delivered and is required. IGNORED when cloudfront_access_log_create_bucket is true.stringfalse
cloudfront_access_log_create_bucketWhen true and cloudfront_access_logging_enabled is also true, this module will create a new, separate S3 bucket to receive Cloudfront Access Logs.boolfalse
cloudfront_access_log_include_cookiesSet true to include cookies in Cloudfront Access Logsboolfalse
cloudfront_access_log_prefixPrefix to use for Cloudfront Access Log object keys. Defaults to no prefix.stringfalse
log_expiration_daysNumber of days after object creation to expire Cloudfront Access Log objects. Only effective if cloudfront_access_log_create_bucket is true.numberfalse
log_glacier_transition_daysNumber of days after object creation to move Cloudfront Access Log objects to the glacier tier. Only effective if cloudfront_access_log_create_bucket is true.numberfalse
log_include_cookiesDEPRECATED. Use cloudfront_access_log_include_cookies instead.boolfalse
log_prefixDEPRECATED. Use cloudfront_access_log_prefix instead.stringfalse
log_standard_transition_daysNumber of days after object creation to move Cloudfront Access Log objects to the infrequent access tier. Only effective if cloudfront_access_log_create_bucket is true.numberfalse
log_versioning_enabledSet true to enable object versioning in the created Cloudfront Access Log S3 Bucket. Only effective if cloudfront_access_log_create_bucket is true.boolfalse
logging_enabledDEPRECATED. Use cloudfront_access_logging_enabled instead.boolfalse
max_ttlMaximum amount of time (in seconds) that an object is in a CloudFront cachenumberfalse
min_ttlMinimum amount of time that you want objects to stay in CloudFront cachesnumberfalse
minimum_protocol_versionCloudfront TLS minimum protocol version. If var.acm_certificate_arn is unset, only "TLSv1" can be specified. See: AWS Cloudfront create-distribution documentation and Supported protocols and ciphers between viewers and CloudFront for more information. Defaults to "TLSv1.2_2019" unless var.acm_certificate_arn is unset, in which case it defaults to TLSv1stringfalse
ordered_cacheAn ordered list of cache behaviors for this distribution. See Cache Behavior Schema section below.list(object({ target_origin_id = string, path_pattern = string, allowed_methods = list(string), cached_methods = list(string), compress = bool, trusted_signers = list(string), trusted_key_groups = list(string) }))false
origin_bucketName of an existing S3 bucket to use as the origin. If this is not provided, it will create a new s3 bucket using var.name and other context related inputsstringfalse
origin_force_destroyDelete all objects from the bucket so that the bucket can be destroyed without error (e.g. true or false)boolfalse
origin_groupsList of Origin Groups to create in the distribution. See Origin Groups Schema section below.list(object({ primary_origin_id = string, failover_origin_id = string, failover_criteria = list(string) }))false
origin_pathAn optional element that causes CloudFront to request your content from a directory in your Amazon S3 bucket or your custom origin. It must begin with a /. Do not add a / at the end of the path.stringfalse
origin_request_policy_idThe unique identifier of the origin request policy that is attached to the behavior.\nShould be used in conjunction with cache_policy_id.\nstringfalse
origin_ssl_protocolsThe SSL/TLS protocols that you want CloudFront to use when communicating with your origin over HTTPS.list(string)false
override_origin_bucket_policyWhen using an existing origin bucket (through var.origin_bucket), setting this to 'false' will make it so the existing bucket policy will not be overridenboolfalse
parent_zone_idID of the hosted zone to contain this record (or specify parent_zone_name). Requires dns_alias_enabled set to truestringfalse
parent_zone_nameName of the hosted zone to contain this record (or specify parent_zone_id). Requires dns_alias_enabled set to truestringfalse
price_classPrice class for this distribution: PriceClass_All, PriceClass_200, PriceClass_100stringfalse
query_string_cache_keysWhen forward_query_string is enabled, only the query string keys listed in this argument are cached (incompatible with cache_policy_id)list(string)false
realtime_log_config_arnThe ARN of the real-time log configuration that is attached to this cache behaviorstringfalse
redirect_all_requests_toA hostname to redirect all website requests for this distribution to. If this is set, it overrides other website settingsstringfalse
response_headers_policy_idThe identifier for a response headers policystringfalse
routing_rulesA json array containing routing rules describing redirect behavior and when redirects are appliedstringfalse
s3_access_log_bucket_nameName of the existing S3 bucket where S3 Access Logs will be delivered. Default is not to enable S3 Access Logging.stringfalse
s3_access_log_prefixPrefix to use for S3 Access Log object keys. Defaults to logs/${module.this.id}stringfalse
s3_access_logging_enabledSet true to deliver S3 Access Logs to the s3_access_log_bucket_name bucket.\nDefaults to false if s3_access_log_bucket_name is empty (the default), true otherwise.\nMust be set explicitly if the access log bucket is being created at the same time as this module is being invoked.\nboolfalse
s3_object_ownershipSpecifies the S3 object ownership control on the origin bucket. Valid values are ObjectWriter, BucketOwnerPreferred, and 'BucketOwnerEnforced'.stringfalse
s3_originsA list of S3 origins (in addition to the one created by this module) for this distribution. See S3 Origins Schema section below.listfalse
s3_website_password_enabledIf set to true, and website_enabled is also true, a password will be required in the Referrer field of the\nHTTP request in order to access the website, and Cloudfront will be configured to pass this password in its requests.\nThis will make it much harder for people to bypass Cloudfront and access the S3 website directly via its website endpoint.\nboolfalse
trusted_key_groupsA list of key group IDs that CloudFront can use to validate signed URLs or signed cookies.list(string)false
trusted_signersThe AWS accounts, if any, that you want to allow to create signed URLs for private content. 'self' is acceptable.list(string)false
versioning_enabledWhen set to 'true' the s3 origin bucket will have versioning enabledboolfalse
viewer_protocol_policyLimit the protocol users can use to access content. One of allow-all, https-only, or redirect-to-httpsstringfalse
wait_for_deploymentWhen set to 'true' the resource will wait for the distribution status to change from InProgress to Deployedboolfalse
web_acl_idID of the AWS WAF web ACL that is associated with the distributionstringfalse
website_enabledSet to true to enable the created S3 bucket to serve as a website independently of Cloudfront,\nand to use that website as the origin. See the README for details and caveats. See also s3_website_password_enabled.\nboolfalse
writeConnectionSecretToRefThe secret which the cloud resource connection will be written towriteConnectionSecretToReffalse

Schema Definitions

Cache Behavior Schema

list(object({
target_origin_id = string
path_pattern = string
allowed_methods = list(string)
cached_methods = list(string)
compress = bool
trusted_signers = list(string)
trusted_key_groups = list(string)
# ... and other fields
}))

Origin Groups Schema

list(object({
primary_origin_id = string
failover_origin_id = string
failover_criteria = list(string)
}))

S3 Origins Schema

list(object({
domain_name = string
origin_id = string
origin_path = string
s3_origin_config = object({
origin_access_identity = string
})
}))

writeConnectionSecretToRef

NameDescriptionTypeRequiredDefault
nameThe secret name which the cloud resource connection will be written tostringtrue
namespaceThe secret namespace which the cloud resource connection will be written tostringfalse