diff --git a/builtin/providers/azurerm/resourceid.go b/builtin/providers/azurerm/resourceid.go index 281bd8f9b..4f89945e7 100644 --- a/builtin/providers/azurerm/resourceid.go +++ b/builtin/providers/azurerm/resourceid.go @@ -53,6 +53,11 @@ func parseAzureResourceID(id string) (*ResourceID, error) { key := components[current] value := components[current+1] + // Check key/value for empty strings. + if key == "" || value == "" { + return nil, fmt.Errorf("Key/Value cannot be empty strings. Key: '%s', Value: '%s'", key, value) + } + // Catch the subscriptionID before it can be overwritten by another "subscriptions" // value in the ID which is the case for the Service Bus subscription resource if key == "subscriptions" && subscriptionID == "" { diff --git a/builtin/providers/azurerm/resourceid_test.go b/builtin/providers/azurerm/resourceid_test.go index dff6ed800..4359b70d1 100644 --- a/builtin/providers/azurerm/resourceid_test.go +++ b/builtin/providers/azurerm/resourceid_test.go @@ -11,6 +11,18 @@ func TestParseAzureResourceID(t *testing.T) { expectedResourceID *ResourceID expectError bool }{ + { + // Missing "resourceGroups". + "/subscriptions/00000000-0000-0000-0000-000000000000//myResourceGroup/", + nil, + true, + }, + { + // Empty resource group ID. + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//", + nil, + true, + }, { "random", nil,