Skip to content

Commit

Permalink
Forwarded headers are needed when using CORS on S3 from cloudfront (#25)
Browse files Browse the repository at this point in the history
* Forwarded headers are needed when using CORS on S3 from cloudfront

* lint

* Moved the forwarded header values into a var
  • Loading branch information
Jamie-BitFlight authored and aknysh committed Aug 28, 2018
1 parent b082a13 commit bda2f3f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ Then you can use this method for supressing the superfluous errors.
```
Available targets:
help This help screen
help Help screen
help/all Display help for all targets
help/short This help short screen
lint Lint terraform code
```
Expand All @@ -101,6 +102,7 @@ Available targets:
| 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_header_values | A list of whitelisted header values to forward to the origin | list | `<list>` | 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 | `<list>` | no |
| geo_restriction_type | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | string | `none` | no |
Expand Down
3 changes: 2 additions & 1 deletion docs/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
```
Available targets:
help This help screen
help Help screen
help/all Display help for all targets
help/short This help short screen
lint Lint terraform code
```
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
| 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_header_values | A list of whitelisted header values to forward to the origin | list | `<list>` | 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 | `<list>` | no |
| geo_restriction_type | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | string | `none` | no |
Expand Down
4 changes: 4 additions & 0 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module "cdn" {
parent_zone_id = "${aws_route53_zone.primary.zone_id}"
use_regional_s3_endpoint = "true"
origin_force_destroy = "true"
cors_allowed_headers = ["*"]
cors_allowed_methods = ["GET", "HEAD", "PUT"]
cors_allowed_origins = ["*.cloudposse.com"]
cors_expose_headers = ["ETag"]
}

resource "aws_s3_bucket_object" "index" {
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ resource "aws_cloudfront_distribution" "default" {

forwarded_values {
query_string = "${var.forward_query_string}"
headers = ["${var.forward_header_values}"]

cookies {
forward = "${var.forward_cookies}"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ variable "forward_cookies" {
description = "Time in seconds that browser can cache the response for S3 bucket"
}

variable "forward_header_values" {
type = "list"
description = "A list of whitelisted header values to forward to the origin"
default = ["Access-Control-Request-Headers", "Access-Control-Request-Method", "Origin"]
}

variable "price_class" {
default = "PriceClass_100"
description = "Price class for this distribution: `PriceClass_All`, `PriceClass_200`, `PriceClass_100`"
Expand Down

0 comments on commit bda2f3f

Please sign in to comment.