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_sync_cloud_endpoint #8540

Merged
merged 20 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions azurerm/internal/services/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Client struct {
ADLSGen2PathsClient *paths.Client
ManagementPoliciesClient *storage.ManagementPoliciesClient
BlobServicesClient *storage.BlobServicesClient
CloudEndpointsClient *storagesync.CloudEndpointsClient
EncryptionScopesClient *storage.EncryptionScopesClient
Environment az.Environment
SyncServiceClient *storagesync.ServicesClient
Expand All @@ -55,6 +56,9 @@ func NewClient(options *common.ClientOptions) *Client {
blobServicesClient := storage.NewBlobServicesClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&blobServicesClient.Client, options.ResourceManagerAuthorizer)

cloudEndpointsClient := storagesync.NewCloudEndpointsClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&cloudEndpointsClient.Client, options.ResourceManagerAuthorizer)

encryptionScopesClient := storage.NewEncryptionScopesClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&encryptionScopesClient.Client, options.ResourceManagerAuthorizer)

Expand All @@ -72,6 +76,7 @@ func NewClient(options *common.ClientOptions) *Client {
ADLSGen2PathsClient: &adlsGen2PathsClient,
ManagementPoliciesClient: &managementPoliciesClient,
BlobServicesClient: &blobServicesClient,
CloudEndpointsClient: &cloudEndpointsClient,
EncryptionScopesClient: &encryptionScopesClient,
Environment: options.Environment,
SubscriptionId: options.SubscriptionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 StorageSyncCloudEndpointId struct {
SubscriptionId string
ResourceGroup string
StorageSyncServiceName string
SyncGroupName string
CloudEndpointName string
}

func NewStorageSyncCloudEndpointID(subscriptionId, resourceGroup, storageSyncServiceName, syncGroupName, cloudEndpointName string) StorageSyncCloudEndpointId {
return StorageSyncCloudEndpointId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
StorageSyncServiceName: storageSyncServiceName,
SyncGroupName: syncGroupName,
CloudEndpointName: cloudEndpointName,
}
}

func (id StorageSyncCloudEndpointId) String() string {
segments := []string{
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
fmt.Sprintf("Storage Sync Service Name %q", id.StorageSyncServiceName),
fmt.Sprintf("Sync Group Name %q", id.SyncGroupName),
fmt.Sprintf("Cloud Endpoint Name %q", id.CloudEndpointName),
}
return strings.Join(segments, " / ")
}

func (id StorageSyncCloudEndpointId) ID(_ string) string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StorageSync/storageSyncServices/%s/syncGroups/%s/cloudEndpoints/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.StorageSyncServiceName, id.SyncGroupName, id.CloudEndpointName)
}

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

resourceId := StorageSyncCloudEndpointId{
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.StorageSyncServiceName, err = id.PopSegment("storageSyncServices"); err != nil {
return nil, err
}
if resourceId.SyncGroupName, err = id.PopSegment("syncGroups"); err != nil {
return nil, err
}
if resourceId.CloudEndpointName, err = id.PopSegment("cloudEndpoints"); 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,144 @@
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 = StorageSyncCloudEndpointId{}

func TestStorageSyncCloudEndpointIDFormatter(t *testing.T) {
actual := NewStorageSyncCloudEndpointID("12345678-1234-9876-4563-123456789012", "resGroup1", "storageSyncService1", "syncGroup1", "cloudEndpoint1").ID("")
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.StorageSync/storageSyncServices/storageSyncService1/syncGroups/syncGroup1/cloudEndpoints/cloudEndpoint1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

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

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

{
// missing value for StorageSyncServiceName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.StorageSync/storageSyncServices/",
Error: true,
},

{
// missing SyncGroupName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.StorageSync/storageSyncServices/storageSyncService1/",
Error: true,
},

{
// missing value for SyncGroupName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.StorageSync/storageSyncServices/storageSyncService1/syncGroups/",
Error: true,
},

{
// missing CloudEndpointName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.StorageSync/storageSyncServices/storageSyncService1/syncGroups/syncGroup1/",
Error: true,
},

{
// missing value for CloudEndpointName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.StorageSync/storageSyncServices/storageSyncService1/syncGroups/syncGroup1/cloudEndpoints/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.StorageSync/storageSyncServices/storageSyncService1/syncGroups/syncGroup1/cloudEndpoints/cloudEndpoint1",
Expected: &StorageSyncCloudEndpointId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
StorageSyncServiceName: "storageSyncService1",
SyncGroupName: "syncGroup1",
CloudEndpointName: "cloudEndpoint1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.STORAGESYNC/STORAGESYNCSERVICES/STORAGESYNCSERVICE1/SYNCGROUPS/SYNCGROUP1/CLOUDENDPOINTS/CLOUDENDPOINT1",
Error: true,
},
}

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

actual, err := StorageSyncCloudEndpointID(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.StorageSyncServiceName != v.Expected.StorageSyncServiceName {
t.Fatalf("Expected %q but got %q for StorageSyncServiceName", v.Expected.StorageSyncServiceName, actual.StorageSyncServiceName)
}
if actual.SyncGroupName != v.Expected.SyncGroupName {
t.Fatalf("Expected %q but got %q for SyncGroupName", v.Expected.SyncGroupName, actual.SyncGroupName)
}
if actual.CloudEndpointName != v.Expected.CloudEndpointName {
t.Fatalf("Expected %q but got %q for CloudEndpointName", v.Expected.CloudEndpointName, actual.CloudEndpointName)
}
}
}
1 change: 1 addition & 0 deletions azurerm/internal/services/storage/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource {
"azurerm_storage_table": resourceArmStorageTable(),
"azurerm_storage_table_entity": resourceArmStorageTableEntity(),
"azurerm_storage_sync": resourceArmStorageSync(),
"azurerm_storage_sync_cloud_endpoint": resourceArmStorageSyncCloudEndpoint(),
"azurerm_storage_sync_group": resourceArmStorageSyncGroup(),
}
}
Loading