Skip to content

Commit eab44db

Browse files
committed
Support enabling cors for S3 bucket
1 parent cf6253a commit eab44db

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

deployments/stacks/dpe-k8s/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ module "synapse_dataset_to_crossiant_metadata" {
5454
cluster_name = var.cluster_name
5555
cluster_oidc_provider_arn = module.sage-aws-eks.cluster_oidc_provider_arn
5656
public_access = true
57+
enable_cors = true
5758
}

modules/s3-bucket/main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ resource "aws_s3_bucket_policy" "my_bucket_policy" {
4141
count = var.public_access ? 1 : 0
4242
bucket = aws_s3_bucket.bucket.bucket
4343

44+
depends_on = [ aws_s3_bucket_acl.bucket_acl, aws_s3_bucket_public_access_block.access_block ]
45+
4446
policy = jsonencode({
4547
Version = "2012-10-17",
4648
Statement = [
@@ -54,6 +56,16 @@ resource "aws_s3_bucket_policy" "my_bucket_policy" {
5456
})
5557
}
5658

59+
resource "aws_s3_bucket_cors_configuration" "example" {
60+
count = var.enable_cors ? 1 : 0
61+
bucket = aws_s3_bucket.bucket.id
62+
63+
cors_rule {
64+
allowed_methods = ["GET"]
65+
allowed_origins = ["*"]
66+
}
67+
}
68+
5769
resource "aws_s3_bucket_versioning" "versioning" {
5870
bucket = aws_s3_bucket.bucket.id
5971
versioning_configuration {

modules/s3-bucket/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ variable "public_access" {
3636
description = "Enable/block public access to the bucket"
3737
type = bool
3838
default = false
39+
}
40+
41+
variable "enable_cors" {
42+
description = "Enable CORS on the bucket"
43+
type = bool
44+
default = false
3945
}

0 commit comments

Comments
 (0)