This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
generated from basisai/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
resource_policy.tf
83 lines (67 loc) · 2.32 KB
/
resource_policy.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
resource "google_compute_resource_policy" "backup" {
provider = google-beta
count = var.resource_policy_enabled ? 1 : 0
name = var.resource_policy_name
region = var.region
project = var.project_id
snapshot_schedule_policy {
schedule {
dynamic "hourly_schedule" {
for_each = var.snapshot_hourly ? [{}] : []
content {
hours_in_cycle = var.snapshot_hours_in_cycle
start_time = var.snapshot_start_time
}
}
dynamic "daily_schedule" {
for_each = var.snapshot_daily ? [{}] : []
content {
days_in_cycle = var.snapshot_days_in_cycle
start_time = var.snapshot_start_time
}
}
dynamic "weekly_schedule" {
for_each = var.snapshot_weekly ? [{}] : []
content {
dynamic "day_of_weeks" {
for_each = var.snapshot_day_of_weeks
content {
day = day_of_weeks.key
start_time = day_of_weeks.value
}
}
}
}
}
dynamic "retention_policy" {
for_each = var.snapshot_retention_policy != null ? [var.snapshot_retention_policy] : []
content {
max_retention_days = retention_policy.value.max_retention_days
on_source_disk_delete = retention_policy.value.on_source_disk_delete
}
}
snapshot_properties {
labels = var.snapshot_labels
storage_locations = try(coalescelist(var.snapshot_storage_locations, compact([var.region])), null)
}
}
lifecycle {
create_before_destroy = true
}
}
resource "google_compute_disk_resource_policy_attachment" "backup" {
provider = google-beta
count = var.resource_policy_enabled && !var.regional_disks ? var.replicas : 0
name = google_compute_resource_policy.backup[0].name
disk = google_compute_disk.disk[count.index].name
zone = google_compute_disk.disk[count.index].zone
project = var.project_id
}
resource "google_compute_region_disk_resource_policy_attachment" "backup" {
provider = google-beta
count = var.resource_policy_enabled && var.regional_disks ? var.replicas : 0
name = google_compute_resource_policy.backup[0].name
disk = google_compute_region_disk.disk[count.index].name
region = google_compute_region_disk.disk[count.index].region
project = var.project_id
}