Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Terraform module to create AWS CloudFront resources 🇺🇦

License

NotificationsYou must be signed in to change notification settings

terraform-aws-modules/terraform-aws-cloudfront

Terraform module which creates AWS CloudFront resources with all (or almost all) features provided by Terraform AWS provider.

Usage

CloudFront distribution with versioning enabled

module"cdn" {source="terraform-aws-modules/cloudfront/aws"aliases=["cdn.example.com"]comment="My awesome CloudFront"enabled=trueis_ipv6_enabled=trueprice_class="PriceClass_All"retain_on_delete=falsewait_for_deployment=falsecreate_origin_access_identity=trueorigin_access_identities={    s3_bucket_one="My awesome CloudFront can access"  }logging_config={    bucket="logs-my-cdn.s3.amazonaws.com"  }origin={    something= {      domain_name="something.example.com"      custom_origin_config= {        http_port=80        https_port=443        origin_protocol_policy="match-viewer"        origin_ssl_protocols= ["TLSv1","TLSv1.1","TLSv1.2"]      }    }    s3_one= {      domain_name="my-s3-bycket.s3.amazonaws.com"      s3_origin_config= {        origin_access_identity="s3_bucket_one"      }    }  }default_cache_behavior={    target_origin_id="something"    viewer_protocol_policy="allow-all"    allowed_methods= ["GET","HEAD","OPTIONS"]    cached_methods= ["GET","HEAD"]    compress=true    query_string=true  }ordered_cache_behavior=[    {      path_pattern="/static/*"      target_origin_id="s3_one"      viewer_protocol_policy="redirect-to-https"      allowed_methods= ["GET","HEAD","OPTIONS"]      cached_methods= ["GET","HEAD"]      compress=true      query_string=true    }  ]viewer_certificate={    acm_certificate_arn="arn:aws:acm:us-east-1:135367859851:certificate/1032b155-22da-4ae0-9f69-e206f825458b"    ssl_support_method="sni-only"  }}

Examples

  • Complete - Complete example which creates AWS CloudFront distribution and integrates it with otherterraform-aws-modules to create additional resources: S3 buckets, Lambda Functions, CloudFront Functions, VPC Origins, ACM Certificate, Route53 Records.

Notes

  • Error: updating CloudFront Distribution (ETXXXXXXXXXXXX): InvalidArgument: The parameter ForwardedValues cannot be used when a cache policy is associated to the cache behavior.
    • When defining a behavior inordered_cache_behavior anddefault_cache_behavior with a cache policy, you must specifyuse_forwarded_values = false.
