forked from appvia/terraform-aws-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocals.tf
131 lines (114 loc) · 3.16 KB
/
locals.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
locals {
# CloudFormation templates directory
cf_dir = format("%s/cloud_formation", path.module)
# CloudFormation templates
cf_role_tpl = file(format("%s/role.yaml", local.cf_dir))
cf_vault_tpl = file(format("%s/vault.yaml", local.cf_dir))
# List of regions to apply backups
backup_regions = coalescelist(var.regions, [
data.aws_region.current.name,
])
}
locals {
vaults_per_region = merge([
for v in var.vaults : {
for r in local.backup_regions :
lower("${r}-${v.name}") => {
vault = v
region = r
}
}
]...)
all_role_names = toset([
for p in var.plans : p.backup_role_name
if p.backup_role_name != "lza-backup-service-linked-role"
])
}
locals {
backup_plans = {
for p in var.plans :
p.name => {
regions = {
"@@assign" = local.backup_regions
}
rules = {
(p.name) = {
target_backup_vault_name = {
"@@assign" = p.vault_name
}
schedule_expression = {
"@@assign" = p.schedule
}
start_backup_window_minutes = {
"@@assign" = tostring(p.start_window_minutes)
}
complete_backup_window_minutes = {
"@@assign" = tostring(p.complete_window_minutes)
}
copy_actions = {
for b in p.copy_backups :
(b.target_vault) => {
target_backup_vault_arn = {
"@@assign" = b.target_vault
}
lifecycle = merge(
{},
try(b.lifecycle.cold_storage_after_days, null) == null ? {} : {
move_to_cold_storage_after_days = {
"@@assign" : tostring(b.lifecycle.cold_storage_after_days)
}
},
try(b.lifecycle.delete_after_days, null) == null ? {} : {
delete_after_days = {
"@@assign" : tostring(b.lifecycle.delete_after_days)
}
},
)
}
}
lifecycle = merge(
{},
try(p.lifecycle.cold_storage_after_days, null) == null ? {} : {
move_to_cold_storage_after_days = {
"@@assign" : tostring(p.lifecycle.cold_storage_after_days)
}
},
try(p.lifecycle.delete_after_days, null) == null ? {} : {
delete_after_days = {
"@@assign" : tostring(p.lifecycle.delete_after_days)
}
},
)
}
}
selections = {
tags = {
backup-policy = {
iam_role_arn = {
"@@assign" = "arn:aws:iam::$account:role/backup/${p.backup_role_name}"
}
tag_key = {
"@@assign" = p.backup_tag_name
}
tag_value = {
"@@assign" = [
p.name,
]
}
}
}
}
backup_plan_tags = {
for k, v in var.tags :
k => {
tag_key = {
"@@assign" = k
}
tag_value = {
"@@assign" = v
}
}
}
}
}
}