Merge pull request #4739 from hashicorp/b-azurerm-resource-id-parsing

provider/azurerm: Parse "resourcegroups" in IDs
This commit is contained in:
James Nugent 2016-01-19 11:42:45 -05:00
commit a4abb0e66c
2 changed files with 21 additions and 1 deletions

View File

@ -69,7 +69,15 @@ func parseAzureResourceID(id string) (*ResourceID, error) {
idObj.ResourceGroup = resourceGroup
delete(componentMap, "resourceGroups")
} else {
return nil, fmt.Errorf("No resource group name found in: %q", path)
// Some Azure APIs are weird and provide things in lower case...
// However it's not clear whether the casing of other elements in the URI
// matter, so we explicitly look for that case here.
if resourceGroup, ok := componentMap["resourcegroups"]; ok {
idObj.ResourceGroup = resourceGroup
delete(componentMap, "resourcegroups")
} else {
return nil, fmt.Errorf("No resource group name found in: %q", path)
}
}
// It is OK not to have a provider in the case of a resource group

View File

@ -89,6 +89,18 @@ func TestParseAzureResourceID(t *testing.T) {
},
false,
},
{
"/subscriptions/34ca515c-4629-458e-bf7c-738d77e0d0ea/resourcegroups/acceptanceTestResourceGroup1/providers/Microsoft.Cdn/profiles/acceptanceTestCdnProfile1",
&ResourceID{
SubscriptionID: "34ca515c-4629-458e-bf7c-738d77e0d0ea",
ResourceGroup: "acceptanceTestResourceGroup1",
Provider: "Microsoft.Cdn",
Path: map[string]string{
"profiles": "acceptanceTestCdnProfile1",
},
},
false,
},
}
for _, test := range testCases {