Skip to content

Commit

Permalink
Merge pull request #25307 from hashicorp/bugfix/storage-table-entity-…
Browse files Browse the repository at this point in the history
…data-source-lookup-error

bugfix: fix a bug parsing the table endpoint into a data plane account ID in `data.azurerm_storage_table_entity`
  • Loading branch information
tombuildsstuff authored Mar 19, 2024
2 parents eb8a687 + 40e15d7 commit b7c13e9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 6 deletions.
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 plane endpoint: %v", err)
}

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
3 changes: 2 additions & 1 deletion internal/services/storage/storage_table_entity_resource.go
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

0 comments on commit b7c13e9

Please sign in to comment.