forked from hashicorp/terraform-provider-azurerm
/
data_source_batch_account.go
71 lines (57 loc) · 1.84 KB
/
data_source_batch_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
package azurerm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceArmBatchAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmBatchAccountRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateAzureRMBatchAccountName,
},
"resource_group_name": resourceGroupNameForDataSourceSchema(),
"location": locationForDataSourceSchema(),
"storage_account_id": {
Type: schema.TypeString,
Computed: true,
},
"pool_allocation_mode": {
Type: schema.TypeString,
Computed: true,
},
"tags": tagsForDataSourceSchema(),
},
}
}
func dataSourceArmBatchAccountRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).batchAccountClient
resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)
ctx := meta.(*ArmClient).StopContext
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Batch account %q (Resource Group %q) was not found", name, resourceGroup)
}
return fmt.Errorf("Error making Read request on AzureRM Batch account %q: %+v", name, err)
}
d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}
if props := resp.AccountProperties; props != nil {
if autoStorage := props.AutoStorage; autoStorage != nil {
d.Set("storage_account_id", autoStorage.StorageAccountID)
}
d.Set("pool_allocation_mode", props.PoolAllocationMode)
}
flattenAndSetTags(d, resp.Tags)
return nil
}