Skip to main content
Version: v1.7

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\nCloudfront Access Logs are to be delivered and is required. IGNORED when cloudfront_access_log_create_bucket is true.\nstringfalse
cloudfront_access_log_create_bucketWhen true and cloudfront_access_logging_enabled is also true, this module will create a new,\nseparate S3 bucket to receive Cloudfront Access Logs.\nboolfalse
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
cloudfront_access_logging_enabledSet true to enable delivery of Cloudfront Access Logs to an S3 bucketboolfalse
cloudfront_origin_access_identity_iam_arnExisting cloudfront origin access identity iam arn that is supplied in the s3 bucket policystringfalse
cloudfront_origin_access_identity_pathExisting cloudfront origin access identity path used in the cloudfront distribution's s3_origin_config contentstringfalse
commentComment for the origin access identitystringfalse
compressCompress content for web requests that include Accept-Encoding: gzip in the request headerboolfalse
cors_allowed_headersList of allowed headers for S3 bucketlist(string)false
cors_allowed_methodsList of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for S3 bucketlist(string)false
cors_allowed_originsList of allowed origins (e.g. example.com, test.com) for S3 bucketlist(string)false
cors_expose_headersList of expose header in the response for S3 bucketlist(string)false
cors_max_age_secondsTime in seconds that browser can cache the response for S3 bucketnumberfalse
custom_error_responseList of one or more custom error response element mapslist(object({\n error_caching_min_ttl = string\n error_code = string\n response_code = string\n response_page_path = string\n }))false
custom_origin_headersA list of origin header parameters that will be sent to originlist(object({ name = string, value = string }))false
custom_originsA list of additional custom website origins for this distribution.\nlist(object({\n domain_name = string\n origin_id = string\n origin_path = string\n custom_headers = list(object({\n name = string\n value = string\n }))\n custom_origin_config = object({\n http_port = number\n https_port = number\n origin_protocol_policy = string\n origin_ssl_protocols = list(string)\n origin_keepalive_timeout = number\n origin_read_timeout = number\n })\n }))false
default_root_objectObject that CloudFront return when requests the root URLstringfalse
default_ttlDefault amount of time (in seconds) that an object is in a CloudFront cachenumberfalse
deployment_actionsList of actions to permit deployment_principal_arns to perform on bucket and bucket prefixes (see deployment_principal_arns)list(string)false
deployment_principal_arns(Optional) Map of IAM Principal ARNs to lists of S3 path prefixes to grant deployment_actions permissions.\nResource list will include the bucket itself along with all the prefixes. Prefixes should not begin with '/'.\nmap(list(string))false
distribution_enabledSet to false to create the distribution but still prevent CloudFront from serving requests.boolfalse
dns_alias_enabledCreate a DNS alias for the CDN. Requires parent_zone_id or parent_zone_nameboolfalse
encryption_enabledWhen set to 'true' the resource will have aes256 encryption enabled by defaultboolfalse
error_documentAn absolute path to the document to return in case of a 4XX errorstringfalse
external_aliasesList of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfront. No new route53 records will be created for theselist(string)false
extra_logs_attributesAdditional attributes to add to the end of the generated Cloudfront Access Log S3 Bucket name.\nOnly effective if cloudfront_access_log_create_bucket is true.\nlist(string)false
extra_origin_attributesAdditional attributes to put onto the origin labellist(string)false
forward_cookiesSpecifies whether you want CloudFront to forward all or no cookies to the origin. Can be 'all' or 'none'stringfalse
forward_header_valuesA list of whitelisted header values to forward to the origin (incompatible with cache_policy_id)list(string)false
forward_query_stringForward query strings to the origin that is associated with this cache behavior (incompatible with cache_policy_id)boolfalse
function_associationA config block that triggers a CloudFront function with specific actions.\nSee the aws_cloudfront_distribution\ndocumentation for more information.\nlist(object({\n event_type = string\n function_arn = string\n }))false
geo_restriction_locationsList of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist)list(string)false
geo_restriction_typeMethod that use to restrict distribution of your content by country: none, whitelist, or blackliststringfalse
index_documentAmazon S3 returns this index document when requests are made to the root domain or any of the subfoldersstringfalse
ipv6_enabledSet to true to enable an AAAA DNS record to be set as well as the A recordboolfalse
lambda_function_associationA config block that triggers a lambda@edge function with specific actionslist(object({\n event_type = string\n include_body = bool\n lambda_arn = string\n }))false
log_expiration_daysNumber of days after object creation to expire Cloudfront Access Log objects.\nOnly effective if cloudfront_access_log_create_bucket is true.\nnumberfalse
log_glacier_transition_daysNumber of days after object creation to move Cloudfront Access Log objects to the glacier tier.\nOnly effective if cloudfront_access_log_create_bucket is true.\nnumberfalse
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.\nOnly effective if cloudfront_access_log_create_bucket is true.\nnumberfalse
log_versioning_enabledSet true to enable object versioning in the created Cloudfront Access Log S3 Bucket.\nOnly effective if cloudfront_access_log_create_bucket is true.\nboolfalse
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.\nIf var.acm_certificate_arn is unset, only "TLSv1" can be specified. See: AWS Cloudfront create-distribution documentation\nand Supported protocols and ciphers between viewers and CloudFront for more information.\nDefaults to "TLSv1.2_2019" unless var.acm_certificate_arn is unset, in which case it defaults to TLSv1\nstringfalse
ordered_cacheAn ordered list of cache behaviors resource for this distribution.\nList in order of precedence (first match wins). This is in addition to the default cache policy.\nSet target_origin_id to "" to specify the S3 bucket origin created by this module.\nlist(object({\n target_origin_id = string\n path_pattern = string\n\n allowed_methods = list(string)\n cached_methods = list(string)\n compress = bool\n trusted_signers = list(string)\n trusted_key_groups = list(string)\n\n cache_policy_id = string\n origin_request_policy_id = string\n\n viewer_protocol_policy = string\n min_ttl = number\n default_ttl = number\n max_ttl = number\n response_headers_policy_id = string\n\n forward_query_string = bool\n forward_header_values = list(string)\n forward_cookies = string\n forward_cookies_whitelisted_names = list(string)\n\n lambda_function_association = list(object({\n event_type = string\n include_body = bool\n lambda_arn = string\n }))\n\n function_association = list(object({\n event_type = string\n function_arn = string\n }))\n }))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.\nThe values of primary_origin_id and failover_origin_id must correspond to origin IDs existing in var.s3_origins or var.custom_origins.\n\nIf primary_origin_id is set to null or "", then the origin id of the origin created by this module will be used in its place.\nThis is to allow for the use case of making the origin created by this module the primary origin in an origin group.\nlist(object({\n primary_origin_id = string\n failover_origin_id = string\n failover_criteria = list(string)\n }))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.\nS3 buckets configured as websites are custom_origins, not s3_origins.\nSpecifying s3_origin_config.origin_access_identity as null or "" will have it translated to the origin_access_identity used by the origin created by the module.\nlist(object({\n domain_name = string\n origin_id = string\n origin_path = string\n s3_origin_config = object({\n origin_access_identity = string\n })\n }))false
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

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