Skip to content

Commit

Permalink
Merge pull request #7 from realglobe-Inc/cors
Browse files Browse the repository at this point in the history
Enable to allow CORS origins
  • Loading branch information
s-oku authored Aug 16, 2019
2 parents af57528 + 56fb9d6 commit 7f3d704
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Provision a static website hosted through S3 + CloudFront in AWS
```hcl
module "website" {
source = "realglobe-Inc/static-website/aws"
version = "2.1.1"
version = "2.2.0"
service_name = "your-service-name"
aws_profile = "aws-profile-name"
domain_names = list("foo.example.com", "bar.example.com")
Expand Down
5 changes: 3 additions & 2 deletions cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ resource "aws_cloudfront_distribution" "web_dist" {
}

default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD", "OPTIONS"]
target_origin_id = local.s3_origin_id
compress = true

forwarded_values {
query_string = false
headers = ["Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers"]

cookies {
forward = "none"
Expand Down
7 changes: 7 additions & 0 deletions s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ resource "aws_s3_bucket" "hosting" {
bucket = var.s3_bucket_name
policy = data.aws_iam_policy_document.bucket_policy.json

cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET"]
allowed_origins = var.cors_allowed_origins
max_age_seconds = 3000
}

versioning {
enabled = true
}
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ variable "lambda_function_associations" {
type = map(string)
default = {}
}
variable "cors_allowed_origins" {
description = "CORS allowed origins"
type = list(string)
default = []
}

0 comments on commit 7f3d704

Please sign in to comment.