github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/website/source/docs/providers/aws/r/cloudfront_distribution.html.markdown (about)

     1  ---
     2  layout: "aws"
     3  page_title: "AWS: cloudfront_distribution"
     4  sidebar_current: "docs-aws-resource-cloudfront-distribution"
     5  description: |-
     6    Provides a CloudFront web distribution resource.
     7  ---
     8  
     9  # aws\_cloudfront\_distribution
    10  
    11  Creates an Amazon CloudFront web distribution.
    12  
    13  For information about CloudFront distributions, see the
    14  [Amazon CloudFront Developer Guide][1]. For specific information about creating
    15  CloudFront web distributions, see the [POST Distribution][2] page in the Amazon
    16  CloudFront API Reference.
    17  
    18  ~> **NOTE:** CloudFront distributions take about 15 minutes to a deployed state
    19  after creation or modification. During this time, deletes to resources will be
    20  blocked. If you need to delete a distribution that is enabled and you do not
    21  want to wait, you need to use the `retain_on_delete` flag.
    22  
    23  ## Example Usage
    24  
    25  The following example below creates a CloudFront distribution with an S3 origin.
    26  
    27  ```hcl
    28  resource "aws_s3_bucket" "b" {
    29    bucket = "mybucket"
    30    acl    = "private"
    31  
    32    tags {
    33      Name = "My bucket"
    34    }
    35  }
    36  
    37  resource "aws_cloudfront_distribution" "s3_distribution" {
    38    origin {
    39      domain_name = "${aws_s3_bucket.b.bucket_domain_name}"
    40      origin_id   = "myS3Origin"
    41  
    42      s3_origin_config {
    43        origin_access_identity = "origin-access-identity/cloudfront/ABCDEFG1234567"
    44      }
    45    }
    46  
    47    enabled             = true
    48    is_ipv6_enabled     = true
    49    comment             = "Some comment"
    50    default_root_object = "index.html"
    51  
    52    logging_config {
    53      include_cookies = false
    54      bucket          = "mylogs.s3.amazonaws.com"
    55      prefix          = "myprefix"
    56    }
    57  
    58    aliases = ["mysite.example.com", "yoursite.example.com"]
    59  
    60    default_cache_behavior {
    61      allowed_methods  = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
    62      cached_methods   = ["GET", "HEAD"]
    63      target_origin_id = "myS3Origin"
    64  
    65      forwarded_values {
    66        query_string = false
    67  
    68        cookies {
    69          forward = "none"
    70        }
    71      }
    72  
    73      viewer_protocol_policy = "allow-all"
    74      min_ttl                = 0
    75      default_ttl            = 3600
    76      max_ttl                = 86400
    77    }
    78  
    79    price_class = "PriceClass_200"
    80  
    81    restrictions {
    82      geo_restriction {
    83        restriction_type = "whitelist"
    84        locations        = ["US", "CA", "GB", "DE"]
    85      }
    86    }
    87  
    88    tags {
    89      Environment = "production"
    90    }
    91  
    92    viewer_certificate {
    93      cloudfront_default_certificate = true
    94    }
    95  }
    96  ```
    97  
    98  ## Argument Reference
    99  
   100  The CloudFront distribution argument layout is a complex structure composed
   101  of several sub-resources - these resources are laid out below.
   102  
   103  ### Top-Level Arguments
   104  
   105    * `aliases` (Optional) - Extra CNAMEs (alternate domain names), if any, for
   106      this distribution.
   107  
   108    * `cache_behavior` (Optional) - A [cache behavior](#cache-behavior-arguments)
   109      resource for this distribution (multiples allowed).
   110  
   111    * `comment` (Optional) - Any comments you want to include about the
   112      distribution.
   113  
   114    * `custom_error_response` (Optional) - One or more [custom error response](#custom-error-response-arguments) elements (multiples allowed).
   115  
   116    * `default_cache_behavior` (Required) - The [default cache behavior](#default-cache-behavior-arguments) for this distribution (maximum
   117      one).
   118  
   119    * `default_root_object` (Optional) - The object that you want CloudFront to
   120      return (for example, index.html) when an end user requests the root URL.
   121  
   122    * `enabled` (Required) - Whether the distribution is enabled to accept end
   123      user requests for content.
   124  
   125    * `is_ipv6_enabled` (Optional) - Whether the IPv6 is enabled for the distribution.
   126  
   127    * `http_version` (Optional) - The maximum HTTP version to support on the
   128      distribution. Allowed values are `http1.1` and `http2`. The default is
   129      `http2`.
   130  
   131    * `logging_config` (Optional) - The [logging
   132      configuration](#logging-config-arguments) that controls how logs are written
   133      to your distribution (maximum one).
   134  
   135    * `origin` (Required) - One or more [origins](#origin-arguments) for this
   136      distribution (multiples allowed).
   137  
   138    * `price_class` (Optional) - The price class for this distribution. One of
   139      `PriceClass_All`, `PriceClass_200`, `PriceClass_100`
   140  
   141    * `restrictions` (Required) - The [restriction
   142      configuration](#restrictions-arguments) for this distribution (maximum one).
   143  
   144    * `tags` - (Optional) A mapping of tags to assign to the resource.
   145  
   146    * `viewer_certificate` (Required) - The [SSL
   147      configuration](#viewer-certificate-arguments) for this distribution (maximum
   148      one).
   149  
   150    * `web_acl_id` (Optional) - If you're using AWS WAF to filter CloudFront
   151      requests, the Id of the AWS WAF web ACL that is associated with the
   152      distribution.
   153  
   154    * `retain_on_delete` (Optional) - Disables the distribution instead of
   155      deleting it when destroying the resource through Terraform. If this is set,
   156      the distribution needs to be deleted manually afterwards. Default: `false`.
   157  
   158  #### Cache Behavior Arguments
   159  
   160    * `allowed_methods` (Required) - Controls which HTTP methods CloudFront
   161      processes and forwards to your Amazon S3 bucket or your custom origin.
   162  
   163    * `cached_methods` (Required) - Controls whether CloudFront caches the
   164      response to requests using the specified HTTP methods.
   165  
   166    * `compress` (Optional) - Whether you want CloudFront to automatically
   167      compress content for web requests that include `Accept-Encoding: gzip` in
   168      the request header (default: `false`).
   169  
   170    * `default_ttl` (Required) - The default amount of time (in seconds) that an
   171      object is in a CloudFront cache before CloudFront forwards another request
   172      in the absence of an `Cache-Control max-age` or `Expires` header.
   173  
   174    * `forwarded_values` (Required) - The [forwarded values configuration](#forwarded-values-arguments) that specifies how CloudFront
   175      handles query strings, cookies and headers (maximum one).
   176  
   177    * `lambda_function_association` (Optional) - A config block that triggers a lambda function with
   178    specific actions. Defined below, maximum 4. **Lambda@Edge is in technical
   179    Preview, and must be enabled on your AWS account to be used**
   180  
   181    * `max_ttl` (Required) - The maximum amount of time (in seconds) that an
   182      object is in a CloudFront cache before CloudFront forwards another request
   183      to your origin to determine whether the object has been updated. Only
   184      effective in the presence of `Cache-Control max-age`, `Cache-Control
   185      s-maxage`, and `Expires` headers.
   186  
   187    * `min_ttl` (Required) - The minimum amount of time that you want objects to
   188      stay in CloudFront caches before CloudFront queries your origin to see
   189      whether the object has been updated.
   190  
   191    * `path_pattern` (Required) - The pattern (for example, `images/*.jpg)` that
   192      specifies which requests you want this cache behavior to apply to.
   193  
   194    * `smooth_streaming` (Optional) - Indicates whether you want to distribute
   195      media files in Microsoft Smooth Streaming format using the origin that is
   196      associated with this cache behavior.
   197  
   198    * `target_origin_id` (Required) - The value of ID for the origin that you want
   199      CloudFront to route requests to when a request matches the path pattern
   200      either for a cache behavior or for the default cache behavior.
   201  
   202    * `trusted_signers` (Optional) - The AWS accounts, if any, that you want to
   203      allow to create signed URLs for private content.
   204  
   205    * `viewer_protocol_policy` (Required) - Use this element to specify the
   206      protocol that users can use to access the files in the origin specified by
   207      TargetOriginId when a request matches the path pattern in PathPattern. One
   208      of `allow-all`, `https-only`, or `redirect-to-https`.
   209  
   210  ##### Forwarded Values Arguments
   211  
   212    * `cookies` (Required) - The [forwarded values cookies](#cookies-arguments)
   213      that specifies how CloudFront handles cookies (maximum one).
   214  
   215    * `headers` (Optional) - Specifies the Headers, if any, that you want
   216      CloudFront to vary upon for this cache behavior. Specify `*` to include all
   217      headers.
   218  
   219    * `query_string` (Required) - Indicates whether you want CloudFront to forward
   220      query strings to the origin that is associated with this cache behavior.
   221  
   222    * `query_string_cache_keys` (Optional) - When specified, along with a value of
   223      `true` for `query_string`, all query strings are forwarded, however only the
   224      query string keys listed in this argument are cached. When omitted with a
   225      value of `true` for `query_string`, all query string keys are cached.
   226  
   227  ##### Lambda Function Association
   228  
   229  Lambda@Edge allows you to associate an AWS Lambda Function with a predefined
   230  event. You can associate a single function per event type. See [What is
   231  Lambda@Edge](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/what-is-lambda-at-edge.html)
   232  for more information
   233  
   234    * `event_type` (Required) - The specific event to trigger this function.
   235    Valid values: `viewer-request`, `origin-request`, `viewer-response`,
   236    `origin-response`
   237  
   238    * `lambda_arn` (Required) - ARN of the Lambda function.
   239  
   240  ##### Cookies Arguments
   241  
   242    * `forward` (Required) - Specifies whether you want CloudFront to forward
   243      cookies to the origin that is associated with this cache behavior. You can
   244      specify `all`, `none` or `whitelist`. If `whitelist`, you must include the
   245      subsequent `whitelisted_names`
   246  
   247    * `whitelisted_names` (Optional) - If you have specified `whitelist` to
   248      `forward`, the whitelisted cookies that you want CloudFront to forward to
   249      your origin.
   250  
   251  #### Custom Error Response Arguments
   252  
   253    * `error_caching_min_ttl` (Optional) - The minimum amount of time you want
   254      HTTP error codes to stay in CloudFront caches before CloudFront queries your
   255      origin to see whether the object has been updated.
   256  
   257    * `error_code` (Required) - The 4xx or 5xx HTTP status code that you want to
   258      customize.
   259  
   260    * `response_code` (Optional) - The HTTP status code that you want CloudFront
   261      to return with the custom error page to the viewer.
   262  
   263    * `response_page_path` (Optional) - The path of the custom error page (for
   264      example, `/custom_404.html`).
   265  
   266  #### Default Cache Behavior Arguments
   267  
   268  The arguments for `default_cache_behavior` are the same as for
   269  [`cache_behavior`](#cache-behavior-arguments), except for the `path_pattern`
   270  argument is not required.
   271  
   272  #### Logging Config Arguments
   273  
   274    * `bucket` (Required) - The Amazon S3 bucket to store the access logs in, for
   275      example, `myawslogbucket.s3.amazonaws.com`.
   276  
   277    * `include_cookies` (Optional) - Specifies whether you want CloudFront to
   278      include cookies in access logs (default: `false`).
   279  
   280    * `prefix` (Optional) - An optional string that you want CloudFront to prefix
   281      to the access log filenames for this distribution, for example, `myprefix/`.
   282  
   283  #### Origin Arguments
   284  
   285    * `custom_origin_config` - The [CloudFront custom
   286      origin](#custom-origin-config-arguments) configuration information. If an S3
   287      origin is required, use `s3_origin_config` instead.
   288  
   289    * `domain_name` (Required) - The DNS domain name of either the S3 bucket, or
   290      web site of your custom origin.
   291  
   292    * `custom_header` (Optional) - One or more sub-resources with `name` and
   293      `value` parameters that specify header data that will be sent to the origin
   294      (multiples allowed).
   295  
   296    * `origin_id` (Required) - A unique identifier for the origin.
   297  
   298    * `origin_path` (Optional) - An optional element that causes CloudFront to
   299      request your content from a directory in your Amazon S3 bucket or your
   300      custom origin.
   301  
   302    * `s3_origin_config` - The [CloudFront S3 origin](#s3-origin-config-arguments)
   303      configuration information. If a custom origin is required, use
   304      `custom_origin_config` instead.
   305  
   306  ##### Custom Origin Config Arguments
   307  
   308    * `http_port` (Required) - The HTTP port the custom origin listens on.
   309  
   310    * `https_port` (Required) - The HTTPS port the custom origin listens on.
   311  
   312    * `origin_protocol_policy` (Required) - The origin protocol policy to apply to
   313      your origin. One of `http-only`, `https-only`, or `match-viewer`.
   314  
   315    * `origin_ssl_protocols` (Required) - The SSL/TLS protocols that you want
   316      CloudFront to use when communicating with your origin over HTTPS. A list of
   317      one or more of `SSLv3`, `TLSv1`, `TLSv1.1`, and `TLSv1.2`.
   318  
   319    * `origin_keepalive_timeout` - (Optional) The Custom KeepAlive timeout, in seconds. Value must be between `1` and `60`.
   320  
   321    * `origin_read_timeout` - (Optional) The Custom Read timeout, in seconds. Value must be between `4` and `60`.
   322  
   323  ##### S3 Origin Config Arguments
   324  
   325  * `origin_access_identity` (Optional) - The [CloudFront origin access
   326    identity][5] to associate with the origin.
   327  
   328  #### Restrictions Arguments
   329  
   330  The `restrictions` sub-resource takes another single sub-resource named
   331  `geo_restriction` (see the example for usage).
   332  
   333  The arguments of `geo_restriction` are:
   334  
   335    * `locations` (Optional) - The [ISO 3166-1-alpha-2 codes][4] for which you
   336      want CloudFront either to distribute your content (`whitelist`) or not
   337      distribute your content (`blacklist`).
   338  
   339    * `restriction_type` (Required) - The method that you want to use to restrict
   340      distribution of your content by country: `none`, `whitelist`, or
   341      `blacklist`.
   342  
   343  #### Viewer Certificate Arguments
   344  
   345    * `acm_certificate_arn` - The ARN of the [AWS Certificate Manager][6]
   346      certificate that you wish to use with this distribution. Specify this,
   347      `cloudfront_default_certificate`, or `iam_certificate_id`.  The ACM
   348      certificate must be in  US-EAST-1.
   349  
   350    * `cloudfront_default_certificate` - `true` if you want viewers to use HTTPS
   351      to request your objects and you're using the CloudFront domain name for your
   352      distribution. Specify this, `acm_certificate_arn`, or `iam_certificate_id`.
   353  
   354    * `iam_certificate_id` - The IAM certificate identifier of the custom viewer
   355      certificate for this distribution if you are using a custom domain. Specify
   356      this, `acm_certificate_arn`, or `cloudfront_default_certificate`.
   357  
   358    * `minimum_protocol_version` - The minimum version of the SSL protocol that
   359      you want CloudFront to use for HTTPS connections. One of `SSLv3` or `TLSv1`.
   360      Default: `SSLv3`. **NOTE**: If you are using a custom certificate (specified
   361      with `acm_certificate_arn` or `iam_certificate_id`), and have specified
   362      `sni-only` in `ssl_support_method`, `TLSv1` must be specified.
   363  
   364    * `ssl_support_method`: Specifies how you want CloudFront to serve HTTPS
   365      requests. One of `vip` or `sni-only`. Required if you specify
   366      `acm_certificate_arn` or `iam_certificate_id`. **NOTE:** `vip` causes
   367      CloudFront to use a dedicated IP address and may incur extra charges.
   368  
   369  ## Attribute Reference
   370  
   371  The following attributes are exported:
   372  
   373    * `id` - The identifier for the distribution. For example: `EDFDVBD632BHDS5`.
   374  
   375    * `arn` - The ARN (Amazon Resource Name) for the distribution. For example: arn:aws:cloudfront::123456789012:distribution/EDFDVBD632BHDS5, where 123456789012 is your AWS account ID.
   376  
   377    * `caller_reference` - Internal value used by CloudFront to allow future
   378      updates to the distribution configuration.
   379  
   380    * `status` - The current status of the distribution. `Deployed` if the
   381      distribution's information is fully propagated throughout the Amazon
   382      CloudFront system.
   383  
   384    * `active_trusted_signers` - The key pair IDs that CloudFront is aware of for
   385      each trusted signer, if the distribution is set up to serve private content
   386      with signed URLs.
   387  
   388    * `domain_name` - The domain name corresponding to the distribution. For
   389      example: `d604721fxaaqy9.cloudfront.net`.
   390  
   391    * `last_modified_time` - The date and time the distribution was last modified.
   392  
   393    * `in_progress_validation_batches` - The number of invalidation batches
   394      currently in progress.
   395  
   396    * `etag` - The current version of the distribution's information. For example:
   397      `E2QWRUHAPOMQZL`.
   398  
   399    * `hosted_zone_id` - The CloudFront Route 53 zone ID that can be used to
   400       route an [Alias Resource Record Set][7] to. This attribute is simply an
   401       alias for the zone ID `Z2FDTNDATAQYW2`.
   402  
   403  
   404  [1]: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html
   405  [2]: http://docs.aws.amazon.com/AmazonCloudFront/latest/APIReference/CreateDistribution.html
   406  [3]: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html
   407  [4]: http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm
   408  [5]: /docs/providers/aws/r/cloudfront_origin_access_identity.html
   409  [6]: https://aws.amazon.com/certificate-manager/
   410  [7]: http://docs.aws.amazon.com/Route53/latest/APIReference/CreateAliasRRSAPI.html
   411  
   412  
   413  ## Import
   414  
   415  Cloudfront Distributions can be imported using the `id`, e.g.
   416  
   417  ```
   418  $ terraform import aws_cloudfront_distribution.distribution E74FTE3EXAMPLE
   419  ```