From 543d9c01f6dd96d4a1e0dda4e25734bca4a3c051 Mon Sep 17 00:00:00 2001 From: Ash Davies <3853061+DrizzlyOwl@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:03:25 +0000 Subject: [PATCH] Delete CI reports after 14 days --- terraform/README.md | 3 ++- terraform/ci-storage.tf | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/terraform/README.md b/terraform/README.md index 70e660b55..6a04e494e 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -134,7 +134,7 @@ If everything looks good, answer `yes` and wait for the new infrastructure to be | Name | Version | |------|---------| -| [azurerm](#provider\_azurerm) | 3.77.0 | +| [azurerm](#provider\_azurerm) | 3.79.0 | ## Modules @@ -151,6 +151,7 @@ If everything looks good, answer `yes` and wait for the new infrastructure to be | [azurerm_monitor_diagnostic_setting.ci-test-reports](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_diagnostic_setting) | resource | | [azurerm_storage_account.ci-test-reports](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) | resource | | [azurerm_storage_container.ci-test-reports](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_container) | resource | +| [azurerm_storage_management_policy.ci-test-reports](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_management_policy) | resource | | [azurerm_storage_account_blob_container_sas.ci-test-reports](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/storage_account_blob_container_sas) | data source | ## Inputs diff --git a/terraform/ci-storage.tf b/terraform/ci-storage.tf index 809f5a95b..670e1ba83 100644 --- a/terraform/ci-storage.tf +++ b/terraform/ci-storage.tf @@ -39,6 +39,32 @@ resource "azurerm_monitor_diagnostic_setting" "ci-test-reports" { } } +resource "azurerm_storage_management_policy" "ci-test-reports" { + count = local.enable_ci_report_storage_container ? 1 : 0 + + storage_account_id = azurerm_storage_account.ci-test-reports[0].id + + rule { + name = "ci-report-cool-off" + enabled = true + + filters { + blob_types = ["blockBlob"] + } + + actions { + base_blob { + tier_to_cool_after_days_since_creation_greater_than = 7 + delete_after_days_since_creation_greater_than = 14 + } + + snapshot { + delete_after_days_since_creation_greater_than = 14 + } + } + } +} + data "azurerm_storage_account_blob_container_sas" "ci-test-reports" { count = local.enable_ci_report_storage_container ? 1 : 0