• Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language HCL
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Terraform module to create AWS CloudFront resources ๐Ÿ‡บ๐Ÿ‡ฆ

AWS CloudFront Terraform module

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             = true
  is_ipv6_enabled     = true
  price_class         = "PriceClass_All"
  retain_on_delete    = false
  wait_for_deployment = false

  create_origin_access_identity = true
  origin_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 other terraform-aws-modules to create additional resources: S3 buckets, Lambda Functions, CloudFront Functions, ACM Certificate, Route53 Records.

Requirements

Name Version
terraform >= 0.13.1
aws >= 4.29

Providers

Name Version
aws >= 4.29

Modules

No modules.

Resources

Name Type
aws_cloudfront_distribution.this resource
aws_cloudfront_monitoring_subscription.this resource
aws_cloudfront_origin_access_control.this resource
aws_cloudfront_origin_access_identity.this resource

Inputs

Name Description Type Default Required
aliases Extra CNAMEs (alternate domain names), if any, for this distribution. list(string) null no
comment Any comments you want to include about the distribution. string null no
create_distribution Controls if CloudFront distribution should be created bool true no
create_monitoring_subscription If enabled, the resource for monitoring subscription will created. bool false no
create_origin_access_control Controls if CloudFront origin access control should be created bool false no
create_origin_access_identity Controls if CloudFront origin access identity should be created bool false no
custom_error_response One or more custom error response elements any {} no
default_cache_behavior The default cache behavior for this distribution any null no
default_root_object The object that you want CloudFront to return (for example, index.html) when an end user requests the root URL. string null no
enabled Whether the distribution is enabled to accept end user requests for content. bool true no
geo_restriction The restriction configuration for this distribution (geo_restrictions) any {} no
http_version The 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_enabled Whether the IPv6 is enabled for the distribution. bool null no
logging_config The logging configuration that controls how logs are written to your distribution (maximum one). any {} no
ordered_cache_behavior An 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
origin One or more origins for this distribution (multiples allowed). any null no
origin_access_control Map of CloudFront origin access control
map(object({
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_identities Map of CloudFront origin access identities (value as a comment) map(string) {} no
origin_group One or more origin_group for this distribution (multiples allowed). any {} no
price_class The price class for this distribution. One of PriceClass_All, PriceClass_200, PriceClass_100 string null no
realtime_metrics_subscription_status A flag that indicates whether additional CloudWatch metrics are enabled for a given CloudFront distribution. Valid values are Enabled and Disabled. string "Enabled" no
retain_on_delete Disables the distribution instead of deleting it when destroying the resource through Terraform. If this is set, the distribution needs to be deleted manually afterwards. bool false no
tags A map of tags to assign to the resource. map(string) null no
viewer_certificate The SSL configuration for this distribution any
{
"cloudfront_default_certificate": true,
"minimum_protocol_version": "TLSv1"
}
no
wait_for_deployment If enabled, the resource will wait for the distribution status to change from InProgress to Deployed. Setting this to false will skip the process. bool true no
web_acl_id If 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. string null no

Outputs

Name Description
cloudfront_distribution_arn The ARN (Amazon Resource Name) for the distribution.
cloudfront_distribution_caller_reference Internal value used by CloudFront to allow future updates to the distribution configuration.
cloudfront_distribution_domain_name The domain name corresponding to the distribution.
cloudfront_distribution_etag The current version of the distribution's information.
cloudfront_distribution_hosted_zone_id The CloudFront Route 53 zone ID that can be used to route an Alias Resource Record Set to.
cloudfront_distribution_id The identifier for the distribution.
cloudfront_distribution_in_progress_validation_batches The number of invalidation batches currently in progress.
cloudfront_distribution_last_modified_time The date and time the distribution was last modified.
cloudfront_distribution_status The current status of the distribution. Deployed if the distribution's information is fully propagated throughout the Amazon CloudFront system.
cloudfront_distribution_tags Tags of the distribution's
cloudfront_distribution_trusted_signers List of nested attributes for active trusted signers, if the distribution is set up to serve private content with signed URLs
cloudfront_monitoring_subscription_id The ID of the CloudFront monitoring subscription, which corresponds to the distribution_id.
cloudfront_origin_access_controls The origin access controls created
cloudfront_origin_access_controls_ids The IDS of the origin access identities created
cloudfront_origin_access_identities The origin access identities created
cloudfront_origin_access_identity_iam_arns The IAM arns of the origin access identities created
cloudfront_origin_access_identity_ids The IDS of the origin access identities created

Authors

Module is maintained by Anton Babenko with help from these awesome contributors:

License

Apache 2 Licensed. See LICENSE for full details.

More Repositories

1

terraform-aws-eks

Terraform module to create Amazon Elastic Kubernetes (EKS) resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
4,372
star
2

terraform-aws-vpc

Terraform module to create AWS VPC resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
2,949
star
3

terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
899
star
4

terraform-aws-rds

Terraform module to create AWS RDS resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
879
star
5

terraform-aws-iam

Terraform module to create AWS IAM resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
779
star
6

terraform-aws-ec2-instance

Terraform module to create AWS EC2 instance(s) resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
751
star
7

terraform-aws-security-group

Terraform module to create AWS Security Group resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
563
star
8

terraform-aws-ecs

Terraform module to create AWS ECS resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
555
star
9

terraform-aws-atlantis

Terraform module to deploy Atlantis on AWS Fargate ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
519
star
10

terraform-aws-s3-bucket

Terraform module to create AWS S3 resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
511
star
11

terraform-aws-notify-slack

Terraform module to create AWS resources for sending notifications to Slack ๐Ÿ‡บ๐Ÿ‡ฆ
Python
466
star
12

terraform-aws-alb

Terraform module to create AWS Application/Network Load Balancer (ALB/NLB) resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
433
star
13

terraform-aws-rds-aurora

Terraform module to create AWS RDS Aurora resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
384
star
14

terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
292
star
15

terraform-aws-pricing

Terraform module which calculates price of AWS infrastructure (from Terraform state and plan) ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
183
star
16

terraform-aws-acm

Terraform module to create AWS ACM resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
182
star
17

terraform-aws-cloudwatch

Terraform module to create AWS Cloudwatch resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
163
star
18

terraform-aws-elb

Terraform module to create AWS ELB resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
148
star
19

terraform-aws-apigateway-v2

Terraform module to create AWS API Gateway v2 (HTTP/WebSocket) ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
146
star
20

terraform-aws-eventbridge

Terraform module to create AWS EventBridge resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
142
star
21

terraform-aws-transit-gateway

Terraform module to create AWS Transit Gateway resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
141
star
22

terraform-aws-route53

Terraform module to create AWS Route53 resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
126
star
23

terraform-aws-vpn-gateway

Terraform module to create AWS VPN gateway resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
111
star
24

terraform-aws-dynamodb-table

Terraform module to create AWS DynamoDB resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
100
star
25

terraform-aws-sns

Terraform module to create AWS SNS resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
95
star
26

terraform-aws-sqs

Terraform module to create AWS SQS resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
92
star
27

terraform-aws-key-pair

Terraform module to create AWS EC2 key pair resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
83
star
28

terraform-aws-redshift

Terraform module to create AWS Redshift resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
81
star
29

meta

Meta-configurations for repositories, teams, files in terraform-aws-modules organization ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
76
star
30

terraform-aws-solutions

Set of standalone and reusable AWS/DevOps solutions implemented as Terraform modules ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
75
star
31

terraform-aws-step-functions

Terraform module to create AWS Step Functions ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
70
star
32

terraform-aws-dms

Terraform module to create AWS DMS (Database Migration Service) resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
62
star
33

terraform-aws-rds-proxy

Terraform module to create AWS RDS Proxy resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
56
star
34

terraform-aws-msk-kafka-cluster

Terraform module to create AWS MSK (Managed Streaming for Kafka) resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
55
star
35

terraform-aws-datadog-forwarders

Terraform module to create resources on AWS to forward logs/metrics to Datadog ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
53
star
36

terraform-aws-eks-pod-identity

Terraform module to create AWS EKS Pod Identity resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
52
star
37

terraform-aws-appsync

Terraform module to create AWS AWS AppSync resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
50
star
38

terraform-aws-kms

Terraform module to create AWS KMS resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
49
star
39

terraform-aws-ecr

Terraform module to create AWS ECR resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
49
star
40

terraform-aws-managed-service-grafana

Terraform module to create AWS Managed Service for Grafana (AMG) resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
36
star
41

terraform-aws-batch

Terraform module to create AWS Batch resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
35
star
42

terraform-aws-app-runner

Terraform module to create AWS App Runner resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
32
star
43

terraform-aws-secrets-manager

Terraform module to create AWS Secrets Manager resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
28
star
44

terraform-aws-appconfig

Terraform module to create AWS AppConfig resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
27
star
45

terraform-aws-managed-service-prometheus

Terraform module to create AWS Managed Service for Prometheus (AMP) resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
26
star
46

terraform-aws-efs

Terraform module to create AWS EFS resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
24
star
47

terraform-aws-emr

Terraform module to create AWS EMR resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
23
star
48

.github

Meta-GitHub repository for all terraform-aws-modules repositories ๐Ÿ‡บ๐Ÿ‡ฆ
22
star
49

terraform-aws-ssm-parameter

Terraform module to create AWS SSM Parameter resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
20
star
50

terraform-aws-s3-object

Terraform module which creates S3 object resources on AWS
HCL
17
star
51

terraform-aws-ebs-optimized

Terraform module to determine if an instance can be flagged for EBS optimization
HCL
17
star
52

terraform-aws-customer-gateway

Terraform module to create AWS Customer Gateway resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
17
star
53

terraform-aws-global-accelerator

Terraform module to create AWS Global Accelerator resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
16
star
54

terraform-aws-memory-db

Terraform module to create AWS MemoryDB resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
16
star
55

terraform-aws-opensearch

Terraform module to create AWS OpenSearch resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
15
star
56

terraform-aws-elasticache

Terraform module to create AWS ElastiCache resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
12
star
57

terraform-aws-network-firewall

Terraform module to create AWS Network Firewall resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
12
star
58

terraform-aws-fsx

Terraform module to create AWS FSx resources ๐Ÿ‡บ๐Ÿ‡ฆ
HCL
4
star
59

atlantis-demo

Demo repository for Atlantis
3
star