forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_arm_resource_group.go
49 lines (37 loc) · 1.21 KB
/
data_source_arm_resource_group.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
package azurerm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceArmResourceGroup() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmResourceGroupRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"location": locationForDataSourceSchema(),
"tags": tagsForDataSourceSchema(),
},
}
}
func dataSourceArmResourceGroupRead(d *schema.ResourceData, meta interface{}) error {
armClient := meta.(*ArmClient)
resourceGroupName := d.Get("name").(string)
location, getLocationOk := d.GetOk("location")
resourceId := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s", armClient.subscriptionId, resourceGroupName)
d.SetId(resourceId)
if err := resourceArmResourceGroupRead(d, meta); err != nil {
return err
}
if getLocationOk {
actualLocation := azureRMNormalizeLocation(d.Get("location").(string))
location := azureRMNormalizeLocation(location)
if location != actualLocation {
return fmt.Errorf(`The location specified in Data Source (%s) doesn't match the actual location of the Resource Group "%s (%s)"`,
location, resourceGroupName, actualLocation)
}
}
return nil
}