forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spatial_anchors_account_data_source.go
84 lines (68 loc) · 2.49 KB
/
spatial_anchors_account_data_source.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
package mixedreality
import (
"fmt"
"regexp"
"time"
"github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/azure"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/clients"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/mixedreality/parse"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/validation"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/timeouts"
"github.com/kevinklinger/terraform-provider-azurerm/v2/utils"
)
func dataSourceSpatialAnchorsAccount() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceSpatialAnchorsAccountRead,
Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`^[-\w._()]+$`),
"Spatial Anchors Account name must be 1 - 90 characters long, contain only word characters and underscores.",
),
},
"location": azure.SchemaLocationForDataSource(),
"resource_group_name": azure.SchemaResourceGroupName(),
"account_domain": {
Type: pluginsdk.TypeString,
Computed: true,
},
"account_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}
func dataSourceSpatialAnchorsAccountRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).MixedReality.SpatialAnchorsAccountClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
id := parse.NewSpatialAnchorsAccountID(subscriptionId, resourceGroup, name)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return nil
}
return fmt.Errorf("retrieving Spatial Anchors Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
d.SetId(id.ID())
d.Set("name", resp.Name)
d.Set("resource_group_name", id.ResourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
if props := resp.AccountProperties; props != nil {
d.Set("account_domain", props.AccountDomain)
d.Set("account_id", props.AccountID)
}
return nil
}