-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
data_source_availability_set.go
92 lines (76 loc) · 2.56 KB
/
data_source_availability_set.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
package azurerm
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceArmAvailabilitySet() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmAvailabilitySetRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*schema.Schema{
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.NoEmptyStrings,
},
"location": {
Type: schema.TypeString,
Computed: true,
},
"platform_update_domain_count": {
Type: schema.TypeString,
Computed: true,
},
"platform_fault_domain_count": {
Type: schema.TypeString,
Computed: true,
},
"managed": {
Type: schema.TypeBool,
Computed: true,
},
"tags": tags.SchemaDataSource(),
},
}
}
func dataSourceArmAvailabilitySetRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Compute.AvailabilitySetsClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()
resGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)
resp, err := client.Get(ctx, resGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Availability Set %q (Resource Group %q) was not found", name, resGroup)
}
return fmt.Errorf("Error making Read request on Availability Set %q (Resource Group %q): %+v", name, resGroup, err)
}
d.SetId(*resp.ID)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
if resp.Sku != nil && resp.Sku.Name != nil {
d.Set("managed", strings.EqualFold(*resp.Sku.Name, "Aligned"))
}
if props := resp.AvailabilitySetProperties; props != nil {
if v := props.PlatformUpdateDomainCount; v != nil {
d.Set("platform_update_domain_count", strconv.Itoa(int(*v)))
}
if v := props.PlatformFaultDomainCount; v != nil {
d.Set("platform_fault_domain_count", strconv.Itoa(int(*v)))
}
}
return tags.FlattenAndSet(d, resp.Tags)
}