/
virtual_network_gateway_connection.go
75 lines (64 loc) 路 1.98 KB
/
virtual_network_gateway_connection.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
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
package azure
import (
"fmt"
"strings"
"github.com/shopspring/decimal"
"github.com/tidwall/gjson"
"github.com/infracost/infracost/internal/schema"
)
func GetAzureRMVirtualNetworkGatewayConnectionRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "azurerm_virtual_network_gateway_connection",
RFunc: NewAzureRMVirtualNetworkGatewayConnection,
ReferenceAttributes: []string{
"virtual_network_gateway_id",
},
Notes: []string{"Price for additional S2S tunnels is used"},
}
}
func NewAzureRMVirtualNetworkGatewayConnection(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
sku := "Basic"
var vpnGateway *schema.ResourceData
if len(d.References("virtual_network_gateway_id")) > 0 {
vpnGateway = d.References("virtual_network_gateway_id")[0]
sku = vpnGateway.Get("sku").String()
}
region := lookupRegion(d, []string{})
if strings.ToLower(sku) == "basic" {
return &schema.Resource{
Name: d.Address,
NoPrice: true,
IsSkipped: true,
}
}
costComponents := make([]*schema.CostComponent, 0)
if d.Get("type").Type != gjson.Null {
if strings.ToLower(d.Get("type").String()) == "ipsec" {
costComponents = append(costComponents, vpnGatewayS2S(region, sku))
}
}
return &schema.Resource{
Name: d.Address,
CostComponents: costComponents,
}
}
func vpnGatewayS2S(region, sku string) *schema.CostComponent {
return &schema.CostComponent{
Name: fmt.Sprintf("VPN gateway (%s)", sku),
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
HourlyQuantity: decimalPtr(decimal.NewFromInt(1)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("azure"),
Region: strPtr(region),
Service: strPtr("VPN Gateway"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "skuName", Value: strPtr(sku)},
{Key: "meterName", ValueRegex: strPtr(fmt.Sprintf("/%s/i", "S2S Connection"))},
},
},
PriceFilter: &schema.PriceFilter{
PurchaseOption: strPtr("Consumption"),
},
}
}