Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MS] provider/azurerm: Data Source for Azure Resource Group #15022

Merged
merged 9 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Change location to computed.
  • Loading branch information
whiskeyjay committed Jun 7, 2017
commit dbe93e4d6b81404b10abc9713638d5cb0b19f88f
20 changes: 4 additions & 16 deletions builtin/providers/azurerm/data_source_arm_resource_group.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package azurerm

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
)

Expand All @@ -26,31 +24,21 @@ func dataSourceArmResourceGroupRead(d *schema.ResourceData, meta interface{}) er
armClient := meta.(*ArmClient)

resourceGroupName := d.Get("name").(string)
location, getLocationOk := d.GetOk("location")
resourceId := &ResourceID{
SubscriptionID: armClient.subscriptionId,
ResourceGroup: resourceGroupName,
}
resourceIdString, err := composeAzureResourceID(resourceId)

if resourceIdString, err := composeAzureResourceID(resourceId); err == nil {
d.SetId(resourceIdString)
} else {
if err != nil {
return err
}

d.SetId(resourceIdString)

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
}
7 changes: 2 additions & 5 deletions builtin/providers/azurerm/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ func locationSchema() *schema.Schema {

func locationForDataSourceSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
StateFunc: azureRMNormalizeLocation,
DiffSuppressFunc: azureRMSuppressLocationDiff,
Type: schema.TypeString,
Computed: true,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ resource "azurerm_managed_disk" "test" {
## Argument Reference

* `name` - (Required) Specifies the name of the resource group.
* `location` - (Optional) Specifies the location of the resource group.

~> **NOTE:** If the specified location doesn't match the actual resource group location, an error message with the actual location value will be shown.

## Attributes Reference

* `location` - The location of the resource group.
* `tags` - A mapping of tags assigned to the resource group.