Skip to content

Commit

Permalink
Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Dec 11, 2024
1 parent 2eef779 commit afaba5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/resources/function_commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"slices"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
Expand Down Expand Up @@ -545,6 +546,8 @@ func readFunctionArgumentsCommon(d *schema.ResourceData, args []sdk.NormalizedAr
// TODO [SNOW-1348103]: handle empty list
return nil
}
// We do it the unusual way because the default values are not returned by SF.
// We update what we have - leaving the defaults unchanged.
if currentArgs, ok := d.Get("arguments").([]map[string]any); !ok {
return fmt.Errorf("arguments must be a list")
} else {
Expand All @@ -561,13 +564,12 @@ func readFunctionImportsCommon(d *schema.ResourceData, imports []sdk.NormalizedP
// don't do anything if imports not present
return nil
}
imps := make([]map[string]any, len(imports))
for i, imp := range imports {
imps[i] = map[string]any{
imps := collections.Map(imports, func(imp sdk.NormalizedPath) map[string]any {
return map[string]any{
"stage_location": imp.StageLocation,
"path_on_stage": imp.PathOnStage,
}
}
})
return d.Set("imports", imps)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/sdk/functions_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func functionDetailsFromRows(rows []FunctionDetail) (*FunctionDetails, error) {
return v, errors.Join(errs...)
}

// TODO [SNOW-1850370]: use ParseCommaSeparatedStringArray + collections.MapErr combo here and in other methods?
func parseFunctionDetailsImport(details FunctionDetails) ([]NormalizedPath, error) {
functionDetailsImports := make([]NormalizedPath, 0)
if details.Imports == nil || *details.Imports == "" || *details.Imports == "[]" {
Expand Down

0 comments on commit afaba5a

Please sign in to comment.