forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_app_service_plan.go
119 lines (97 loc) · 2.57 KB
/
data_source_app_service_plan.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
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
package azurerm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceAppServicePlan() *schema.Resource {
return &schema.Resource{
Read: dataSourceAppServicePlanRead,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"resource_group_name": resourceGroupNameForDataSourceSchema(),
"location": locationForDataSourceSchema(),
"kind": {
Type: schema.TypeString,
Computed: true,
},
"sku": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tier": {
Type: schema.TypeString,
Computed: true,
},
"size": {
Type: schema.TypeString,
Computed: true,
},
"capacity": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"properties": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"reserved": {
Type: schema.TypeBool,
Computed: true,
},
"per_site_scaling": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"maximum_number_of_workers": {
Type: schema.TypeInt,
Computed: true,
},
"tags": tagsForDataSourceSchema(),
},
}
}
func dataSourceAppServicePlanRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicePlansClient
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
ctx := meta.(*ArmClient).StopContext
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
}
return fmt.Errorf("Error making Read request on App Service Plan %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("location", azureRMNormalizeLocation(*resp.Location))
d.Set("kind", resp.Kind)
if props := resp.AppServicePlanProperties; props != nil {
d.Set("properties", flattenAppServiceProperties(props))
if props.MaximumNumberOfWorkers != nil {
d.Set("maximum_number_of_workers", int(*props.MaximumNumberOfWorkers))
}
}
if sku := resp.Sku; sku != nil {
d.Set("sku", flattenAppServicePlanSku(sku))
}
flattenAndSetTags(d, resp.Tags)
return nil
}