Skip to content

Instantly share code, notes, and snippets.

@3deep5me
Created February 11, 2025 10:18
Show Gist options
  • Save 3deep5me/2571b3070fb6bc243b1664d60eb2d5d1 to your computer and use it in GitHub Desktop.
Save 3deep5me/2571b3070fb6bc243b1664d60eb2d5d1 to your computer and use it in GitHub Desktop.
Hetzner Object Storage with AWS Terraform Provider
resource "aws_s3_bucket" "main" {
bucket = "my-bucket-a9c8ae4e2"
object_lock_enabled = true
}
resource "aws_s3_bucket_acl" "main" {
bucket = aws_s3_bucket.main.id
acl = "private"
}
resource "aws_s3_bucket_object_lock_configuration" "example" {
bucket = aws_s3_bucket.main.id
rule {
default_retention {
mode = "COMPLIANCE"
days = 7
}
}
}
resource "aws_s3_bucket_lifecycle_configuration" "main" {
bucket = aws_s3_bucket.main.id
# Required for Hetzner compatibility
transition_default_minimum_object_size = ""
rule {
id = "expire-7d"
status = "Enabled"
expiration {
days = 7
}
}
}
resource "aws_s3_bucket_policy" "main" {
bucket = aws_s3_bucket.main.id
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Principal = "*",
Action = ["s3:GetObject"],
# add your project id
Resource = ["arn:aws:s3:::${aws_s3_bucket.main.bucket}/*"]
}
]
})
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
skip_region_validation = true
endpoints {
s3 = "https://fsn1.your-objectstorage.com"
}
region = "fsn1"
# Please checks the docs on how to store those credentials safely.
access_key = ""
secret_key = ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment