Skip to content

Commit

Permalink
add CORS policies to bucket configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Dec 15, 2024
1 parent 2445af1 commit 30b8268
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cloud/aws/deploytf/.nitric/modules/bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ resource "aws_s3_bucket" "bucket" {
}
}

resource "aws_s3_bucket_cors_configuration" "cors_policy" {
bucket = aws_s3_bucket.bucket.id

# TODO: Make this configurable
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["PUT", "POST", "GET"]
allowed_origins = ["*"]
max_age_seconds = 3000
}

cors_rule {
allowed_methods = ["GET"]
allowed_origins = ["*"]
}
}

# Deploy bucket lambda invocation permissions
resource "aws_lambda_permission" "allow_bucket" {
for_each = var.notification_targets
Expand Down
8 changes: 8 additions & 0 deletions cloud/gcp/deploytf/.nitric/modules/bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ resource "google_storage_bucket" "bucket" {
type = "Delete"
}
}

cors {
# TODO: Make this configurable
origin = ["*"]
method = ["GET", "HEAD", "PUT", "POST"]
response_header = ["*"]
max_age_seconds = 3600
}
labels = {
"x-nitric-${var.stack_id}-name" = var.bucket_name
"x-nitric-${var.stack_id}-type" = "bucket"
Expand Down

0 comments on commit 30b8268

Please sign in to comment.