-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19969 from jennings/storage-queue-resource-manage…
…r-id resource `azurerm_storage_queue` - add `resource_manager_id`
- Loading branch information
Showing
6 changed files
with
358 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
internal/services/storage/parse/storage_queue_resource_manager.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package parse | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" | ||
) | ||
|
||
type StorageQueueResourceManagerId struct { | ||
SubscriptionId string | ||
ResourceGroup string | ||
StorageAccountName string | ||
QueueServiceName string | ||
QueueName string | ||
} | ||
|
||
func NewStorageQueueResourceManagerID(subscriptionId, resourceGroup, storageAccountName, queueServiceName, queueName string) StorageQueueResourceManagerId { | ||
return StorageQueueResourceManagerId{ | ||
SubscriptionId: subscriptionId, | ||
ResourceGroup: resourceGroup, | ||
StorageAccountName: storageAccountName, | ||
QueueServiceName: queueServiceName, | ||
QueueName: queueName, | ||
} | ||
} | ||
|
||
func (id StorageQueueResourceManagerId) String() string { | ||
segments := []string{ | ||
fmt.Sprintf("Queue Name %q", id.QueueName), | ||
fmt.Sprintf("Queue Service Name %q", id.QueueServiceName), | ||
fmt.Sprintf("Storage Account Name %q", id.StorageAccountName), | ||
fmt.Sprintf("Resource Group %q", id.ResourceGroup), | ||
} | ||
segmentsStr := strings.Join(segments, " / ") | ||
return fmt.Sprintf("%s: (%s)", "Storage Queue Resource Manager", segmentsStr) | ||
} | ||
|
||
func (id StorageQueueResourceManagerId) ID() string { | ||
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Storage/storageAccounts/%s/queueServices/%s/queues/%s" | ||
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.StorageAccountName, id.QueueServiceName, id.QueueName) | ||
} | ||
|
||
// StorageQueueResourceManagerID parses a StorageQueueResourceManager ID into an StorageQueueResourceManagerId struct | ||
func StorageQueueResourceManagerID(input string) (*StorageQueueResourceManagerId, error) { | ||
id, err := resourceids.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resourceId := StorageQueueResourceManagerId{ | ||
SubscriptionId: id.SubscriptionID, | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if resourceId.SubscriptionId == "" { | ||
return nil, fmt.Errorf("ID was missing the 'subscriptions' element") | ||
} | ||
|
||
if resourceId.ResourceGroup == "" { | ||
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") | ||
} | ||
|
||
if resourceId.StorageAccountName, err = id.PopSegment("storageAccounts"); err != nil { | ||
return nil, err | ||
} | ||
if resourceId.QueueServiceName, err = id.PopSegment("queueServices"); err != nil { | ||
return nil, err | ||
} | ||
if resourceId.QueueName, err = id.PopSegment("queues"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &resourceId, nil | ||
} |
144 changes: 144 additions & 0 deletions
144
internal/services/storage/parse/storage_queue_resource_manager_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package parse | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" | ||
) | ||
|
||
var _ resourceids.Id = StorageQueueResourceManagerId{} | ||
|
||
func TestStorageQueueResourceManagerIDFormatter(t *testing.T) { | ||
actual := NewStorageQueueResourceManagerID("12345678-1234-9876-4563-123456789012", "resGroup1", "storageAccount1", "default", "queue1").ID() | ||
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/default/queues/queue1" | ||
if actual != expected { | ||
t.Fatalf("Expected %q but got %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestStorageQueueResourceManagerID(t *testing.T) { | ||
testData := []struct { | ||
Input string | ||
Error bool | ||
Expected *StorageQueueResourceManagerId | ||
}{ | ||
|
||
{ | ||
// empty | ||
Input: "", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing SubscriptionId | ||
Input: "/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for SubscriptionId | ||
Input: "/subscriptions/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing ResourceGroup | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for ResourceGroup | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing StorageAccountName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for StorageAccountName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing QueueServiceName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for QueueServiceName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing QueueName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/default/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for QueueName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/default/queues/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// valid | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/default/queues/queue1", | ||
Expected: &StorageQueueResourceManagerId{ | ||
SubscriptionId: "12345678-1234-9876-4563-123456789012", | ||
ResourceGroup: "resGroup1", | ||
StorageAccountName: "storageAccount1", | ||
QueueServiceName: "default", | ||
QueueName: "queue1", | ||
}, | ||
}, | ||
|
||
{ | ||
// upper-cased | ||
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.STORAGE/STORAGEACCOUNTS/STORAGEACCOUNT1/QUEUESERVICES/DEFAULT/QUEUES/QUEUE1", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Input) | ||
|
||
actual, err := StorageQueueResourceManagerID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expect a value but got an error: %s", err) | ||
} | ||
if v.Error { | ||
t.Fatal("Expect an error but didn't get one") | ||
} | ||
|
||
if actual.SubscriptionId != v.Expected.SubscriptionId { | ||
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) | ||
} | ||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
if actual.StorageAccountName != v.Expected.StorageAccountName { | ||
t.Fatalf("Expected %q but got %q for StorageAccountName", v.Expected.StorageAccountName, actual.StorageAccountName) | ||
} | ||
if actual.QueueServiceName != v.Expected.QueueServiceName { | ||
t.Fatalf("Expected %q but got %q for QueueServiceName", v.Expected.QueueServiceName, actual.QueueServiceName) | ||
} | ||
if actual.QueueName != v.Expected.QueueName { | ||
t.Fatalf("Expected %q but got %q for QueueName", v.Expected.QueueName, actual.QueueName) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
internal/services/storage/validate/storage_queue_resource_manager_id.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package validate | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/parse" | ||
) | ||
|
||
func StorageQueueResourceManagerID(input interface{}, key string) (warnings []string, errors []error) { | ||
v, ok := input.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected %q to be a string", key)) | ||
return | ||
} | ||
|
||
if _, err := parse.StorageQueueResourceManagerID(v); err != nil { | ||
errors = append(errors, err) | ||
} | ||
|
||
return | ||
} |
100 changes: 100 additions & 0 deletions
100
internal/services/storage/validate/storage_queue_resource_manager_id_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package validate | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import "testing" | ||
|
||
func TestStorageQueueResourceManagerID(t *testing.T) { | ||
cases := []struct { | ||
Input string | ||
Valid bool | ||
}{ | ||
|
||
{ | ||
// empty | ||
Input: "", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing SubscriptionId | ||
Input: "/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing value for SubscriptionId | ||
Input: "/subscriptions/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing ResourceGroup | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing value for ResourceGroup | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing StorageAccountName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing value for StorageAccountName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing QueueServiceName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing value for QueueServiceName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing QueueName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/default/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// missing value for QueueName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/default/queues/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
// valid | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/queueServices/default/queues/queue1", | ||
Valid: true, | ||
}, | ||
|
||
{ | ||
// upper-cased | ||
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.STORAGE/STORAGEACCOUNTS/STORAGEACCOUNT1/QUEUESERVICES/DEFAULT/QUEUES/QUEUE1", | ||
Valid: false, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Logf("[DEBUG] Testing Value %s", tc.Input) | ||
_, errors := StorageQueueResourceManagerID(tc.Input, "test") | ||
valid := len(errors) == 0 | ||
|
||
if tc.Valid != valid { | ||
t.Fatalf("Expected %t but got %t", tc.Valid, valid) | ||
} | ||
} | ||
} |