Skip to content

Commit d0ede62

Browse files
authored
Merge pull request #23 from datafold/gerard-eng-2673-reduce-clickhouse-backup-retention-to-7-days
fix: Update clickhouse backup retention
2 parents 1a5507d + 7324f91 commit d0ede62

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ https://docs.datafold.com/datafold-deployment/dedicated-cloud/azure
261261
| <a name="input_azure_bastion_subnet_cidrs"></a> [azure\_bastion\_subnet\_cidrs](#input\_azure\_bastion\_subnet\_cidrs) | The CIDR block for the Azure Bastion subnet. If empty it will be calculated from the VPC CIDR and given size. | `list(string)` | `[]` | no |
262262
| <a name="input_azure_bastion_subnet_name_override"></a> [azure\_bastion\_subnet\_name\_override](#input\_azure\_bastion\_subnet\_name\_override) | Override for the name used in resource.azurerm\_subnet.azure\_bastion\_subnet (modules/networking) | `string` | `""` | no |
263263
| <a name="input_azure_bastion_subnet_size"></a> [azure\_bastion\_subnet\_size](#input\_azure\_bastion\_subnet\_size) | The size of the Azure Bastion subnet in number of IPs | `number` | `256` | no |
264+
| <a name="input_backup_lifecycle_expiration_days"></a> [backup\_lifecycle\_expiration\_days](#input\_backup\_lifecycle\_expiration\_days) | Number of days after which clickhouse backup objects will expire and be deleted. | `number` | `6` | no |
264265
| <a name="input_bastion_host_name_override"></a> [bastion\_host\_name\_override](#input\_bastion\_host\_name\_override) | Override for the name used in resource.azurerm\_bastion\_host.bastion (modules/networking) | `string` | `""` | no |
265266
| <a name="input_bastion_public_ip_name_override"></a> [bastion\_public\_ip\_name\_override](#input\_bastion\_public\_ip\_name\_override) | Override for the name used in resource.azurerm\_public\_ip.ip\_bastion\_host (modules/networking) | `string` | `""` | no |
266267
| <a name="input_ch_data_disk_iops"></a> [ch\_data\_disk\_iops](#input\_ch\_data\_disk\_iops) | IOPS of volume | `number` | `3000` | no |

main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,12 @@ module "clickhouse_backup" {
233233
identity = module.identity.identity
234234

235235
# Resource name overrides
236-
storage_account_name_override = var.storage_account_name_override
236+
storage_account_name_override = var.storage_account_name_override
237237
clickhouse_backup_container_name_override = var.clickhouse_backup_container_name_override
238-
storage_private_dns_zone_name_override = var.storage_private_dns_zone_name_override
239-
storage_private_endpoint_name_override = var.storage_private_endpoint_name_override
240-
storage_dns_link_name_override = var.storage_dns_link_name_override
238+
storage_private_dns_zone_name_override = var.storage_private_dns_zone_name_override
239+
storage_private_endpoint_name_override = var.storage_private_endpoint_name_override
240+
storage_dns_link_name_override = var.storage_dns_link_name_override
241+
backup_lifecycle_expiration_days = var.backup_lifecycle_expiration_days
241242
}
242243

243244
module "data_lake" {

modules/clickhouse_backup/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ resource "azurerm_storage_container" "clickhouse_backup" {
2626
container_access_type = "private"
2727
}
2828

29+
resource "azurerm_storage_management_policy" "clickhouse_backup" {
30+
storage_account_id = azurerm_storage_account.storage.id
31+
32+
rule {
33+
name = "backup_retention"
34+
enabled = true
35+
filters {
36+
blob_types = ["blockBlob"]
37+
prefix_match = [local.clickhouse_backup_container_name]
38+
}
39+
actions {
40+
base_blob {
41+
delete_after_days_since_modification_greater_than = var.backup_lifecycle_expiration_days
42+
}
43+
}
44+
}
45+
}
46+
2947
# ============PrivateLink for Storage Account====================
3048
resource "azurerm_private_dns_zone" "storage_account_dns" {
3149
name = local.storage_private_dns_zone_name

modules/clickhouse_backup/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ variable "storage_dns_link_name_override" {
6666
description = "Override for the name used in resource.azurerm_private_dns_zone_virtual_network_link.storage_account_link"
6767
type = string
6868
default = ""
69+
}
70+
71+
variable "backup_lifecycle_expiration_days" {
72+
type = number
73+
default = 6
74+
description = "Number of days after which clickhouse backup objects will expire and be deleted."
6975
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,12 @@ variable "storage_dns_link_name_override" {
579579
default = ""
580580
}
581581

582+
variable "backup_lifecycle_expiration_days" {
583+
type = number
584+
default = 6
585+
description = "Number of days after which clickhouse backup objects will expire and be deleted."
586+
}
587+
582588
# Key Vault Module Overrides
583589
variable "key_vault_name_override" {
584590
description = "Override for the name used in resource.azurerm_key_vault.default (modules/key_vault)"

0 commit comments

Comments
 (0)