/
recovery_services_vault.go
50 lines (42 loc) 路 1.23 KB
/
recovery_services_vault.go
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
package azure
import (
"sort"
"github.com/infracost/infracost/internal/resources/azure"
"github.com/infracost/infracost/internal/schema"
)
func getRecoveryServicesVaultRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "azurerm_recovery_services_vault",
CoreRFunc: newRecoveryServicesVault,
ReferenceAttributes: []string{
"resource_group_name",
"azurerm_backup_protected_vm.recovery_vault_name",
},
CustomRefIDFunc: func(d *schema.ResourceData) []string {
name := d.Get("name").String()
if name != "" {
return []string{name}
}
return nil
},
}
}
func newRecoveryServicesVault(d *schema.ResourceData) schema.CoreResource {
region := lookupRegion(d, []string{"resource_group_name"})
vms := d.References("azurerm_backup_protected_vm.recovery_vault_name")
var protectedVMs []*azure.BackupProtectedVM
for _, vm := range vms {
protectedVm := newBackupProtectedVm(vm)
if protectedVm != nil {
protectedVMs = append(protectedVMs, protectedVm)
}
}
sort.Slice(protectedVMs, func(i, j int) bool {
return protectedVMs[i].Address < protectedVMs[j].Address
})
return &azure.RecoveryServicesVault{
Address: d.Address,
Region: region,
ProtectedVMs: protectedVMs,
}
}