/
function_app.go
79 lines (66 loc) 路 2.06 KB
/
function_app.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
76
77
78
79
package azure
import (
"strings"
"github.com/infracost/infracost/internal/resources/azure"
"github.com/infracost/infracost/internal/schema"
)
func getFunctionAppRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "azurerm_function_app",
ReferenceAttributes: []string{
"app_service_plan_id",
},
CoreRFunc: func(d *schema.ResourceData) schema.CoreResource {
return newFunctionApp(d)
},
}
}
func newFunctionApp(d *schema.ResourceData) *azure.FunctionApp {
appServicePlan := d.References("app_service_plan_id")
servicePlan := d.References("service_plan_id")
region := lookupRegion(d, []string{})
if len(appServicePlan) == 0 && len(servicePlan) == 0 {
return &azure.FunctionApp{
Address: d.Address,
Region: region,
Tier: "standard",
}
}
if len(appServicePlan) > 0 {
data := appServicePlan[0]
return newFunctionAppFromAppServicePlanRef(d, data)
}
data := servicePlan[0]
return newFunctionAppFromAppServicePlanRef(d, data)
}
func newFunctionAppFromAppServicePlanRef(d *schema.ResourceData, data *schema.ResourceData) *azure.FunctionApp {
region := lookupRegion(d, []string{})
tier := "standard"
// support for the legacy azurerm_app_service_plan resource. This is only applicable for the legacy azurerm_function_app resource.
if data.Get("sku").Exists() {
skuTier := strings.ToLower(data.Get("sku.0.tier").String())
skuSize := strings.ToLower(data.Get("sku.0.size").String())
kind := strings.ToLower(data.Get("kind").String())
if strings.ToLower(skuSize) != "y1" && (strings.ToLower(kind) == "elastic" || strings.ToLower(skuTier) == "elasticpremium") {
tier = "premium"
}
return &azure.FunctionApp{
Address: d.Address,
Region: region,
SKUName: skuSize,
Tier: tier,
OSType: kind,
}
}
skuName := data.Get("sku_name").String()
if strings.HasPrefix(strings.ToLower(skuName), "ep") {
tier = "premium"
}
return &azure.FunctionApp{
Address: d.Address,
Region: region,
SKUName: strings.ToLower(skuName),
Tier: tier,
OSType: strings.ToLower(data.Get("os_type").String()),
}
}