ordered_cache_behavior = [{  path_pattern           = "/my/path"  target_origin_id       = "my-origin"  viewer_protocol_policy = "https-only"  allowed_methods        = ["GET", "HEAD"]  use_forwarded_values   = false  # AllViewerAndCloudFrontHeaders-2022-06  origin_request_policy_id = "33f36d7e-f396-46d9-90e0-52428a34d9dc"  # CachingDisabled  cache_policy_id          = "4135ea2d-6df8-44a3-9df3-4b5a84be39ad"}]

Requirements

NameVersion
terraform>= 1.5.7
aws>= 5.83

Providers

NameVersion
aws>= 5.83

Modules

No modules.

Resources

NameType
aws_cloudfront_distribution.thisresource
aws_cloudfront_monitoring_subscription.thisresource
aws_cloudfront_origin_access_control.thisresource
aws_cloudfront_origin_access_identity.thisresource
aws_cloudfront_vpc_origin.thisresource
aws_cloudfront_cache_policy.thisdata source
aws_cloudfront_origin_request_policy.thisdata source
aws_cloudfront_response_headers_policy.thisdata source

Inputs

NameDescriptionTypeDefaultRequired
aliasesExtra CNAMEs (alternate domain names), if any, for this distribution.list(string)nullno
commentAny comments you want to include about the distribution.stringnullno
continuous_deployment_policy_idIdentifier of a continuous deployment policy. This argument should only be set on a production distribution.stringnullno
create_distributionControls if CloudFront distribution should be createdbooltrueno
create_monitoring_subscriptionIf enabled, the resource for monitoring subscription will created.boolfalseno
create_origin_access_controlControls if CloudFront origin access control should be createdboolfalseno
create_origin_access_identityControls if CloudFront origin access identity should be createdboolfalseno
create_vpc_originIf enabled, the resource for VPC origin will be created.boolfalseno
custom_error_responseOne or more custom error response elementsany{}no
default_cache_behaviorThe default cache behavior for this distributionanynullno
default_root_objectThe object that you want CloudFront to return (for example, index.html) when an end user requests the root URL.stringnullno
enabledWhether the distribution is enabled to accept end user requests for content.booltrueno
geo_restrictionThe restriction configuration for this distribution (geo_restrictions)any{}no
http_versionThe maximum HTTP version to support on the distribution. Allowed values are http1.1, http2, http2and3, and http3. The default is http2.string"http2"no
is_ipv6_enabledWhether the IPv6 is enabled for the distribution.boolnullno
logging_configThe logging configuration that controls how logs are written to your distribution (maximum one).any{}no
ordered_cache_behaviorAn ordered list of cache behaviors resource for this distribution. List from top to bottom in order of precedence. The topmost cache behavior will have precedence 0.any[]no
originOne or more origins for this distribution (multiples allowed).anynullno
origin_access_controlMap of CloudFront origin access control
map(object({
name = optional(string)
description = string
origin_type = string
signing_behavior = string
signing_protocol = string
}))
{
"s3": {
"description": "",
"origin_type": "s3",
"signing_behavior": "always",
"signing_protocol": "sigv4"
}
}
no
origin_access_identitiesMap of CloudFront origin access identities (value as a comment)map(string){}no
origin_groupOne or more origin_group for this distribution (multiples allowed).any{}no
price_classThe price class for this distribution. One of PriceClass_All, PriceClass_200, PriceClass_100stringnullno
realtime_metrics_subscription_statusA flag that indicates whether additional CloudWatch metrics are enabled for a given CloudFront distribution. Valid values areEnabled andDisabled.string"Enabled"no
retain_on_deleteDisables the distribution instead of deleting it when destroying the resource through Terraform. If this is set, the distribution needs to be deleted manually afterwards.boolfalseno
stagingWhether the distribution is a staging distribution.boolfalseno
tagsA map of tags to assign to the resource.map(string)nullno
viewer_certificateThe SSL configuration for this distributionany
{
"cloudfront_default_certificate": true,
"minimum_protocol_version": "TLSv1"
}
no
vpc_originMap of CloudFront VPC origin
map(object({
name = string
arn = string
http_port = number
https_port = number
origin_protocol_policy = string
origin_ssl_protocols = object({
items = list(string)
quantity = number
})
}))
{}no
vpc_origin_timeoutsCreate, update, and delete timeout configurations for vpc originmap(string){}no
wait_for_deploymentIf enabled, the resource will wait for the distribution status to change from InProgress to Deployed. Setting this to false will skip the process.booltrueno
web_acl_idIf you're using AWS WAF to filter CloudFront requests, the Id of the AWS WAF web ACL that is associated with the distribution. The WAF Web ACL must exist in the WAF Global (CloudFront) region and the credentials configuring this argument must have waf:GetWebACL permissions assigned. If using WAFv2, provide the ARN of the web ACL.stringnullno

Outputs

NameDescription
cloudfront_distribution_arnThe ARN (Amazon Resource Name) for the distribution.
cloudfront_distribution_caller_referenceInternal value used by CloudFront to allow future updates to the distribution configuration.
cloudfront_distribution_domain_nameThe domain name corresponding to the distribution.
cloudfront_distribution_etagThe current version of the distribution's information.
cloudfront_distribution_hosted_zone_idThe CloudFront Route 53 zone ID that can be used to route an Alias Resource Record Set to.
cloudfront_distribution_idThe identifier for the distribution.
cloudfront_distribution_in_progress_validation_batchesThe number of invalidation batches currently in progress.
cloudfront_distribution_last_modified_timeThe date and time the distribution was last modified.
cloudfront_distribution_statusThe current status of the distribution. Deployed if the distribution's information is fully propagated throughout the Amazon CloudFront system.
cloudfront_distribution_tagsTags of the distribution's
cloudfront_distribution_trusted_signersList of nested attributes for active trusted signers, if the distribution is set up to serve private content with signed URLs
cloudfront_monitoring_subscription_idThe ID of the CloudFront monitoring subscription, which corresponds to thedistribution_id.
cloudfront_origin_access_controlsThe origin access controls created
cloudfront_origin_access_controls_idsThe IDS of the origin access identities created
cloudfront_origin_access_identitiesThe origin access identities created
cloudfront_origin_access_identity_iam_arnsThe IAM arns of the origin access identities created
cloudfront_origin_access_identity_idsThe IDS of the origin access identities created
cloudfront_vpc_origin_idsThe IDS of the VPC origin created

Authors

Module is maintained byAnton Babenko with help from these awesome contributors:

License

Apache 2 Licensed. SeeLICENSE for full details.

About

Terraform module to create AWS CloudFront resources 🇺🇦

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors37

Languages


[8]ページ先頭

©2009-2025 Movatter.jp