Skip to content

Commit

Permalink
including #23019 fixes #23004
Browse files Browse the repository at this point in the history
* fix panic of path slice index

* add a validation for storage_data_lake_gen2_filesystem_id
  • Loading branch information
wuxu92 authored Aug 25, 2023
1 parent 540807c commit d72e9d7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/services/synapse/synapse_workspace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ func resourceSynapseWorkspace() *pluginsdk.Resource {
"location": commonschema.Location(),

"storage_data_lake_gen2_filesystem_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.IsURLWithPath,
},

"sql_administrator_login": {
Expand Down Expand Up @@ -795,7 +796,7 @@ func expandArmWorkspaceDataLakeStorageAccountDetails(storageDataLakeGen2Filesyst
uri, _ := url.Parse(storageDataLakeGen2FilesystemId)
return &synapse.DataLakeStorageAccountDetails{
AccountURL: utils.String(fmt.Sprintf("%s://%s", uri.Scheme, uri.Host)), // https://storageaccountname.dfs.core.windows.net/filesystemname -> https://storageaccountname.dfs.core.windows.net
Filesystem: utils.String(uri.Path[1:]), // https://storageaccountname.dfs.core.windows.net/filesystemname -> filesystemname
Filesystem: utils.String(strings.TrimPrefix(uri.Path, "/")), // https://storageaccountname.dfs.core.windows.net/filesystemname -> filesystemname
}
}

Expand Down
29 changes: 29 additions & 0 deletions internal/tf/validation/pluginsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package validation

import (
"fmt"
"net/url"
"regexp"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -171,6 +173,33 @@ func IsURLWithScheme(validSchemes []string) func(interface{}, string) ([]string,
return validation.IsURLWithScheme(validSchemes)
}

// IsURLWithPath is a SchemaValidateFunc that tests if the provided value is of type string and a valid URL with a path
func IsURLWithPath(i interface{}, k string) (_ []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return
}

if v == "" {
errors = append(errors, fmt.Errorf("expected %q url to not be empty, got %v", k, i))
return
}

u, err := url.Parse(v)
if err != nil {
errors = append(errors, fmt.Errorf("expected %q to be a valid url, got %v: %+v", k, v, err))
return
}

if strings.TrimPrefix(u.Path, "/") == "" {
errors = append(errors, fmt.Errorf("expected %q to have a non empty path got %v", k, v))
return
}

return
}

// IsUUID is a ValidateFunc that ensures a string can be parsed as UUID
func IsUUID(i interface{}, k string) ([]string, []error) {
return validation.IsUUID(i, k)
Expand Down

0 comments on commit d72e9d7

Please sign in to comment.