| new file mode 100644 |
| index 0000000..1dfe198 |
| --- /dev/null |
| +++ b/infra/prod/hibernate.tf |
| @@ -0,0 +1,78 @@ |
| +# 🤖 Production instance-hibernation state (issue #550 Part 4 v2 on the real |
| +# fleet): the bucket activator-managed instances park in, and the router |
| +# box's scoped credentials for it. Separate from the fleet-backup bucket — |
| +# hibernation's embedded Litestream owns each managed DB's replication |
| +# (deploy/fleet-backup.sh excludes those hosts; two replicators on one WAL |
| +# would fight over checkpointing). |
| + |
| +resource "aws_s3_bucket" "prod_instances" { |
| + bucket = "eleven-prod-instances-${local.account_id}" |
| +} |
| + |
| +resource "aws_s3_bucket_versioning" "prod_instances" { |
| + bucket = aws_s3_bucket.prod_instances.id |
| + |
| + versioning_configuration { |
| + status = "Enabled" |
| + } |
| +} |
| + |
| +resource "aws_s3_bucket_lifecycle_configuration" "prod_instances" { |
| + bucket = aws_s3_bucket.prod_instances.id |
| + |
| + rule { |
| + id = "expire-noncurrent-14d" |
| + status = "Enabled" |
| + |
| + filter {} |
| + |
| + noncurrent_version_expiration { |
| + noncurrent_days = 14 |
| + } |
| + } |
| +} |
| + |
| +resource "aws_s3_bucket_public_access_block" "prod_instances" { |
| + bucket = aws_s3_bucket.prod_instances.id |
| + |
| + block_public_acls = true |
| + block_public_policy = true |
| + ignore_public_acls = true |
| + restrict_public_buckets = true |
| +} |
| + |
| +# The router's activator credentials: object rw + version listing (the wake |
| +# path restores, the lease CASes, sweepers may prune) on this bucket only. |
| +# Key minted by hand, lives in the router's env — never in tofu state. |
| +resource "aws_iam_user" "activator_prod" { |
| + name = "activator-prod" |
| +} |
| + |
| +data "aws_iam_policy_document" "activator_prod" { |
| + statement { |
| + sid = "ListProdInstances" |
| + actions = ["s3:ListBucket", "s3:ListBucketVersions"] |
| + resources = [aws_s3_bucket.prod_instances.arn] |
| + } |
| + |
| + statement { |
| + sid = "ReadWriteProdInstanceObjects" |
| + actions = [ |
| + "s3:GetObject", |
| + "s3:PutObject", |
| + "s3:DeleteObject", |
| + "s3:DeleteObjectVersion", |
| + ] |
| + resources = ["${aws_s3_bucket.prod_instances.arn}/*"] |
| + } |
| +} |
| + |
| +resource "aws_iam_user_policy" "activator_prod" { |
| + name = "activator-prod-instances-bucket" |
| + user = aws_iam_user.activator_prod.name |
| + policy = data.aws_iam_policy_document.activator_prod.json |
| +} |
| + |
| +output "prod_instances_bucket" { |
| + value = aws_s3_bucket.prod_instances.bucket |
| +} |