| 1 | # Get the list of files from the cache |
| 2 | resource "aws_s3_bucket" "cache_inventory" { |
| 3 | provider = aws.us |
| 4 | bucket = "nix-cache-inventory" |
| 5 | } |
| 6 | |
| 7 | resource "aws_s3_bucket_lifecycle_configuration" "cache_inventory" { |
| 8 | provider = aws.us |
| 9 | bucket = aws_s3_bucket.cache_inventory.id |
| 10 | |
| 11 | transition_default_minimum_object_size = "varies_by_storage_class" |
| 12 | |
| 13 | rule { |
| 14 | id = "tf-s3-lifecycle-20231017200421961900000001" |
| 15 | status = "Enabled" |
| 16 | |
| 17 | filter { |
| 18 | prefix = "" |
| 19 | } |
| 20 | |
| 21 | # Only keep the last 30 days |
| 22 | expiration { |
| 23 | days = 30 |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | import { |
| 29 | to = aws_s3_bucket_lifecycle_configuration.cache_inventory |
| 30 | id = aws_s3_bucket.cache_inventory.id |
| 31 | } |
| 32 | |
| 33 | resource "aws_s3_bucket_inventory" "cache_inventory" { |
| 34 | provider = aws.us |
| 35 | |
| 36 | bucket = aws_s3_bucket.cache.id |
| 37 | name = "nix-cache-inventory" |
| 38 | |
| 39 | included_object_versions = "Current" |
| 40 | |
| 41 | optional_fields = [ |
| 42 | "ETag", |
| 43 | "LastModifiedDate", |
| 44 | "Size", |
| 45 | "StorageClass", |
| 46 | ] |
| 47 | |
| 48 | schedule { |
| 49 | frequency = "Daily" |
| 50 | } |
| 51 | |
| 52 | destination { |
| 53 | bucket { |
| 54 | account_id = "080433136561" |
| 55 | format = "Parquet" |
| 56 | bucket_arn = aws_s3_bucket.cache_inventory.arn |
| 57 | } |
| 58 | } |
| 59 | } |