Skip to content

Commit 01ad9fd

Browse files
storagemover: validate multi-cloud ARM IDs, document env vars and MS Learn
Made-with: Cursor
1 parent ca671c8 commit 01ad9fd

5 files changed

+89
-5
lines changed

internal/services/storagemover/storage_mover_multi_cloud_connector_endpoint_resource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
1515
"github.com/hashicorp/go-azure-sdk/resource-manager/storagemover/2025-07-01/endpoints"
1616
"github.com/hashicorp/go-azure-sdk/resource-manager/storagemover/2025-07-01/storagemovers"
17-
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
1817
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
18+
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storagemover/validate"
1919
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
2020
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
2121
)
@@ -74,14 +74,14 @@ func (r StorageMoverMultiCloudConnectorEndpointResource) Arguments() map[string]
7474
Type: pluginsdk.TypeString,
7575
Required: true,
7676
ForceNew: true,
77-
ValidateFunc: azure.ValidateResourceID,
77+
ValidateFunc: validate.MultiCloudConnectorARMResourceID,
7878
},
7979

8080
"aws_s3_bucket_id": {
8181
Type: pluginsdk.TypeString,
8282
Required: true,
8383
ForceNew: true,
84-
ValidateFunc: azure.ValidateResourceID,
84+
ValidateFunc: validate.AwsS3BucketARMResourceID,
8585
},
8686

8787
"description": {

internal/services/storagemover/storage_mover_multi_cloud_connector_endpoint_resource_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

4+
// Acceptance tests for this resource require real Azure resources that are not created by these tests:
5+
// - ARM_TEST_MULTI_CLOUD_CONNECTOR_ID — resource ID of a Microsoft.HybridConnectivity/publicCloudConnectors instance
6+
// - ARM_TEST_AWS_S3_BUCKET_ID — resource ID of a Microsoft.AwsConnector/s3Buckets instance linked for cloud-to-cloud migration
7+
//
8+
// Create those prerequisites in the portal or via ARM as described in
9+
// https://learn.microsoft.com/azure/storage-mover/cloud-to-cloud-migration
10+
// then export the two IDs into the environment before running TF_ACC for this package.
11+
412
package storagemover_test
513

614
import (
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package validate
5+
6+
import (
7+
"fmt"
8+
"strings"
9+
10+
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
11+
)
12+
13+
// MultiCloudConnectorARMResourceID validates a full ARM resource ID for a Hybrid Connectivity public cloud connector.
14+
// See https://learn.microsoft.com/rest/api/storagemover/endpoints/create-or-update
15+
func MultiCloudConnectorARMResourceID(i interface{}, k string) (warnings []string, errors []error) {
16+
warnings, errors = azure.ValidateResourceID(i, k)
17+
if len(errors) > 0 {
18+
return warnings, errors
19+
}
20+
21+
id := strings.ToLower(i.(string))
22+
if !strings.Contains(id, "/providers/microsoft.hybridconnectivity/publiccloudconnectors/") {
23+
errors = append(errors, fmt.Errorf("%q must be the resource ID of a Microsoft.HybridConnectivity/publicCloudConnectors resource", k))
24+
}
25+
return warnings, errors
26+
}
27+
28+
// AwsS3BucketARMResourceID validates a full ARM resource ID for an AWS S3 bucket resource exposed through Microsoft.AwsConnector.
29+
func AwsS3BucketARMResourceID(i interface{}, k string) (warnings []string, errors []error) {
30+
warnings, errors = azure.ValidateResourceID(i, k)
31+
if len(errors) > 0 {
32+
return warnings, errors
33+
}
34+
35+
id := strings.ToLower(i.(string))
36+
if !strings.Contains(id, "/providers/microsoft.awsconnector/s3buckets/") {
37+
errors = append(errors, fmt.Errorf("%q must be the resource ID of a Microsoft.AwsConnector/s3Buckets resource", k))
38+
}
39+
return warnings, errors
40+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package validate
5+
6+
import "testing"
7+
8+
func TestMultiCloudConnectorARMResourceID(t *testing.T) {
9+
t.Parallel()
10+
11+
valid := "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.HybridConnectivity/publicCloudConnectors/c1"
12+
_, errs := MultiCloudConnectorARMResourceID(valid, "multi_cloud_connector_id")
13+
if len(errs) > 0 {
14+
t.Fatalf("expected valid id, got %v", errs)
15+
}
16+
17+
_, errs = MultiCloudConnectorARMResourceID("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Storage/storageAccounts/sa", "multi_cloud_connector_id")
18+
if len(errs) == 0 {
19+
t.Fatal("expected error for wrong resource type")
20+
}
21+
}
22+
23+
func TestAwsS3BucketARMResourceID(t *testing.T) {
24+
t.Parallel()
25+
26+
valid := "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.AwsConnector/s3Buckets/b1"
27+
_, errs := AwsS3BucketARMResourceID(valid, "aws_s3_bucket_id")
28+
if len(errs) > 0 {
29+
t.Fatalf("expected valid id, got %v", errs)
30+
}
31+
32+
_, errs = AwsS3BucketARMResourceID("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Storage/storageAccounts/sa", "aws_s3_bucket_id")
33+
if len(errs) == 0 {
34+
t.Fatal("expected error for wrong resource type")
35+
}
36+
}

website/docs/r/storage_mover_multi_cloud_connector_endpoint.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: |-
88

99
# azurerm_storage_mover_multi_cloud_connector_endpoint
1010

11-
Manages a Storage Mover Multi-Cloud Connector Endpoint for migrating data from AWS S3 to Azure.
11+
Manages a Storage Mover **Target Endpoint** of type Multi-Cloud Connector for [cloud-to-cloud migration](https://learn.microsoft.com/azure/storage-mover/cloud-to-cloud-migration) from AWS S3 to Azure. In the Azure portal this appears under **Storage Mover** → your storage mover → **Endpoints** when creating an endpoint that uses a multi-cloud connector and AWS S3 bucket.
1212

1313
## Example Usage
1414

@@ -28,7 +28,7 @@ resource "azurerm_storage_mover_multi_cloud_connector_endpoint" "example" {
2828
name = "example-mcce"
2929
storage_mover_id = azurerm_storage_mover.example.id
3030
multi_cloud_connector_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.HybridConnectivity/publicCloudConnectors/example-connector"
31-
aws_s3_bucket_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aws-rg/providers/Microsoft.AWSConnector/s3Buckets/example-bucket"
31+
aws_s3_bucket_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aws-rg/providers/Microsoft.AwsConnector/s3Buckets/example-bucket"
3232
description = "Example Multi-Cloud Connector Endpoint"
3333
}
3434
```

0 commit comments

Comments
 (0)