-
Notifications
You must be signed in to change notification settings - Fork 5k
list and identity implementation : azurerm_storage_sync_server_endpoint #31988
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
Open
aayushsingh2502
wants to merge
4
commits into
main
Choose a base branch
from
strgsyncserver_identity_list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bb4c834
list and identity implementation
aayushsingh2502 1295b7f
doc update and bug fix in list test
aayushsingh2502 cf8759f
Merge branch 'main' into strgsyncserver_identity_list
aayushsingh2502 2acf3e1
rearranged entry in registration.go
aayushsingh2502 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
internal/services/storage/storage_sync_server_endpoint_resource_identity_gen_test.go
This file contains hidden or 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,42 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package storage_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/statecheck" | ||
| "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
| customstatecheck "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/statecheck" | ||
| ) | ||
|
|
||
| func testAccStorageSyncServerEndpoint_resourceIdentity(t *testing.T) { | ||
| data := acceptance.BuildTestData(t, "azurerm_storage_sync_server_endpoint", "test") | ||
| r := StorageSyncServerEndpointResource{} | ||
|
|
||
| checkedFields := map[string]struct{}{ | ||
| "name": {}, | ||
| "resource_group_name": {}, | ||
| "storage_sync_service_name": {}, | ||
| "subscription_id": {}, | ||
| "sync_group_name": {}, | ||
| } | ||
|
|
||
| data.ResourceIdentityTest(t, []acceptance.TestStep{ | ||
| { | ||
| Config: r.basic(data), | ||
| ConfigStateChecks: []statecheck.StateCheck{ | ||
| customstatecheck.ExpectAllIdentityFieldsAreChecked("azurerm_storage_sync_server_endpoint.test", checkedFields), | ||
| statecheck.ExpectIdentityValueMatchesStateAtPath("azurerm_storage_sync_server_endpoint.test", tfjsonpath.New("name"), tfjsonpath.New("name")), | ||
| customstatecheck.ExpectStateContainsIdentityValueAtPath("azurerm_storage_sync_server_endpoint.test", tfjsonpath.New("resource_group_name"), tfjsonpath.New("storage_sync_group_id")), | ||
| customstatecheck.ExpectStateContainsIdentityValueAtPath("azurerm_storage_sync_server_endpoint.test", tfjsonpath.New("storage_sync_service_name"), tfjsonpath.New("storage_sync_group_id")), | ||
| customstatecheck.ExpectStateContainsIdentityValueAtPath("azurerm_storage_sync_server_endpoint.test", tfjsonpath.New("subscription_id"), tfjsonpath.New("storage_sync_group_id")), | ||
| customstatecheck.ExpectStateContainsIdentityValueAtPath("azurerm_storage_sync_server_endpoint.test", tfjsonpath.New("sync_group_name"), tfjsonpath.New("storage_sync_group_id")), | ||
| }, | ||
| }, | ||
| data.ImportBlockWithResourceIdentityStep(false), | ||
| data.ImportBlockWithIDStep(false), | ||
| }, true) | ||
| } |
111 changes: 111 additions & 0 deletions
111
internal/services/storage/storage_sync_server_endpoint_resource_list.go
This file contains hidden or 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,111 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package storage | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/go-azure-helpers/framework/typehelpers" | ||
| "github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
| "github.com/hashicorp/go-azure-sdk/resource-manager/storagesync/2020-03-01/serverendpointresource" | ||
| "github.com/hashicorp/terraform-plugin-framework/list" | ||
| "github.com/hashicorp/terraform-plugin-framework/list/schema" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource" | ||
| "github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
| ) | ||
|
|
||
| type ( | ||
| SyncServerEndpointListResource struct{} | ||
| SyncServerEndpointListModel struct { | ||
| StorageSyncGroupId types.String `tfsdk:"storage_sync_group_id"` | ||
| } | ||
| ) | ||
|
|
||
| var _ sdk.FrameworkListWrappedResource = new(SyncServerEndpointListResource) | ||
|
|
||
| func (SyncServerEndpointListResource) Metadata(_ context.Context, _ resource.MetadataRequest, response *resource.MetadataResponse) { | ||
| response.TypeName = SyncServerEndpointResource{}.ResourceType() | ||
| } | ||
|
|
||
| func (SyncServerEndpointListResource) ResourceFunc() *pluginsdk.Resource { | ||
| return sdk.WrappedResource(SyncServerEndpointResource{}) | ||
| } | ||
|
|
||
| func (SyncServerEndpointListResource) ListResourceConfigSchema(_ context.Context, _ list.ListResourceSchemaRequest, response *list.ListResourceSchemaResponse) { | ||
| response.Schema = schema.Schema{ | ||
| Attributes: map[string]schema.Attribute{ | ||
| "storage_sync_group_id": schema.StringAttribute{ | ||
| Required: true, | ||
| Validators: []validator.String{ | ||
| typehelpers.WrappedStringValidator{Func: serverendpointresource.ValidateSyncGroupID}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (SyncServerEndpointListResource) List(ctx context.Context, request list.ListRequest, stream *list.ListResultsStream, metadata sdk.ResourceMetadata) { | ||
| client := metadata.Client.Storage.SyncServerEndpointsClient | ||
|
|
||
| var data SyncServerEndpointListModel | ||
| diags := request.Config.Get(ctx, &data) | ||
| if diags.HasError() { | ||
| stream.Results = list.ListResultsStreamDiagnostics(diags) | ||
| return | ||
| } | ||
|
|
||
| syncGroupId, err := serverendpointresource.ParseSyncGroupID(data.StorageSyncGroupId.ValueString()) | ||
| if err != nil { | ||
| sdk.SetResponseErrorDiagnostic(stream, fmt.Sprintf("parsing storage sync group id for `%s`", SyncServerEndpointResource{}.ResourceType()), err) | ||
| return | ||
| } | ||
|
|
||
| resp, err := client.ServerEndpointsListBySyncGroup(ctx, *syncGroupId) | ||
| if err != nil { | ||
| sdk.SetResponseErrorDiagnostic(stream, fmt.Sprintf("listing `%s`", SyncServerEndpointResource{}.ResourceType()), err) | ||
| return | ||
| } | ||
|
|
||
| results := make([]serverendpointresource.ServerEndpoint, 0) | ||
| if model := resp.Model; model != nil { | ||
| results = pointer.From(model.Value) | ||
| } | ||
|
|
||
| r := SyncServerEndpointResource{} | ||
|
|
||
| stream.Results = func(push func(list.ListResult) bool) { | ||
| for _, serverEndpoint := range results { | ||
| result := request.NewListResult(ctx) | ||
| result.DisplayName = pointer.From(serverEndpoint.Name) | ||
|
|
||
| id, err := serverendpointresource.ParseServerEndpointIDInsensitively(pointer.From(serverEndpoint.Id)) | ||
| if err != nil { | ||
| sdk.SetErrorDiagnosticAndPushListResult(result, push, "parsing Storage Sync Server Endpoint ID", err) | ||
| return | ||
| } | ||
|
|
||
| rmd := sdk.NewResourceMetaData(metadata.Client, r) | ||
| rmd.SetID(id) | ||
|
|
||
| if err := r.flatten(rmd, id, &serverEndpoint); err != nil { | ||
| sdk.SetErrorDiagnosticAndPushListResult(result, push, fmt.Sprintf("encoding `%s` resource data", r.ResourceType()), err) | ||
| return | ||
| } | ||
|
|
||
| sdk.EncodeListResult(ctx, rmd.ResourceData, &result) | ||
| if result.Diagnostics.HasError() { | ||
| push(result) | ||
| return | ||
| } | ||
|
|
||
| if !push(result) { | ||
| return | ||
| } | ||
| } | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
internal/services/storage/storage_sync_server_endpoint_resource_list_test.go
This file contains hidden or 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,54 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package storage_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-testing/querycheck" | ||
| "github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/provider/framework" | ||
| ) | ||
|
|
||
| func TestAccStorageSyncServerEndpoint_list_basic(t *testing.T) { | ||
| t.Skip("@mbfrahry: temporarily skipping as the server must be registered manually. Will come back to this when the server can be registered programmatically") | ||
|
|
||
| r := StorageSyncServerEndpointResource{} | ||
| listResourceAddress := "azurerm_storage_sync_server_endpoint.list" | ||
| data := acceptance.BuildTestData(t, "azurerm_storage_sync_server_endpoint", "test") | ||
|
|
||
| resource.Test(t, resource.TestCase{ | ||
| TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
| tfversion.SkipBelow(tfversion.Version1_14_0), | ||
| }, | ||
| ProtoV5ProviderFactories: framework.ProtoV5ProviderFactoriesInit(context.Background(), "azurerm"), | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: r.basic(data), | ||
| }, | ||
| { | ||
| Query: true, | ||
| Config: r.basicListQuery(data), | ||
| QueryResultChecks: []querycheck.QueryResultCheck{ | ||
| querycheck.ExpectLengthAtLeast(listResourceAddress, 1), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func (r StorageSyncServerEndpointResource) basicListQuery(data acceptance.TestData) string { | ||
| return fmt.Sprintf(` | ||
| list "azurerm_storage_sync_server_endpoint" "list" { | ||
| provider = azurerm | ||
| config { | ||
| storage_sync_group_id = "/subscriptions/%s/resourceGroups/acctestRG-StorageSync-%d/providers/Microsoft.StorageSync/storageSyncServices/acctest-StorageSync-%d/syncGroups/acctest-StorageSyncGroup-%d" | ||
| } | ||
| } | ||
| `, data.Subscriptions.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.