-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
data_source_dev_test_lab.go
112 lines (88 loc) · 3.05 KB
/
data_source_dev_test_lab.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
package azurerm
import (
"fmt"
"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 dataSourceArmDevTestLab() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmDevTestLabRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.DevTestLabName(),
},
"location": azure.SchemaLocationForDataSource(),
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
"storage_type": {
Type: schema.TypeString,
Computed: true,
},
"tags": tags.SchemaDataSource(),
"artifacts_storage_account_id": {
Type: schema.TypeString,
Computed: true,
},
"default_storage_account_id": {
Type: schema.TypeString,
Computed: true,
},
"default_premium_storage_account_id": {
Type: schema.TypeString,
Computed: true,
},
"key_vault_id": {
Type: schema.TypeString,
Computed: true,
},
"premium_data_disk_storage_account_id": {
Type: schema.TypeString,
Computed: true,
},
"unique_identifier": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceArmDevTestLabRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).DevTestLabs.LabsClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
read, err := client.Get(ctx, resourceGroup, name, "")
if err != nil {
if utils.ResponseWasNotFound(read.Response) {
return fmt.Errorf("DevTest Lab %q was not found in Resource Group %q", name, resourceGroup)
}
return fmt.Errorf("Error making Read request on DevTest Lab %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.SetId(*read.ID)
d.Set("name", read.Name)
d.Set("resource_group_name", resourceGroup)
if location := read.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
if props := read.LabProperties; props != nil {
d.Set("storage_type", string(props.LabStorageType))
// Computed fields
d.Set("artifacts_storage_account_id", props.ArtifactsStorageAccount)
d.Set("default_storage_account_id", props.DefaultStorageAccount)
d.Set("default_premium_storage_account_id", props.DefaultPremiumStorageAccount)
d.Set("key_vault_id", props.VaultName)
d.Set("premium_data_disk_storage_account_id", props.PremiumDataDiskStorageAccount)
d.Set("unique_identifier", props.UniqueIdentifier)
}
return tags.FlattenAndSet(d, read.Tags)
}