diff --git a/.gitignore b/.gitignore index cfc0ea00..2c9c0f8c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ # Module directory .idea *.iml -**/.terraform \ No newline at end of file +**/.terraform + +.build-harness +build-harness \ No newline at end of file diff --git a/Makefile b/Makefile index b0f7470c..655f6303 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ SHELL := /bin/bash +# List of targets the `readme` target should call before generating the readme +export README_DEPS ?= docs/targets.md docs/terraform.md + -include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness) +## Lint terraform code lint: - $(SELF) terraform:install terraform:get-modules terraform:get-plugins terraform:lint terraform:validate + $(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate \ No newline at end of file diff --git a/README.md b/README.md index 6e89bffb..394e6a6c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,23 @@ -# terraform-aws-cloudfront-s3-cdn [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-cloudfront-s3-cdn.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-cloudfront-s3-cdn) + + +[![Cloud Posse](https://cloudposse.com/logo-300x69.png)](https://cloudposse.com) + +# terraform-aws-cloudfront-s3-cdn [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-cloudfront-s3-cdn.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-cloudfront-s3-cdn) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-cloudfront-s3-cdn.svg)](https://travis-ci.org/cloudposse/terraform-aws-cloudfront-s3-cdn/releases) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) + Terraform module to easily provision an AWS CloudFront CDN with an S3 or custom origin. +--- + +This project is part of our comprehensive ["SweetOps"](https://docs.cloudposse.com) approach towards DevOps. + + +It's 100% Open Source and licensed under the [APACHE2](LICENSE). + + + + ## Usage ```hcl @@ -43,76 +58,208 @@ If there are warnings around the outputs when destroying using this module. Then you can use this method for supressing the superfluous errors. `TF_WARN_OUTPUT_ERRORS=1 terraform destroy` -## Variables - -| Name | Default | Description | Required | -|:-------------------------------|:----------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------:| -| `namespace` | `` | Namespace (e.g. `cp` or `cloudposse`) | Yes | -| `stage` | `` | Stage (e.g. `prod`, `dev`, `staging`) | Yes | -| `name` | `` | Name (e.g. `bastion` or `db`) | Yes | -| `attributes` | `[]` | Additional attributes (e.g. `policy` or `role`) | No | -| `tags` | `{}` | Additional tags (e.g. `map("BusinessUnit","XYZ")` | No | -| `acm_certificate_arn` | `` | Existing ACM Certificate ARN | No | -| `aliases` | `[]` | List of aliases as a FQDN (e.g. `["www.example.com"]`) | Yes | -| `allowed_methods` | `["*"]` | List of allowed methods (e.g. ` GET, PUT, POST, DELETE, HEAD`) for AWS CloudFront | No | -| `cached_methods` | `["GET", "HEAD"]` | List of cached methods (e.g. ` GET, PUT, POST, DELETE, HEAD`) | No | -| `comment` | `Managed by Terraform` | Comment for the origin access identity | No | -| `compress` | `false` | Compress content for web requests that include Accept-Encoding: gzip in the request header | No | -| `cors_allowed_headers` | `["*"]` | List of allowed headers for S3 bucket | No | -| `cors_allowed_methods` | `["GET"]` | List of allowed methods (e.g. ` GET, PUT, POST, DELETE, HEAD`) for S3 bucket | No | -| `cors_allowed_origins` | `["*"]` | List of allowed origins (e.g. ` example.com, test.com`) for S3 bucket | No | -| `cors_max_age_seconds` | `3600` | Time in seconds that browser can cache the response for S3 bucket | No | -| `cors_expose_headers` | `["ETag"]` | List of expose header in the response for S3 bucket | No | -| `bucket_domain_format` | `%s.s3.amazonaws.com` | Format of bucket domain name | No | -| `default_root_object` | `index.html` | Object that CloudFront return when requests the root URL | No | -| `enabled` | `true` | State of CloudFront | No | -| `forward_cookies` | `none` | Forward cookies to the origin that is associated with this cache behavior | No | -| `forward_query_string` | `false` | Forward query strings to the origin that is associated with this cache behavior | No | -| `geo_restriction_locations` | `[]` | List of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist) | No | -| `geo_restriction_type` | `none` | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | No | -| `is_ipv6_enabled` | `true` | State of CloudFront IPv6 | No | -| `log_standard_transition_days` | `30` | Number of days to persist in the standard storage tier before moving to the glacier tier | No | -| `log_glacier_transition_days` | `60` | Number of days to persist in the standard storage tier before moving to the infrequent access | No | -| `log_expiration_days` | `90` | Number of days after which to expunge the objects | No | -| `log_include_cookies` | `false` | Include cookies in access logs | No | -| `log_prefix` | `` | Path of logs in S3 bucket | No | -| `min_ttl` | `0` | Minimum amount of time that you want objects to stay in CloudFront caches | No | -| `default_ttl` | `60` | Default amount of time (in seconds) that an object is in a CloudFront cache | No | -| `max_ttl` | `31536000` | Maximum amount of time (in seconds) that an object is in a CloudFront cache | No | -| `null` | `` | Empty string | No | -| `price_class` | `PriceClass_100` | Price class for this distribution: `PriceClass_All`, `PriceClass_200`, `PriceClass_100` | No | -| `viewer_protocol_policy` | `redirect-to-https` | Element to specify the protocol: `allow-all`, `https-only`, `redirect-to-https` | No | -| `null` | `` | Empty string | No | -| `origin_force_destroy` | `` | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | No | -| `origin_bucket` | `` | Name of S3 bucket | No | -| `origin_path` | `` | Element that causes CloudFront to request your content from a directory in your Amazon S3 bucket. Begins with `/`. CAUTION! Do not use bare `/` as `origin_path`. | No | -| `parent_zone_id` | `` | ID of the hosted zone to contain this record (or specify `parent_zone_name`) | Yes | -| `parent_zone_name` | `` | Name of the hosted zone to contain this record (or specify `parent_zone_id`) | Yes | -| `use_regional_s3_endpoint` | `"false"` | Use a regional endpoint for the bucket instead of the global endpoint. Useful for speeding up the deploy process caused by the s3 replication latency | No | + + + +## Makefile Targets +``` +Available targets: + + help This help screen + help/all Display help for all targets + lint Lint terraform code + +``` + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| acm_certificate_arn | Existing ACM Certificate ARN | string | `` | no | +| aliases | List of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfront | list | `` | no | +| allowed_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront | list | `` | no | +| attributes | Additional attributes (e.g. `policy` or `role`) | list | `` | no | +| bucket_domain_format | Format of bucket domain name | string | `%s.s3.amazonaws.com` | no | +| cached_methods | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | list | `` | no | +| comment | Comment for the origin access identity | string | `Managed by Terraform` | no | +| compress | Compress content for web requests that include Accept-Encoding: gzip in the request header | string | `false` | no | +| cors_allowed_headers | List of allowed headers for S3 bucket | list | `` | no | +| cors_allowed_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for S3 bucket | list | `` | no | +| cors_allowed_origins | List of allowed origins (e.g. example.com, test.com) for S3 bucket | list | `` | no | +| cors_expose_headers | List of expose header in the response for S3 bucket | list | `` | no | +| cors_max_age_seconds | Time in seconds that browser can cache the response for S3 bucket | string | `3600` | no | +| default_root_object | Object that CloudFront return when requests the root URL | string | `index.html` | no | +| default_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | string | `60` | no | +| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no | +| enabled | Select Enabled if you want CloudFront to begin processing requests as soon as the distribution is created, or select Disabled if you do not want CloudFront to begin processing requests after the distribution is created. | string | `true` | no | +| forward_cookies | Time in seconds that browser can cache the response for S3 bucket | string | `none` | no | +| forward_query_string | Forward query strings to the origin that is associated with this cache behavior | string | `false` | no | +| geo_restriction_locations | List of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist) | list | `` | no | +| geo_restriction_type | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | string | `none` | no | +| is_ipv6_enabled | State of CloudFront IPv6 | string | `true` | no | +| log_expiration_days | Number of days after which to expunge the objects | string | `90` | no | +| log_glacier_transition_days | Number of days after which to move the data to the glacier storage tier | string | `60` | no | +| log_include_cookies | Include cookies in access logs | string | `false` | no | +| log_prefix | Path of logs in S3 bucket | string | `` | no | +| log_standard_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier | string | `30` | no | +| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | string | `31536000` | no | +| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | string | `0` | no | +| name | Name (e.g. `bastion` or `db`) | string | - | yes | +| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes | +| null | an empty string | string | `` | no | +| origin_bucket | Name of S3 bucket | string | `` | no | +| origin_force_destroy | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | string | `false` | no | +| origin_path | (Optional) - An 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. | string | `` | no | +| parent_zone_id | ID of the hosted zone to contain this record (or specify `parent_zone_name`) | string | `` | no | +| parent_zone_name | Name of the hosted zone to contain this record (or specify `parent_zone_id`) | string | `` | no | +| price_class | Price class for this distribution: `PriceClass_All`, `PriceClass_200`, `PriceClass_100` | string | `PriceClass_100` | no | +| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes | +| static_s3_bucket | aws-cli is a bucket owned by amazon that will perminantly exist It allows for the data source to be called during the destruction process without failing. It doesn't get used for anything else, this is a safe workaround for handling the fact that if a data source like the one `aws_s3_bucket.selected` gets an error, you can't continue the terraform process which also includes the 'destroy' command, where is doesn't even need this data source! Don't change this bucket name, its a variable so that we can provide this description. And this works around a problem that is an edge case. | string | `aws-cli` | no | +| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `` | no | +| use_regional_s3_endpoint | When set to 'true' the s3 origin_bucket will use the regional endpoint address instead of the global endpoint address | string | `false` | no | +| viewer_protocol_policy | allow-all, redirect-to-https | string | `redirect-to-https` | no | + ## Outputs -| Name | Description | -|:------------------------|:--------------------------------------------------| -| `cf_arn` | ID of AWS CloudFront distribution | -| `cf_domain_name` | Domain name corresponding to the distribution | -| `cf_etag` | Current version of the distribution's information | -| `cf_hosted_zone_id` | CloudFront Route 53 zone ID | -| `cf_id` | ID of AWS CloudFront distribution | -| `cf_status` | Current status of the distribution | -| `s3_bucket` | Name of S3 bucket | -| `s3_bucket_domain_name` | Domain of S3 bucket | +| Name | Description | +|------|-------------| +| cf_arn | ARN of AWS CloudFront distribution | +| cf_domain_name | Domain name corresponding to the distribution | +| cf_etag | Current version of the distribution's information | +| cf_hosted_zone_id | CloudFront Route 53 zone ID | +| cf_id | ID of AWS CloudFront distribution | +| cf_status | Current status of the distribution | +| s3_bucket | Name of S3 bucket | +| s3_bucket_domain_name | Domain of S3 bucket | + + + + +## Related Projects + +Check out these related projects. + +- [terraform-aws-cloudfront-cdn](https://github.com/cloudposse/terraform-aws-cloudfront-cdn) - Terraform Module that implements a CloudFront Distribution (CDN) for a custom origin. +- [terraform-aws-s3-log-storage](https://github.com/cloudposse/terraform-aws-s3-log-storage) - S3 bucket with built in IAM policy to allow CloudTrail logs + + +## Help + +**Got a question?** + +File a GitHub [issue](https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn/issues), send us an [email][email] or join our [Slack Community][slack]. + +## Commerical Support + +Work directly with our team of DevOps experts via email, slack, and video conferencing. + +We provide *commercial support* for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a fulltime engineer. + +[![E-Mail](https://img.shields.io/badge/email-hello@cloudposse.com-blue.svg)](mailto:hello@cloudposse.com) + +- **Questions.** We'll use a Shared Slack channel between your team and ours. +- **Troubleshooting.** We'll help you triage why things aren't working. +- **Code Reviews.** We'll review your Pull Requests and provide constructive feedback. +- **Bug Fixes.** We'll rapidly work to fix any bugs in our projects. +- **Build New Terraform Modules.** We'll develop original modules to provision infrastructure. +- **Cloud Architecture.** We'll assist with your cloud strategy and design. +- **Implementation.** We'll provide hands on support to implement our reference architectures. + + +## Community Forum + +Get access to our [Open Source Community Forum][slack] on Slack. It's **FREE** to join for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build *sweet* infrastructure. + +## Contributing + +### Bug Reports & Feature Requests + +Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn/issues) to report any bugs or file feature requests. + +### Developing + +If you are interested in being a contributor and want to get involved in developing this project or [help out](https://github.com/orgs/cloudposse/projects/3) with our other projects, we would love to hear from you! Shoot us an [email](mailto:hello@cloudposse.com). + +In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. + + 1. **Fork** the repo on GitHub + 2. **Clone** the project to your own machine + 3. **Commit** changes to your own branch + 4. **Push** your work back up to your fork + 5. Submit a **Pull Request** so that we can review your changes + +**NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request! + +## Copyright + +Copyright © 2017-2018 [Cloud Posse, LLC](https://cloudposse.com) + + +## License + +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + +See [LICENSE](LICENSE) for full details. + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + + +## Trademarks + +All other trademarks referenced herein are the property of their respective owners. + +## About + +This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at + +[![Cloud Posse](https://cloudposse.com/logo-300x69.png)](https://cloudposse.com) + +We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We love [Open Source Software](https://github.com/cloudposse/)! + +We offer paid support on all of our projects. + +Check out [our other projects][github], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation. + [docs]: https://docs.cloudposse.com/ + [website]: https://cloudposse.com/ + [github]: https://github.com/cloudposse/ + [jobs]: https://cloudposse.com/jobs/ + [hire]: https://cloudposse.com/contact/ + [slack]: https://slack.cloudposse.com/ + [linkedin]: https://www.linkedin.com/company/cloudposse + [twitter]: https://twitter.com/cloudposse/ + [email]: mailto:hello@cloudposse.com -## Known Issues -If the bucket is created in a region other than `us-east-1`, it will take a while for the distribution to become fully operational. +### Contributors -> All buckets have at least two REST endpoint hostnames. In eu-west-1, they are example-bucket.s3-eu-west-1.amazonaws.com and example-bucket.s3.amazonaws.com. The first one will be immediately valid when the bucket is created. The second one -- sometimes referred to as the "global endpoint" -- which is the one CloudFront uses -- will not, unless the bucket is in us-east-1. Over a period of seconds to minutes, variable by location and other factors, it becomes globally accessible as well. Before that, the 307 redirect is returned. Hence, the bucket was not ready. +| [![Erik Osterman][osterman_avatar]](osterman_homepage)
[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]](aknysh_homepage)
[Andriy Knysh][aknysh_homepage] | [![Jamie Nelson][Jamie-BitFlight_avatar]](Jamie-BitFlight_homepage)
[Jamie Nelson][Jamie-BitFlight_homepage] | [![Clive Zagno][cliveza_avatar]](cliveza_homepage)
[Clive Zagno][cliveza_homepage] | +|---|---|---|---| -Via: https://stackoverflow.com/questions/38706424/aws-cloudfront-returns-http-307-when-origin-is-s3-bucket + [osterman_homepage]: https://github.com/osterman + [osterman_avatar]: https://github.com/osterman.png?size=150 + [aknysh_homepage]: https://github.com/aknysh + [aknysh_avatar]: https://github.com/aknysh.png?size=150 + [Jamie-BitFlight_homepage]: https://github.com/Jamie-BitFlight + [Jamie-BitFlight_avatar]: https://github.com/Jamie-BitFlight.png?size=150 + [cliveza_homepage]: https://github.com/cliveza + [cliveza_avatar]: https://github.com/cliveza.png?size=150 -## Workaround for Known Issues -To use the regional endpoint name instead of the global bucket name in this module, set `use_regional_s3_endpoint = "true"` in the module. diff --git a/README.yaml b/README.yaml new file mode 100644 index 00000000..8c5f0e60 --- /dev/null +++ b/README.yaml @@ -0,0 +1,96 @@ +--- +# +# This is the canonical configuration for the `README.md` +# Run `make readme` to rebuild the `README.md` +# + +# Name of this project +name: terraform-aws-cloudfront-s3-cdn + +# Logo for this project +#logo: docs/logo.png + +# License of this project +license: "APACHE2" + +# Canonical GitHub repo +github_repo: cloudposse/terraform-aws-cloudfront-s3-cdn + +# Badges to display +badges: + - name: "Build Status" + image: "https://travis-ci.org/cloudposse/terraform-aws-cloudfront-s3-cdn.svg?branch=master" + url: "https://travis-ci.org/cloudposse/terraform-aws-cloudfront-s3-cdn" + - name: "Latest Release" + image: "https://img.shields.io/github/release/cloudposse/terraform-aws-cloudfront-s3-cdn.svg" + url: "https://travis-ci.org/cloudposse/terraform-aws-cloudfront-s3-cdn/releases" + - name: "Slack Community" + image: "https://slack.cloudposse.com/badge.svg" + url: "https://slack.cloudposse.com" + +related: + - name: "terraform-aws-cloudfront-cdn" + description: "Terraform Module that implements a CloudFront Distribution (CDN) for a custom origin." + url: "https://github.com/cloudposse/terraform-aws-cloudfront-cdn" + - name: "terraform-aws-s3-log-storage" + description: "S3 bucket with built in IAM policy to allow CloudTrail logs" + url: "https://github.com/cloudposse/terraform-aws-s3-log-storage" + +# Short description of this project +description: |- + Terraform module to easily provision an AWS CloudFront CDN with an S3 or custom origin. + +# How to use this project +usage: |- + ```hcl + module "cdn" { + source = "git::https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn.git?ref=master" + namespace = "${var.namespace}" + stage = "${var.stage}" + name = "${var.name}" + aliases = "${var.hostname}" + parent_zone_name = "${var.parent_zone_name}" + } + ``` + + Full working example can be found in [example](./example) folder. + + ### Generating ACM Certificate + + Use the AWS cli to [request new ACM certifiates](http://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request.html) (requires email validation) + ``` + aws acm request-certificate --domain-name example.com --subject-alternative-names a.example.com b.example.com *.c.example.com + ``` + + + + __NOTE__: + + Although AWS Certificate Manager is supported in many AWS regions, to use an SSL certificate with CloudFront, it should be requested only in US East (N. Virginia) region. + + https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cnames-and-https-requirements.html + > If you want to require HTTPS between viewers and CloudFront, you must change the AWS region to US East (N. Virginia) in the AWS Certificate Manager console before you request or import a certificate. + + https://docs.aws.amazon.com/acm/latest/userguide/acm-regions.html + > To use an ACM Certificate with Amazon CloudFront, you must request or import the certificate in the US East (N. Virginia) region. ACM Certificates in this region that are associated with a CloudFront distribution are distributed to all the geographic locations configured for that distribution. + + This is a fundamental requirement of CloudFront, and you will need to request the certificate in `us-east-1` region. + + If there are warnings around the outputs when destroying using this module. + Then you can use this method for supressing the superfluous errors. + `TF_WARN_OUTPUT_ERRORS=1 terraform destroy` + +include: + - "docs/targets.md" + - "docs/terraform.md" + +# Contributors to this project +contributors: + - name: "Erik Osterman" + github: "osterman" + - name: "Andriy Knysh" + github: "aknysh" + - name: "Jamie Nelson" + github: "Jamie-BitFlight" + - name: "Clive Zagno" + github: "cliveza" diff --git a/docs/targets.md b/docs/targets.md new file mode 100644 index 00000000..09c39cd6 --- /dev/null +++ b/docs/targets.md @@ -0,0 +1,9 @@ +## Makefile Targets +``` +Available targets: + + help This help screen + help/all Display help for all targets + lint Lint terraform code + +``` diff --git a/docs/terraform.md b/docs/terraform.md new file mode 100644 index 00000000..9f88d61a --- /dev/null +++ b/docs/terraform.md @@ -0,0 +1,62 @@ + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| acm_certificate_arn | Existing ACM Certificate ARN | string | `` | no | +| aliases | List of FQDN's - Used to set the Alternate Domain Names (CNAMEs) setting on Cloudfront | list | `` | no | +| allowed_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront | list | `` | no | +| attributes | Additional attributes (e.g. `policy` or `role`) | list | `` | no | +| bucket_domain_format | Format of bucket domain name | string | `%s.s3.amazonaws.com` | no | +| cached_methods | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | list | `` | no | +| comment | Comment for the origin access identity | string | `Managed by Terraform` | no | +| compress | Compress content for web requests that include Accept-Encoding: gzip in the request header | string | `false` | no | +| cors_allowed_headers | List of allowed headers for S3 bucket | list | `` | no | +| cors_allowed_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for S3 bucket | list | `` | no | +| cors_allowed_origins | List of allowed origins (e.g. example.com, test.com) for S3 bucket | list | `` | no | +| cors_expose_headers | List of expose header in the response for S3 bucket | list | `` | no | +| cors_max_age_seconds | Time in seconds that browser can cache the response for S3 bucket | string | `3600` | no | +| default_root_object | Object that CloudFront return when requests the root URL | string | `index.html` | no | +| default_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | string | `60` | no | +| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no | +| enabled | Select Enabled if you want CloudFront to begin processing requests as soon as the distribution is created, or select Disabled if you do not want CloudFront to begin processing requests after the distribution is created. | string | `true` | no | +| forward_cookies | Time in seconds that browser can cache the response for S3 bucket | string | `none` | no | +| forward_query_string | Forward query strings to the origin that is associated with this cache behavior | string | `false` | no | +| geo_restriction_locations | List of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist) | list | `` | no | +| geo_restriction_type | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | string | `none` | no | +| is_ipv6_enabled | State of CloudFront IPv6 | string | `true` | no | +| log_expiration_days | Number of days after which to expunge the objects | string | `90` | no | +| log_glacier_transition_days | Number of days after which to move the data to the glacier storage tier | string | `60` | no | +| log_include_cookies | Include cookies in access logs | string | `false` | no | +| log_prefix | Path of logs in S3 bucket | string | `` | no | +| log_standard_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier | string | `30` | no | +| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | string | `31536000` | no | +| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | string | `0` | no | +| name | Name (e.g. `bastion` or `db`) | string | - | yes | +| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes | +| null | an empty string | string | `` | no | +| origin_bucket | Name of S3 bucket | string | `` | no | +| origin_force_destroy | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | string | `false` | no | +| origin_path | (Optional) - An 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. | string | `` | no | +| parent_zone_id | ID of the hosted zone to contain this record (or specify `parent_zone_name`) | string | `` | no | +| parent_zone_name | Name of the hosted zone to contain this record (or specify `parent_zone_id`) | string | `` | no | +| price_class | Price class for this distribution: `PriceClass_All`, `PriceClass_200`, `PriceClass_100` | string | `PriceClass_100` | no | +| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes | +| static_s3_bucket | aws-cli is a bucket owned by amazon that will perminantly exist It allows for the data source to be called during the destruction process without failing. It doesn't get used for anything else, this is a safe workaround for handling the fact that if a data source like the one `aws_s3_bucket.selected` gets an error, you can't continue the terraform process which also includes the 'destroy' command, where is doesn't even need this data source! Don't change this bucket name, its a variable so that we can provide this description. And this works around a problem that is an edge case. | string | `aws-cli` | no | +| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `` | no | +| use_regional_s3_endpoint | When set to 'true' the s3 origin_bucket will use the regional endpoint address instead of the global endpoint address | string | `false` | no | +| viewer_protocol_policy | allow-all, redirect-to-https | string | `redirect-to-https` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| cf_arn | ARN of AWS CloudFront distribution | +| cf_domain_name | Domain name corresponding to the distribution | +| cf_etag | Current version of the distribution's information | +| cf_hosted_zone_id | CloudFront Route 53 zone ID | +| cf_id | ID of AWS CloudFront distribution | +| cf_status | Current status of the distribution | +| s3_bucket | Name of S3 bucket | +| s3_bucket_domain_name | Domain of S3 bucket | + diff --git a/outputs.tf b/outputs.tf index 292417d0..bf9200ef 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,31 +1,39 @@ output "cf_id" { - value = "${aws_cloudfront_distribution.default.id}" + value = "${aws_cloudfront_distribution.default.id}" + description = "ID of AWS CloudFront distribution" } output "cf_arn" { - value = "${aws_cloudfront_distribution.default.arn}" + value = "${aws_cloudfront_distribution.default.arn}" + description = "ARN of AWS CloudFront distribution" } output "cf_status" { - value = "${aws_cloudfront_distribution.default.status}" + value = "${aws_cloudfront_distribution.default.status}" + description = "Current status of the distribution" } output "cf_domain_name" { - value = "${aws_cloudfront_distribution.default.domain_name}" + value = "${aws_cloudfront_distribution.default.domain_name}" + description = "Domain name corresponding to the distribution" } output "cf_etag" { - value = "${aws_cloudfront_distribution.default.etag}" + value = "${aws_cloudfront_distribution.default.etag}" + description = "Current version of the distribution's information" } output "cf_hosted_zone_id" { - value = "${aws_cloudfront_distribution.default.hosted_zone_id}" + value = "${aws_cloudfront_distribution.default.hosted_zone_id}" + description = "CloudFront Route 53 zone ID" } output "s3_bucket" { - value = "${local.bucket}" + value = "${local.bucket}" + description = "Name of S3 bucket" } output "s3_bucket_domain_name" { - value = "${local.bucket_domain_name}" + value = "${local.bucket_domain_name}" + description = "Domain of S3 bucket" } diff --git a/variables.tf b/variables.tf index 41efe36c..61a91c65 100644 --- a/variables.tf +++ b/variables.tf @@ -32,7 +32,8 @@ variable "tags" { } variable "enabled" { - default = "true" + default = "true" + description = "Select Enabled if you want CloudFront to begin processing requests as soon as the distribution is created, or select Disabled if you do not want CloudFront to begin processing requests after the distribution is created." } variable "acm_certificate_arn" { @@ -53,7 +54,8 @@ variable "use_regional_s3_endpoint" { } variable "origin_bucket" { - default = "" + default = "" + description = "Name of S3 bucket" } variable "origin_path" { @@ -63,35 +65,43 @@ variable "origin_path" { } variable "origin_force_destroy" { - default = "false" + default = "false" + description = "Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`)" } variable "bucket_domain_format" { - default = "%s.s3.amazonaws.com" + default = "%s.s3.amazonaws.com" + description = "Format of bucket domain name" } variable "compress" { - default = "false" + default = "false" + description = "Compress content for web requests that include Accept-Encoding: gzip in the request header" } variable "is_ipv6_enabled" { - default = "true" + default = "true" + description = "State of CloudFront IPv6" } variable "default_root_object" { - default = "index.html" + default = "index.html" + description = "Object that CloudFront return when requests the root URL" } variable "comment" { - default = "Managed by Terraform" + default = "Managed by Terraform" + description = "Comment for the origin access identity" } variable "log_include_cookies" { - default = "false" + default = "false" + description = "Include cookies in access logs" } variable "log_prefix" { - default = "" + default = "" + description = "Path of logs in S3 bucket" } variable "log_standard_transition_days" { @@ -110,39 +120,47 @@ variable "log_expiration_days" { } variable "forward_query_string" { - default = "false" + default = "false" + description = "Forward query strings to the origin that is associated with this cache behavior" } variable "cors_allowed_headers" { - type = "list" - default = ["*"] + type = "list" + default = ["*"] + description = "List of allowed headers for S3 bucket" } variable "cors_allowed_methods" { - type = "list" - default = ["GET"] + type = "list" + default = ["GET"] + description = "List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for S3 bucket" } variable "cors_allowed_origins" { - type = "list" - default = [] + type = "list" + default = [] + description = "List of allowed origins (e.g. example.com, test.com) for S3 bucket" } variable "cors_expose_headers" { - type = "list" - default = ["ETag"] + type = "list" + default = ["ETag"] + description = "List of expose header in the response for S3 bucket" } variable "cors_max_age_seconds" { - default = "3600" + default = "3600" + description = "Time in seconds that browser can cache the response for S3 bucket" } variable "forward_cookies" { - default = "none" + default = "none" + description = "Time in seconds that browser can cache the response for S3 bucket" } variable "price_class" { - default = "PriceClass_100" + default = "PriceClass_100" + description = "Price class for this distribution: `PriceClass_All`, `PriceClass_200`, `PriceClass_100`" } variable "viewer_protocol_policy" { @@ -151,45 +169,54 @@ variable "viewer_protocol_policy" { } variable "allowed_methods" { - type = "list" - default = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"] + type = "list" + default = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"] + description = "List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront" } variable "cached_methods" { - type = "list" - default = ["GET", "HEAD"] + type = "list" + default = ["GET", "HEAD"] + description = "List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD)" } variable "default_ttl" { - default = "60" + default = "60" + description = "Default amount of time (in seconds) that an object is in a CloudFront cache" } variable "min_ttl" { - default = "0" + default = "0" + description = "Minimum amount of time that you want objects to stay in CloudFront caches" } variable "max_ttl" { - default = "31536000" + default = "31536000" + description = "Maximum amount of time (in seconds) that an object is in a CloudFront cache" } variable "geo_restriction_type" { # e.g. "whitelist" - default = "none" + default = "none" + description = "Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist`" } variable "geo_restriction_locations" { type = "list" # e.g. ["US", "CA", "GB", "DE"] - default = [] + default = [] + description = "List of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist)" } variable "parent_zone_id" { - default = "" + default = "" + description = "ID of the hosted zone to contain this record (or specify `parent_zone_name`)" } variable "parent_zone_name" { - default = "" + default = "" + description = "Name of the hosted zone to contain this record (or specify `parent_zone_id`)" } variable "null" {