Skip to content

Commit

Permalink
fix: external_table headers order doesn't matter (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Lopez authored Oct 26, 2021
1 parent 5fe912d commit e0d74be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/resources/external_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resource "snowflake_external_function" "test_ext_func" {
- **comment** (String) A description of the external function.
- **compression** (String) If specified, the JSON payload is compressed when sent from Snowflake to the proxy service, and when sent back from the proxy service to Snowflake.
- **context_headers** (List of String) Binds Snowflake context function results to HTTP headers.
- **header** (Block List) Allows users to specify key-value metadata that is sent with every request as HTTP headers. (see [below for nested schema](#nestedblock--header))
- **header** (Block Set) Allows users to specify key-value metadata that is sent with every request as HTTP headers. (see [below for nested schema](#nestedblock--header))
- **id** (String) The ID of this resource.
- **max_batch_rows** (Number) This specifies the maximum number of rows in each batch sent to the proxy service.
- **null_input_behavior** (String) Specifies the behavior of the external function when called with null inputs.
Expand Down
6 changes: 4 additions & 2 deletions pkg/resources/external_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var externalFunctionSchema = map[string]*schema.Schema{
Description: "The name of the API integration object that should be used to authenticate the call to the proxy service.",
},
"header": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Description: "Allows users to specify key-value metadata that is sent with every request as HTTP headers.",
Expand All @@ -114,11 +114,13 @@ var externalFunctionSchema = map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Header name",
},
"value": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Header value",
},
},
Expand Down Expand Up @@ -277,7 +279,7 @@ func CreateExternalFunction(d *schema.ResourceData, meta interface{}) error {

if _, ok := d.GetOk("header"); ok {
headers := []map[string]string{}
for _, header := range d.Get("header").([]interface{}) {
for _, header := range d.Get("header").(*schema.Set).List() {
headerDef := map[string]string{}
for key, val := range header.(map[string]interface{}) {
headerDef[key] = val.(string)
Expand Down
5 changes: 3 additions & 2 deletions pkg/resources/external_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/chanzuckerberg/terraform-provider-snowflake/pkg/provider"
"github.com/chanzuckerberg/terraform-provider-snowflake/pkg/resources"
. "github.com/chanzuckerberg/terraform-provider-snowflake/pkg/testhelpers"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -99,7 +100,7 @@ func TestExternalFunctionRead(t *testing.T) {
r.Equal("data", test_func_args["name"].(string))
r.Equal("varchar", test_func_args["type"].(string))

headers := d.Get("header").([]interface{})
headers := d.Get("header").(*schema.Set).List()
r.Len(headers, 1)
test_func_headers := headers[0].(map[string]interface{})
r.Len(test_func_headers, 2)
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestExternalFunctionReadReturnTypeVariant(t *testing.T) {
r.Equal("data", test_func_args["name"].(string))
r.Equal("varchar", test_func_args["type"].(string))

headers := d.Get("header").([]interface{})
headers := d.Get("header").(*schema.Set).List()
r.Len(headers, 1)
test_func_headers := headers[0].(map[string]interface{})
r.Len(test_func_headers, 2)
Expand Down

0 comments on commit e0d74be

Please sign in to comment.