-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
data_source_maps_account.go
89 lines (70 loc) · 2.31 KB
/
data_source_maps_account.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
package azurerm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceArmMapsAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceMapsAccountRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: maps.ValidateName(),
},
"resource_group_name": azure.SchemaResourceGroupName(),
"sku_name": {
Type: schema.TypeString,
Computed: true,
},
"tags": tags.Schema(),
"x_ms_client_id": {
Type: schema.TypeString,
Computed: true,
},
"primary_access_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"secondary_access_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
},
}
}
func dataSourceMapsAccountRead(d *schema.ResourceData, meta interface{}) error {
ctx := meta.(*ArmClient).StopContext
client := meta.(*ArmClient).maps.AccountsClient
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Maps Account %q was not found in Resource Group %q", name, resourceGroup)
}
return fmt.Errorf("Error making Read request on Maps Account %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if sku := resp.Sku; sku != nil {
d.Set("sku_name", sku.Name)
}
if props := resp.Properties; props != nil {
d.Set("x_ms_client_id", props.XMsClientID)
}
keysResp, err := client.ListKeys(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error reading Access Keys request for Maps Account %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.Set("primary_access_key", keysResp.PrimaryKey)
d.Set("secondary_access_key", keysResp.SecondaryKey)
return tags.FlattenAndSet(d, resp.Tags)
}