Created
July 30, 2025 20:56
-
-
Save kubukoz/fd853e91474d3bdb2793b33ad39d87a8 to your computer and use it in GitHub Desktop.
Revisions
-
kubukoz created this gist
Jul 30, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ import besom.api.aws.iam._ import besom.api.aws.s3._ import besom._ import besom.api.aws.s3.inputs.BucketLifecycleRuleArgs import besom.api.aws.s3.inputs.BucketLifecycleRuleExpirationArgs import besom.json._ import besom.api.aws.s3.inputs.BucketLifecycleRuleTransitionArgs @main def main = Pulumi.run { val bucket = Bucket( "ha-backups", BucketArgs( lifecycleRules = Some( List( BucketLifecycleRuleArgs( enabled = true, expiration = Some(BucketLifecycleRuleExpirationArgs(days = 30)), id = Some("expire-old-backups"), transitions = Some( List( // move to Glacier Immediate Retrieval immediately BucketLifecycleRuleTransitionArgs( days = 0, storageClass = "GLACIER_IR" ) ) ) ) ) ) ) ) val haUser = User("home-assistant-backup-user") val policy = Policy( "ha-s3-backup-policy", PolicyArgs( policy = json"""{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowS3BackupOperations", "Effect": "Allow", "Action": [ "s3:ListBucket", "s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:AbortMultipartUpload" ], "Resource": [ ${bucket.arn}, ${bucket.arn.map(_ + "/*")} ] } ] }""".map(_.prettyPrint) ) ) val attachment = UserPolicyAttachment( "ha-backup-user-policy-attachment", UserPolicyAttachmentArgs( user = haUser.name, policyArn = policy.arn ) ) val accessKey = AccessKey( "ha-user-access-key", AccessKeyArgs( user = haUser.name ) ) Stack(attachment).exports( bucketId = bucket.id, accessKeyId = accessKey.id, secretAccessKey = accessKey.secret ) }