diff --git a/internal/services/storage/storage_share_directory_resource.go b/internal/services/storage/storage_share_directory_resource.go index 7629a44c0966..dc5bdedbca12 100644 --- a/internal/services/storage/storage_share_directory_resource.go +++ b/internal/services/storage/storage_share_directory_resource.go @@ -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" @@ -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": { diff --git a/internal/services/storage/storage_share_file_resource.go b/internal/services/storage/storage_share_file_resource.go index 7fc78dcccfa4..8401540bfb0b 100644 --- a/internal/services/storage/storage_share_file_resource.go +++ b/internal/services/storage/storage_share_file_resource.go @@ -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": { diff --git a/internal/services/storage/storage_table_entity_resource.go b/internal/services/storage/storage_table_entity_resource.go index 8d61e74fa4f0..5f5f798f3f61 100644 --- a/internal/services/storage/storage_table_entity_resource.go +++ b/internal/services/storage/storage_table_entity_resource.go @@ -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" @@ -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": { diff --git a/internal/services/storage/validate/storage_share_name.go b/internal/services/storage/validate/storage_share.go similarity index 60% rename from internal/services/storage/validate/storage_share_name.go rename to internal/services/storage/validate/storage_share.go index d9a2a03dcf44..3df3cccb03b7 100644 --- a/internal/services/storage/validate/storage_share_name.go +++ b/internal/services/storage/validate/storage_share.go @@ -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) { diff --git a/internal/services/storage/validate/storage_share_name_test.go b/internal/services/storage/validate/storage_share_test.go similarity index 100% rename from internal/services/storage/validate/storage_share_name_test.go rename to internal/services/storage/validate/storage_share_test.go diff --git a/internal/services/storage/validate/storage_table_name.go b/internal/services/storage/validate/storage_table.go similarity index 50% rename from internal/services/storage/validate/storage_table_name.go rename to internal/services/storage/validate/storage_table.go index f1824ce72a7a..30a7ed055275 100644 --- a/internal/services/storage/validate/storage_table_name.go +++ b/internal/services/storage/validate/storage_table.go @@ -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" { diff --git a/internal/services/storage/validate/storage_table_name_test.go b/internal/services/storage/validate/storage_table_test.go similarity index 100% rename from internal/services/storage/validate/storage_table_name_test.go rename to internal/services/storage/validate/storage_table_test.go