Last active
June 26, 2025 06:33
-
-
Save jenseickmeyer/5e39faf7374d46b4021c453659622fe2 to your computer and use it in GitHub Desktop.
Terraform template for setting up S3 bucket and IAM permissions for Litestream backups.
This file contains hidden or 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
resource "aws_s3_bucket" "database_backups" { | |
bucket = "my-app-database-backups" | |
} | |
resource "aws_s3_bucket_public_access_block" "database_backups_block_public" { | |
bucket = aws_s3_bucket.database_backups.id | |
block_public_acls = true | |
ignore_public_acls = true | |
block_public_policy = true | |
restrict_public_buckets = true | |
} | |
resource "aws_s3_bucket_ownership_controls" "database_backups_ownership_controls" { | |
bucket = aws_s3_bucket.database_backups.id | |
rule { | |
object_ownership = "BucketOwnerEnforced" | |
} | |
} | |
resource "aws_iam_user" "my_app" { | |
name = "my-app" | |
} | |
resource "aws_iam_user_policy" "database_backups_access_policy" { | |
name = "DatabaseBackupsAccessPolicy" | |
user = aws_iam_user.my_app.name | |
policy = jsonencode({ | |
Version = "2012-10-17" | |
Statement = [ | |
{ | |
Effect = "Allow" | |
Action = [ | |
"s3:GetBucketLocation", | |
"s3:ListBucket" | |
] | |
Resource = aws_s3_bucket.database_backups.arn | |
}, | |
{ | |
Effect = "Allow" | |
Action = [ | |
"s3:PutObject", | |
"s3:GetObject", | |
"s3:DeleteObject" | |
] | |
Resource = "${aws_s3_bucket.database_backups.arn}/*" | |
} | |
] | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment