/
snapshot.go
44 lines (37 loc) 路 924 Bytes
/
snapshot.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
package azure
import (
"github.com/infracost/infracost/internal/resources/azure"
"github.com/infracost/infracost/internal/schema"
)
func getSnapshotRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "azurerm_snapshot",
CoreRFunc: newSnapshot,
ReferenceAttributes: []string{
"resource_group_name",
"source_uri",
},
}
}
func newSnapshot(d *schema.ResourceData) schema.CoreResource {
region := lookupRegion(d, []string{"resource_group_name"})
return &azure.Image{
Type: "Snapshot",
StorageGB: snapshotStorageSize(d),
Address: d.Address,
Region: region,
}
}
func snapshotStorageSize(d *schema.ResourceData) *float64 {
v := d.Get("disk_size_gb")
if v.Exists() && v.Value() != nil {
size := v.Float()
return &size
}
refs := d.References("source_uri")
if len(refs) > 0 {
size := refs[0].Get("disk_size_gb").Float()
return &size
}
return nil
}