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