Created
March 7, 2025 18:03
-
-
Save Schachte/766ec92bd965ee89583679e35f3fe4dd to your computer and use it in GitHub Desktop.
Repro R2 Terraform CORS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
cloudflare = { | |
source = "cloudflare/cloudflare" | |
version = "5.1.0" | |
} | |
} | |
required_version = ">= 1.5.7" | |
} | |
provider "cloudflare" { | |
api_token = var.cloudflare_api_token | |
} | |
variable "cloudflare_api_token" { | |
description = "Cloudflare API token" | |
type = string | |
sensitive = true | |
} | |
variable "cloudflare_account_id" { | |
description = "Cloudflare account ID" | |
type = string | |
default = "<REDACTED>" | |
} | |
resource "cloudflare_r2_bucket" "test" { | |
account_id = "<REDACTED>" | |
name = "babylist-assets" | |
location = "wnam" | |
} | |
resource "cloudflare_r2_bucket_cors" "test" { | |
account_id = "<REDACTED>" | |
bucket_name = cloudflare_r2_bucket.test.name | |
rules = [{ | |
allowed = { | |
methods = ["GET"] | |
origins = [ | |
"www.babylist.com", | |
"my.babylist.com", | |
"canary.babylist.com", | |
"staging.babylist.com", | |
"staging2.babylist.com", | |
"staging3.babylist.com", | |
"staging4.babylist.com", | |
"staging5.babylist.com", | |
"staging6.babylist.com", | |
"staging7.babylist.com", | |
"staging8.babylist.com", | |
"staging9.babylist.com", | |
"staging10.babylist.com", | |
"staging11.babylist.com", | |
"staging12.babylist.com" | |
] | |
headers = [] | |
} | |
id = "Allow Public Asset Service" | |
expose_headers = [] | |
max_age_seconds = 3600 | |
}] | |
} | |
output "bucket_id" { | |
description = "ID of the created R2 bucket" | |
value = cloudflare_r2_bucket.test.id | |
} | |
output "bucket_name" { | |
description = "Name of the created R2 bucket" | |
value = cloudflare_r2_bucket.test.name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment