-
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.
new resource: azurerm_storage_container_immutability_policy
- Loading branch information
1 parent
75d6f38
commit 24eddf6
Showing
9 changed files
with
1,030 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
internal/services/storage/parse/storage_container_immutability_policy.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,90 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
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 StorageContainerImmutabilityPolicyId struct { | ||
SubscriptionId string | ||
ResourceGroup string | ||
StorageAccountName string | ||
BlobServiceName string | ||
ContainerName string | ||
ImmutabilityPolicyName string | ||
} | ||
|
||
func NewStorageContainerImmutabilityPolicyID(subscriptionId, resourceGroup, storageAccountName, blobServiceName, containerName, immutabilityPolicyName string) StorageContainerImmutabilityPolicyId { | ||
return StorageContainerImmutabilityPolicyId{ | ||
SubscriptionId: subscriptionId, | ||
ResourceGroup: resourceGroup, | ||
StorageAccountName: storageAccountName, | ||
BlobServiceName: blobServiceName, | ||
ContainerName: containerName, | ||
ImmutabilityPolicyName: immutabilityPolicyName, | ||
} | ||
} | ||
|
||
func (id StorageContainerImmutabilityPolicyId) String() string { | ||
segments := []string{ | ||
fmt.Sprintf("Immutability Policy Name %q", id.ImmutabilityPolicyName), | ||
fmt.Sprintf("Container Name %q", id.ContainerName), | ||
fmt.Sprintf("Blob Service Name %q", id.BlobServiceName), | ||
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 Container Immutability Policy", segmentsStr) | ||
} | ||
|
||
func (id StorageContainerImmutabilityPolicyId) ID() string { | ||
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Storage/storageAccounts/%s/blobServices/%s/containers/%s/immutabilityPolicies/%s" | ||
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.StorageAccountName, id.BlobServiceName, id.ContainerName, id.ImmutabilityPolicyName) | ||
} | ||
|
||
// StorageContainerImmutabilityPolicyID parses a StorageContainerImmutabilityPolicy ID into an StorageContainerImmutabilityPolicyId struct | ||
func StorageContainerImmutabilityPolicyID(input string) (*StorageContainerImmutabilityPolicyId, error) { | ||
id, err := resourceids.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing %q as an StorageContainerImmutabilityPolicy ID: %+v", input, err) | ||
} | ||
|
||
resourceId := StorageContainerImmutabilityPolicyId{ | ||
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.BlobServiceName, err = id.PopSegment("blobServices"); err != nil { | ||
return nil, err | ||
} | ||
if resourceId.ContainerName, err = id.PopSegment("containers"); err != nil { | ||
return nil, err | ||
} | ||
if resourceId.ImmutabilityPolicyName, err = id.PopSegment("immutabilityPolicies"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &resourceId, nil | ||
} |
163 changes: 163 additions & 0 deletions
163
internal/services/storage/parse/storage_container_immutability_policy_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,163 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
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 = StorageContainerImmutabilityPolicyId{} | ||
|
||
func TestStorageContainerImmutabilityPolicyIDFormatter(t *testing.T) { | ||
actual := NewStorageContainerImmutabilityPolicyID("12345678-1234-9876-4563-123456789012", "resGroup1", "storageAccount1", "default", "container1", "default").ID() | ||
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/blobServices/default/containers/container1/immutabilityPolicies/default" | ||
if actual != expected { | ||
t.Fatalf("Expected %q but got %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestStorageContainerImmutabilityPolicyID(t *testing.T) { | ||
testData := []struct { | ||
Input string | ||
Error bool | ||
Expected *StorageContainerImmutabilityPolicyId | ||
}{ | ||
|
||
{ | ||
// 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 BlobServiceName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for BlobServiceName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/blobServices/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing ContainerName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/blobServices/default/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for ContainerName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/blobServices/default/containers/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing ImmutabilityPolicyName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/blobServices/default/containers/container1/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for ImmutabilityPolicyName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/blobServices/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// valid | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/blobServices/default/containers/container1/immutabilityPolicies/default", | ||
Expected: &StorageContainerImmutabilityPolicyId{ | ||
SubscriptionId: "12345678-1234-9876-4563-123456789012", | ||
ResourceGroup: "resGroup1", | ||
StorageAccountName: "storageAccount1", | ||
BlobServiceName: "default", | ||
ContainerName: "container1", | ||
ImmutabilityPolicyName: "default", | ||
}, | ||
}, | ||
|
||
{ | ||
// upper-cased | ||
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.STORAGE/STORAGEACCOUNTS/STORAGEACCOUNT1/BLOBSERVICES/DEFAULT/CONTAINERS/CONTAINER1/IMMUTABILITYPOLICIES/DEFAULT", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Input) | ||
|
||
actual, err := StorageContainerImmutabilityPolicyID(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.BlobServiceName != v.Expected.BlobServiceName { | ||
t.Fatalf("Expected %q but got %q for BlobServiceName", v.Expected.BlobServiceName, actual.BlobServiceName) | ||
} | ||
if actual.ContainerName != v.Expected.ContainerName { | ||
t.Fatalf("Expected %q but got %q for ContainerName", v.Expected.ContainerName, actual.ContainerName) | ||
} | ||
if actual.ImmutabilityPolicyName != v.Expected.ImmutabilityPolicyName { | ||
t.Fatalf("Expected %q but got %q for ImmutabilityPolicyName", v.Expected.ImmutabilityPolicyName, actual.ImmutabilityPolicyName) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.