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

azurerm_synapse_workspace: fix panic of slice index out-of-range #23019

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a resource id? should we not be validating it as an id not a uri?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@katbyte, the ID here is in the form of a URI (e.g., https://storageaccountname.dfs.core.windows.net/filesystemname)

},

"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
Loading