Skip to content

Commit bda2f3f

Browse files
Jamie-BitFlightaknysh
authored andcommitted
Forwarded headers are needed when using CORS on S3 from cloudfront (#25)
* Forwarded headers are needed when using CORS on S3 from cloudfront * lint * Moved the forwarded header values into a var
1 parent b082a13 commit bda2f3f

File tree

6 files changed

+17
-2
lines changed

6 files changed

+17
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ Then you can use this method for supressing the superfluous errors.
7373
```
7474
Available targets:
7575
76-
help This help screen
76+
help Help screen
7777
help/all Display help for all targets
78+
help/short This help short screen
7879
lint Lint terraform code
7980
8081
```
@@ -101,6 +102,7 @@ Available targets:
101102
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
102103
| 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 |
103104
| forward_cookies | Time in seconds that browser can cache the response for S3 bucket | string | `none` | no |
105+
| forward_header_values | A list of whitelisted header values to forward to the origin | list | `<list>` | no |
104106
| forward_query_string | Forward query strings to the origin that is associated with this cache behavior | string | `false` | no |
105107
| geo_restriction_locations | List of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist) | list | `<list>` | no |
106108
| geo_restriction_type | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | string | `none` | no |

docs/targets.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
```
33
Available targets:
44
5-
help This help screen
5+
help Help screen
66
help/all Display help for all targets
7+
help/short This help short screen
78
lint Lint terraform code
89
910
```

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
2222
| 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 |
2323
| forward_cookies | Time in seconds that browser can cache the response for S3 bucket | string | `none` | no |
24+
| forward_header_values | A list of whitelisted header values to forward to the origin | list | `<list>` | no |
2425
| forward_query_string | Forward query strings to the origin that is associated with this cache behavior | string | `false` | no |
2526
| geo_restriction_locations | List of country codes for which CloudFront either to distribute content (whitelist) or not distribute your content (blacklist) | list | `<list>` | no |
2627
| geo_restriction_type | Method that use to restrict distribution of your content by country: `none`, `whitelist`, or `blacklist` | string | `none` | no |

example/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ module "cdn" {
1212
parent_zone_id = "${aws_route53_zone.primary.zone_id}"
1313
use_regional_s3_endpoint = "true"
1414
origin_force_destroy = "true"
15+
cors_allowed_headers = ["*"]
16+
cors_allowed_methods = ["GET", "HEAD", "PUT"]
17+
cors_allowed_origins = ["*.cloudposse.com"]
18+
cors_expose_headers = ["ETag"]
1519
}
1620

1721
resource "aws_s3_bucket_object" "index" {

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ resource "aws_cloudfront_distribution" "default" {
144144

145145
forwarded_values {
146146
query_string = "${var.forward_query_string}"
147+
headers = ["${var.forward_header_values}"]
147148

148149
cookies {
149150
forward = "${var.forward_cookies}"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ variable "forward_cookies" {
163163
description = "Time in seconds that browser can cache the response for S3 bucket"
164164
}
165165

166+
variable "forward_header_values" {
167+
type = "list"
168+
description = "A list of whitelisted header values to forward to the origin"
169+
default = ["Access-Control-Request-Headers", "Access-Control-Request-Method", "Origin"]
170+
}
171+
166172
variable "price_class" {
167173
default = "PriceClass_100"
168174
description = "Price class for this distribution: `PriceClass_All`, `PriceClass_200`, `PriceClass_100`"

0 commit comments

Comments
 (0)