Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource azurerm_storage_object_replication_policy #11744

Merged
merged 11 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions azurerm/internal/services/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ import (
)

type Client struct {
AccountsClient *storage.AccountsClient
FileSystemsClient *filesystems.Client
ADLSGen2PathsClient *paths.Client
ManagementPoliciesClient *storage.ManagementPoliciesClient
BlobServicesClient *storage.BlobServicesClient
BlobInventoryPoliciesClient *storage.BlobInventoryPoliciesClient
CloudEndpointsClient *storagesync.CloudEndpointsClient
EncryptionScopesClient *storage.EncryptionScopesClient
Environment az.Environment
SyncServiceClient *storagesync.ServicesClient
SyncGroupsClient *storagesync.SyncGroupsClient
SubscriptionId string
AccountsClient *storage.AccountsClient
FileSystemsClient *filesystems.Client
ADLSGen2PathsClient *paths.Client
ManagementPoliciesClient *storage.ManagementPoliciesClient
BlobServicesClient *storage.BlobServicesClient
BlobInventoryPoliciesClient *storage.BlobInventoryPoliciesClient
CloudEndpointsClient *storagesync.CloudEndpointsClient
EncryptionScopesClient *storage.EncryptionScopesClient
Environment az.Environment
ObjectReplicationPolicyClient *storage.ObjectReplicationPoliciesClient
SyncServiceClient *storagesync.ServicesClient
SyncGroupsClient *storagesync.SyncGroupsClient
SubscriptionId string

resourceManagerAuthorizer autorest.Authorizer
storageAdAuth *autorest.Authorizer
Expand Down Expand Up @@ -66,6 +67,9 @@ func NewClient(options *common.ClientOptions) *Client {
encryptionScopesClient := storage.NewEncryptionScopesClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&encryptionScopesClient.Client, options.ResourceManagerAuthorizer)

objectReplicationPolicyClient := storage.NewObjectReplicationPoliciesClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&objectReplicationPolicyClient.Client, options.ResourceManagerAuthorizer)

syncServiceClient := storagesync.NewServicesClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&syncServiceClient.Client, options.ResourceManagerAuthorizer)

Expand All @@ -75,18 +79,19 @@ func NewClient(options *common.ClientOptions) *Client {
// TODO: switch Storage Containers to using the storage.BlobContainersClient
// (which should fix #2977) when the storage clients have been moved in here
client := Client{
AccountsClient: &accountsClient,
FileSystemsClient: &fileSystemsClient,
ADLSGen2PathsClient: &adlsGen2PathsClient,
ManagementPoliciesClient: &managementPoliciesClient,
BlobServicesClient: &blobServicesClient,
BlobInventoryPoliciesClient: &blobInventoryPoliciesClient,
CloudEndpointsClient: &cloudEndpointsClient,
EncryptionScopesClient: &encryptionScopesClient,
Environment: options.Environment,
SubscriptionId: options.SubscriptionId,
SyncServiceClient: &syncServiceClient,
SyncGroupsClient: &syncGroupsClient,
AccountsClient: &accountsClient,
FileSystemsClient: &fileSystemsClient,
ADLSGen2PathsClient: &adlsGen2PathsClient,
ManagementPoliciesClient: &managementPoliciesClient,
BlobServicesClient: &blobServicesClient,
BlobInventoryPoliciesClient: &blobInventoryPoliciesClient,
CloudEndpointsClient: &cloudEndpointsClient,
EncryptionScopesClient: &encryptionScopesClient,
Environment: options.Environment,
ObjectReplicationPolicyClient: &objectReplicationPolicyClient,
SubscriptionId: options.SubscriptionId,
SyncServiceClient: &syncServiceClient,
SyncGroupsClient: &syncGroupsClient,

resourceManagerAuthorizer: options.ResourceManagerAuthorizer,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type ObjectReplicationPolicyId struct {
SubscriptionId string
ResourceGroup string
StorageAccountName string
Name string
}

func NewObjectReplicationPolicyID(subscriptionId, resourceGroup, storageAccountName, name string) ObjectReplicationPolicyId {
return ObjectReplicationPolicyId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
StorageAccountName: storageAccountName,
Name: name,
}
}

func (id ObjectReplicationPolicyId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Storage Account Name %q", id.StorageAccountName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Object Replication Policy", segmentsStr)
}

func (id ObjectReplicationPolicyId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Storage/storageAccounts/%s/objectReplicationPolicies/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.StorageAccountName, id.Name)
}

// ObjectReplicationPolicyID parses a ObjectReplicationPolicy ID into an ObjectReplicationPolicyId struct
func ObjectReplicationPolicyID(input string) (*ObjectReplicationPolicyId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := ObjectReplicationPolicyId{
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.Name, err = id.PopSegment("objectReplicationPolicies"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/resourceid"
)

var _ resourceid.Formatter = ObjectReplicationPolicyId{}

func TestObjectReplicationPolicyIDFormatter(t *testing.T) {
actual := NewObjectReplicationPolicyID("12345678-1234-9876-4563-123456789012", "resGroup1", "storageAccount1", "objectReplicationPolicy1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/objectReplicationPolicies/objectReplicationPolicy1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestObjectReplicationPolicyID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *ObjectReplicationPolicyId
}{

{
// 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 Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/",
Error: true,
},

{
// missing value for Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/objectReplicationPolicies/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/objectReplicationPolicies/objectReplicationPolicy1",
Expected: &ObjectReplicationPolicyId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
StorageAccountName: "storageAccount1",
Name: "objectReplicationPolicy1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.STORAGE/STORAGEACCOUNTS/STORAGEACCOUNT1/OBJECTREPLICATIONPOLICIES/OBJECTREPLICATIONPOLICY1",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Input)

actual, err := ObjectReplicationPolicyID(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.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
}
}
1 change: 1 addition & 0 deletions azurerm/internal/services/storage/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
"azurerm_storage_data_lake_gen2_filesystem": resourceStorageDataLakeGen2FileSystem(),
"azurerm_storage_data_lake_gen2_path": resourceStorageDataLakeGen2Path(),
"azurerm_storage_management_policy": resourceStorageManagementPolicy(),
"azurerm_storage_object_replication_policy": resourceStorageObjectReplicationPolicy(),
"azurerm_storage_queue": resourceStorageQueue(),
"azurerm_storage_share": resourceStorageShare(),
"azurerm_storage_share_file": resourceStorageShareFile(),
Expand Down
1 change: 1 addition & 0 deletions azurerm/internal/services/storage/resourceids.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package storage

//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=BlobInventoryPolicy -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/inventoryPolicies/inventoryPolicy1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=EncryptionScope -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/encryptionScopes/encryptionScope1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ObjectReplicationPolicy -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/objectReplicationPolicies/objectReplicationPolicy1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=StorageAccount -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=StorageContainerResourceManager -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/blobServices/default/containers/container1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=StorageShareResourceManager -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storageAccount1/fileServices/fileService1/fileshares/share1
Expand Down
Loading