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

bugfix: fix a bug parsing the table endpoint into a data plane account ID in data.azurerm_storage_table_entity #25307

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/client"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/helpers"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
storageValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -58,7 +59,7 @@ func resourceStorageShareDirectory() *pluginsdk.Resource {
Computed: true, // TODO: remove computed in v4.0
ForceNew: true,
ConflictsWith: []string{"share_name", "storage_account_name"},
ValidateFunc: validation.IsURLWithPath, // note: storage domain suffix cannot be determined at validation time, so just make sure it's a well-formed URL
ValidateFunc: storageValidate.StorageShareDataPlaneID,
},

"share_name": {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/storage/storage_share_file_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func resourceStorageShareFile() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.IsURLWithPath, // note: storage domain suffix cannot be determined at validation time, so just make sure it's a well-formed URL
ValidateFunc: storageValidate.StorageShareDataPlaneID,
},

"path": {
Expand Down
12 changes: 9 additions & 3 deletions internal/services/storage/storage_table_entity_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/client"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -78,12 +79,17 @@ func dataSourceStorageTableEntityRead(d *pluginsdk.ResourceData, meta interface{
return fmt.Errorf("the parent Storage Account %s was not found", accountName)
}

client, err := storageClient.TableEntityDataPlaneClient(ctx, *account, storageClient.DataPlaneOperationSupportingAnyAuthMethod())
dataPlaneClient, err := storageClient.TableEntityDataPlaneClient(ctx, *account, storageClient.DataPlaneOperationSupportingAnyAuthMethod())
if err != nil {
return fmt.Errorf("building Table Entity Client for Storage Account %q (Resource Group %q): %v", accountName, account.ResourceGroup, err)
}

accountId, err := accounts.ParseAccountID(accountName, storageClient.StorageDomainSuffix)
endpoint, err := account.DataPlaneEndpoint(client.EndpointTypeTable)
if err != nil {
return fmt.Errorf("retrieving the table data plan endpoint: %v", err)
manicminer marked this conversation as resolved.
Show resolved Hide resolved
}

accountId, err := accounts.ParseAccountID(*endpoint, storageClient.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("parsing Account ID: %v", err)
}
Expand All @@ -96,7 +102,7 @@ func dataSourceStorageTableEntityRead(d *pluginsdk.ResourceData, meta interface{
MetaDataLevel: entities.NoMetaData,
}

result, err := client.Get(ctx, tableName, input)
result, err := dataPlaneClient.Get(ctx, tableName, input)
if err != nil {
return fmt.Errorf("retrieving %s: %v", id, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/client"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/helpers"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
storageValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -49,7 +50,7 @@ func resourceStorageTableEntity() *pluginsdk.Resource {
Optional: true, // TODO: make required and forcenew in v4.0
Computed: true, // TODO: remove computed in v4.0
ConflictsWith: []string{"table_name", "storage_account_name"},
ValidateFunc: validation.IsURLWithPath, // note: storage domain suffix cannot be determined at validation time, so just make sure it's a well-formed URL
ValidateFunc: storageValidate.StorageTableDataPlaneID,
},

"table_name": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@ package validate
import (
"fmt"
"regexp"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/client"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/tombuildsstuff/giovanni/storage/2023-11-03/file/shares"
)

func StorageShareDataPlaneID(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}

if client.StorageDomainSuffix == nil {
return validation.IsURLWithPath(input, key)
}

if _, err := shares.ParseShareID(v, *client.StorageDomainSuffix); err != nil {
errors = append(errors, err)
}

return
}

func StorageShareName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@ package validate
import (
"fmt"
"regexp"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/client"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/tombuildsstuff/giovanni/storage/2023-11-03/table/tables"
)

func StorageTableDataPlaneID(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}

if client.StorageDomainSuffix == nil {
return validation.IsURLWithPath(input, key)
}

if _, err := tables.ParseTableID(v, *client.StorageDomainSuffix); err != nil {
errors = append(errors, err)
}

return
}

func StorageTableName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
if value == "table" {
Expand Down
Loading