Skip to content

Commit

Permalink
introduce staging binary cache to migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Oct 16, 2024
1 parent ca7f33f commit 1ec1d4c
Show file tree
Hide file tree
Showing 10 changed files with 651 additions and 0 deletions.
132 changes: 132 additions & 0 deletions terraform/cache-bucket/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
variable "bucket_name" {
type = string
}

resource "aws_s3_bucket" "cache" {
provider = aws
bucket = var.bucket_name

lifecycle_rule {
enabled = true

transition {
days = 365
storage_class = "STANDARD_IA"
}
}

cors_rule {
allowed_headers = ["Authorization"]
allowed_methods = ["GET"]
allowed_origins = ["*"]
max_age_seconds = 3000
}
}

resource "aws_s3_bucket_public_access_block" "cache" {
bucket = aws_s3_bucket.cache.bucket

block_public_acls = false
block_public_policy = false
}

resource "aws_s3_bucket_object" "cache-nix-cache-info" {
provider = aws
depends_on = [aws_s3_bucket_public_access_block.cache]

bucket = aws_s3_bucket.cache.bucket
content_type = "text/x-nix-cache-info"
etag = filemd5("${path.module}/../cache-staging/nix-cache-info")
key = "nix-cache-info"
source = "${path.module}/../cache-staging/nix-cache-info"
}

resource "aws_s3_bucket_object" "cache-index-html" {
provider = aws
depends_on = [aws_s3_bucket_public_access_block.cache]

bucket = aws_s3_bucket.cache.bucket
content_type = "text/html"
etag = filemd5("${path.module}/../cache-staging/index.html")
key = "index.html"
source = "${path.module}/../cache-staging/index.html"
}

resource "aws_s3_bucket_policy" "cache" {
provider = aws
bucket = aws_s3_bucket.cache.id
depends_on = [aws_s3_bucket_public_access_block.cache]

# imported from existing
policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${var.bucket_name}/*"
},
{
"Sid": "AllowUploadDebuginfoWrite",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::080433136561:user/s3-upload-releases"
},
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::${var.bucket_name}/debuginfo/*"
},
{
"Sid": "AllowUploadDebuginfoRead",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::080433136561:user/s3-upload-releases"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${var.bucket_name}/*"
},
{
"Sid": "AllowUploadDebuginfoRead2",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::080433136561:user/s3-upload-releases"
},
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::${var.bucket_name}"
}
]
}
EOF
}

resource "aws_s3_bucket_request_payment_configuration" "cache" {
provider = aws
bucket = aws_s3_bucket.cache.id
payer = "Requester"
}

output "bucket" {
value = aws_s3_bucket.cache.bucket
}

output "bucket_domain_name" {
value = aws_s3_bucket.cache.bucket_domain_name
}

output "bucket_regional_domain_name" {
value = aws_s3_bucket.cache.bucket_regional_domain_name
}

output "region" {
value = aws_s3_bucket.cache.region
}
7 changes: 7 additions & 0 deletions terraform/cache-bucket/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
aws = {
source = "registry.terraform.io/hashicorp/aws"
}
}
}
Loading

0 comments on commit 1ec1d4c

Please sign in to comment.