Skip to content

Commit a4abb0e

Browse files
committed
Merge pull request hashicorp#4739 from hashicorp/b-azurerm-resource-id-parsing
provider/azurerm: Parse "resourcegroups" in IDs
2 parents 8e5108b + c3ce8b8 commit a4abb0e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

builtin/providers/azurerm/resourceid.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ func parseAzureResourceID(id string) (*ResourceID, error) {
6969
idObj.ResourceGroup = resourceGroup
7070
delete(componentMap, "resourceGroups")
7171
} else {
72-
return nil, fmt.Errorf("No resource group name found in: %q", path)
72+
// Some Azure APIs are weird and provide things in lower case...
73+
// However it's not clear whether the casing of other elements in the URI
74+
// matter, so we explicitly look for that case here.
75+
if resourceGroup, ok := componentMap["resourcegroups"]; ok {
76+
idObj.ResourceGroup = resourceGroup
77+
delete(componentMap, "resourcegroups")
78+
} else {
79+
return nil, fmt.Errorf("No resource group name found in: %q", path)
80+
}
7381
}
7482

7583
// It is OK not to have a provider in the case of a resource group

builtin/providers/azurerm/resourceid_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ func TestParseAzureResourceID(t *testing.T) {
8989
},
9090
false,
9191
},
92+
{
93+
"/subscriptions/34ca515c-4629-458e-bf7c-738d77e0d0ea/resourcegroups/acceptanceTestResourceGroup1/providers/Microsoft.Cdn/profiles/acceptanceTestCdnProfile1",
94+
&ResourceID{
95+
SubscriptionID: "34ca515c-4629-458e-bf7c-738d77e0d0ea",
96+
ResourceGroup: "acceptanceTestResourceGroup1",
97+
Provider: "Microsoft.Cdn",
98+
Path: map[string]string{
99+
"profiles": "acceptanceTestCdnProfile1",
100+
},
101+
},
102+
false,
103+
},
92104
}
93105

94106
for _, test := range testCases {

0 commit comments

Comments
 (0)