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

fix: refactor ReadWarehouse function to correctly read object parameters #745

Merged
merged 13 commits into from
Nov 29, 2021
26 changes: 0 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/arrow/go/arrow v0.0.0-20200601151325-b2287a20f230/go.mod h1:QNYViu/X0HXDHw7m3KXzWSVXIbfUvJqBFe6Gj8/pYA0=
github.com/apache/arrow/go/arrow v0.0.0-20210818145353-234c94e4ce64/go.mod h1:2qMFB56yOP3KzkB3PbYZ4AlUFg3a88F67TIx5lB/WwY=
github.com/apache/arrow/go/arrow v0.0.0-20211011184517-ca18e8aae80b h1:ehX0e2PehpfojivavS4e9/cdTqYxcf0feSx8Z5aAuTs=
github.com/apache/arrow/go/arrow v0.0.0-20211011184517-ca18e8aae80b/go.mod h1:Q7yQnSMnLvcXlZ8RV+jwz/6y1rQTqbX6C82SndT52Zs=
github.com/apache/arrow/go/arrow v0.0.0-20211012155236-b2b2cbeb28a7 h1:K8BuDHnJBWHjZtxvlArKbCX6z9SIoqQeokHolhybZx0=
github.com/apache/arrow/go/arrow v0.0.0-20211012155236-b2b2cbeb28a7/go.mod h1:Q7yQnSMnLvcXlZ8RV+jwz/6y1rQTqbX6C82SndT52Zs=
github.com/apparentlymart/go-cidr v1.0.1/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
Expand Down Expand Up @@ -169,61 +167,39 @@ github.com/aws/aws-sdk-go v1.33.11/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZve
github.com/aws/aws-sdk-go v1.40.34 h1:SBYmodndE2d4AYucuuJnOXk4MD1SFbucoIdpwKVKeSA=
github.com/aws/aws-sdk-go v1.40.34/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
github.com/aws/aws-sdk-go-v2 v1.8.0/go.mod h1:xEFuWz+3TYdlPRuo+CqATbeDWIWyaT5uAPwPaWtgse0=
github.com/aws/aws-sdk-go-v2 v1.9.1 h1:ZbovGV/qo40nrOJ4q8G33AGICzaPI45FHQWJ9650pF4=
github.com/aws/aws-sdk-go-v2 v1.9.1/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4=
github.com/aws/aws-sdk-go-v2 v1.9.2 h1:dUFQcMNZMLON4BOe273pl0filK9RqyQMhCK/6xssL6s=
github.com/aws/aws-sdk-go-v2 v1.9.2/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4=
github.com/aws/aws-sdk-go-v2/config v1.6.0/go.mod h1:TNtBVmka80lRPk5+S9ZqVfFszOQAGJJ9KbT3EM3CHNU=
github.com/aws/aws-sdk-go-v2/config v1.8.2 h1:Dqy4ySXFmulRmZhfynm/5CD4Y6aXiTVhDtXLIuUe/r0=
github.com/aws/aws-sdk-go-v2/config v1.8.2/go.mod h1:r0bkX9NyuCuf28qVcsEMtpAQibT7gA1Q0gzkjvgJdLU=
github.com/aws/aws-sdk-go-v2/config v1.8.3 h1:o5583X4qUfuRrOGOgmOcDgvr5gJVSu57NK08cWAhIDk=
github.com/aws/aws-sdk-go-v2/config v1.8.3/go.mod h1:4AEiLtAb8kLs7vgw2ZV3p2VZ1+hBavOc84hqxVNpCyw=
github.com/aws/aws-sdk-go-v2/credentials v1.3.2/go.mod h1:PACKuTJdt6AlXvEq8rFI4eDmoqDFC5DpVKQbWysaDgM=
github.com/aws/aws-sdk-go-v2/credentials v1.4.2 h1:8kVE4Og6wlhVrMGiORQ3p9gRj2exjzhFRB+QzWBUa5Q=
github.com/aws/aws-sdk-go-v2/credentials v1.4.2/go.mod h1:9Sp6u121/f0NnvHyhG7dgoYeUTEFC2vsvJqJ6wXpkaI=
github.com/aws/aws-sdk-go-v2/credentials v1.4.3 h1:LTdD5QhK073MpElh9umLLP97wxphkgVC/OjQaEbBwZA=
github.com/aws/aws-sdk-go-v2/credentials v1.4.3/go.mod h1:FNNC6nQZQUuyhq5aE5c7ata8o9e4ECGmS4lAXC7o1mQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.4.0/go.mod h1:Mj/U8OpDbcVcoctrYwA2bak8k/HFPdcLzI/vaiXMwuM=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.5.1 h1:Nm+BxqBtT0r+AnD6byGMCGT4Km0QwHBy8mAYptNPXY4=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.5.1/go.mod h1:W1ldHfsgeGlKpJ4xZMKZUI6Wmp6EAstU7PxnhbXWWrI=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.6.0 h1:9tfxW/icbSu98C2pcNynm5jmDwU3/741F11688B6QnU=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.6.0/go.mod h1:gqlclDEZp4aqJOancXK6TN24aKhT0W0Ae9MHk3wzTMM=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.4.0/go.mod h1:eHwXu2+uE/T6gpnYWwBwqoeqRf9IXyCcolyOWDRAErQ=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.3 h1:0O72494cCsazjpsGfo+LXezru6PMSp0HUB1m5UfpaRU=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.3/go.mod h1:claNkz2j/N/AZceFcAbR0NyuWnrn+jCYpI+6Ozjsc0k=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.4 h1:TnU1cY51027j/MQeFy7DIgk1UuzJY+wLFYqXceY/fiE=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.4/go.mod h1:Ex7XQmbFmgFHrjUX6TN3mApKW5Hglyga+F7wZHTtYhA=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.0/go.mod h1:Q5jATQc+f1MfZp3PDMhn6ry18hGvE0i8yvbXoKbnZaE=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.3 h1:NnXJXUz7oihrSlPKEM0yZ19b+7GQ47MX/LluLlEyE/Y=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.3/go.mod h1:EES9ToeC3h063zCFDdqWGnARExNdULPaBvARm1FLwxA=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.4 h1:leSJ6vCqtPpTmBIgE7044B1wql1E4n//McF+mEgNrYg=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.4/go.mod h1:ZcBrrI3zBKlhGFNYWvju0I3TR93I7YIgAfy82Fh4lcQ=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.2.2/go.mod h1:EASdTcM1lGhUe1/p4gkojHwlGJkeoRjjr1sRCzup3Is=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.3.0 h1:gceOysEWNNwLd6cki65IMBZ4WAM0MwgBQq2n7kejoT8=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.3.0/go.mod h1:v8ygadNyATSm6elwJ/4gzJwcFhri9RqS8skgHKiwXPU=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.2/go.mod h1:NXmNI41bdEsJMrD0v9rUvbGCB5GwdBEpKvUvIY3vTFg=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.1 h1:APEjhKZLFlNVLATnA/TJyA+w1r/xd5r5ACWBDZ9aIvc=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.1/go.mod h1:Ve+eJOx9UWaT/lMVebnFhDhO49fSLVedHoA82+Rqme0=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.2 h1:r7jel2aa4d9Duys7wEmWqDd5ebpC9w6Kxu6wIjjp18E=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.2/go.mod h1:72HRZDLMtmVQiLG2tLfQcaWLCssELvGl+Zf2WVxMmR8=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.5.2/go.mod h1:QuL2Ym8BkrLmN4lUofXYq6000/i5jPjosCNK//t6gak=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.7.1 h1:YEz2KMyqK2zyG3uOa0l2xBc/H6NUVJir8FhwHQHF3rc=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.7.1/go.mod h1:yg4EN/BKoc7+DLhNOxxdvoO3+iyW2FuynvaKqLcLDUM=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.7.2 h1:RnZjLgtCGLsF2xYYksy0yrx6xPvKG9BYv29VfK4p/J8=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.7.2/go.mod h1:np7TMuJNT83O0oDOSF8i4dF3dvGqA6hPYYo6YYkzgRA=
github.com/aws/aws-sdk-go-v2/service/s3 v1.12.0/go.mod h1:6J++A5xpo7QDsIeSqPK4UHqMSyPOCopa+zKtqAMhqVQ=
github.com/aws/aws-sdk-go-v2/service/s3 v1.16.0 h1:dt1JQFj/135ozwGIWeCM3aQ8N/kB3Xu3Uu4r9zuOIyc=
github.com/aws/aws-sdk-go-v2/service/s3 v1.16.0/go.mod h1:Tk23mCmfL3wb3tNIeMk/0diUZ0W4R6uZtjYKguMLW2s=
github.com/aws/aws-sdk-go-v2/service/s3 v1.16.1 h1:z+P3r4LrwdudLKBoEVWxIORrk4sVg4/iqpG3+CS53AY=
github.com/aws/aws-sdk-go-v2/service/s3 v1.16.1/go.mod h1:CQe/KvWV1AqRc65KqeJjrLzr5X2ijnFTTVzJW0VBRCI=
github.com/aws/aws-sdk-go-v2/service/sso v1.3.2/go.mod h1:J21I6kF+d/6XHVk7kp/cx9YVD2TMD2TbLwtRGVcinXo=
github.com/aws/aws-sdk-go-v2/service/sso v1.4.1 h1:RfgQyv3bFT2Js6XokcrNtTjQ6wAVBRpoCgTFsypihHA=
github.com/aws/aws-sdk-go-v2/service/sso v1.4.1/go.mod h1:ycPdbJZlM0BLhuBnd80WX9PucWPG88qps/2jl9HugXs=
github.com/aws/aws-sdk-go-v2/service/sso v1.4.2 h1:pZwkxZbspdqRGzddDB92bkZBoB7lg85sMRE7OqdB3V0=
github.com/aws/aws-sdk-go-v2/service/sso v1.4.2/go.mod h1:NBvT9R1MEF+Ud6ApJKM0G+IkPchKS7p7c2YPKwHmBOk=
github.com/aws/aws-sdk-go-v2/service/sts v1.6.1/go.mod h1:hLZ/AnkIKHLuPGjEiyghNEdvJ2PP0MgOxcmv9EBJ4xs=
github.com/aws/aws-sdk-go-v2/service/sts v1.7.1 h1:7ce9ugapSgBapwLhg7AJTqKW5U92VRX3vX65k2tsB+g=
github.com/aws/aws-sdk-go-v2/service/sts v1.7.1/go.mod h1:r1i8QwKPzwByXqZb3POQfBs7jozrdnHz8PVbsvyx73w=
github.com/aws/aws-sdk-go-v2/service/sts v1.7.2 h1:ol2Y5DWqnJeKqNd8th7JWzBtqu63xpOfs1Is+n1t8/4=
github.com/aws/aws-sdk-go-v2/service/sts v1.7.2/go.mod h1:8EzeIqfWt2wWT4rJVu3f21TfrhJ8AEMzVybRNSb/b4g=
github.com/aws/smithy-go v1.7.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
Expand Down Expand Up @@ -1502,8 +1478,6 @@ google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U=
google.golang.org/genproto v0.0.0-20211011165927-a5fb3255271e h1:B3r2Cb5u7Od6/WGb95VHDMp99VU/fuqPYZb6VM8IozI=
google.golang.org/genproto v0.0.0-20211011165927-a5fb3255271e/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211012143446-e1d23e1da178 h1:sjksfRCbEowdKjfEEAUtbT/Ji7rS6z/Rr/075r57JLQ=
google.golang.org/genproto v0.0.0-20211012143446-e1d23e1da178/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
Expand Down
2 changes: 1 addition & 1 deletion pkg/datasources/materialized_views_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestAccMaterializedViews(t *testing.T) {
func materializedViews(warehouseName string, databaseName string, schemaName string, tableName string, viewName string) string {
return fmt.Sprintf(`
resource "snowflake_warehouse" "w" {
name = "%v"
name = "%v"
initially_suspended = false
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/datasources/tasks_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func tasks(databaseName string, schemaName string, taskName string) string {
}

resource snowflake_warehouse "test" {
name = snowflake_database.test.name
name = snowflake_database.test.name
max_concurrency_level = 8
statement_timeout_in_seconds = 172800
}

resource snowflake_task "test" {
Expand Down
10 changes: 6 additions & 4 deletions pkg/datasources/warehouses_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ func TestAccWarehouses(t *testing.T) {
func warehouses(warehouseName string) string {
return fmt.Sprintf(`
resource snowflake_warehouse "s"{
name = "%v"
warehouse_size = "XSMALL"
initially_suspended = true
auto_suspend = 60
name = "%v"
warehouse_size = "XSMALL"
initially_suspended = true
auto_suspend = 60
max_concurrency_level = 8
statement_timeout_in_seconds = 172800
}

data snowflake_warehouses "s" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/task_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ var (
rootname = "root_task"
childname = "child_task"
soloname = "standalone_task"
warehousename = acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
databasename = acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
warehousename = strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
databasename = strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

initialState = &AccTaskTestSettings{ //nolint
WarehouseName: warehousename,
Expand Down
31 changes: 27 additions & 4 deletions pkg/resources/task_grant_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,41 @@ func TestAcc_TaskGrant(t *testing.T) {
Providers: providers(),
Steps: []resource.TestStep{
{
Config: taskGrantConfig(accName),
Config: taskGrantConfig(accName, 8),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_task_grant.test", "database_name", accName),
resource.TestCheckResourceAttr("snowflake_task_grant.test", "schema_name", accName),
resource.TestCheckResourceAttr("snowflake_task_grant.test", "task_name", accName),
resource.TestCheckResourceAttr("snowflake_task_grant.test", "with_grant_option", "false"),
resource.TestCheckResourceAttr("snowflake_task_grant.test", "privilege", "OPERATE"),
resource.TestCheckResourceAttr("snowflake_warehouse.test", "max_concurrency_level", "8"),
resource.TestCheckResourceAttr("snowflake_warehouse.test", "statement_timeout_in_seconds", "86400"),
),
},
// UPDATE MAX_CONCURRENCY_LEVEL
{
Config: taskGrantConfig(accName, 10),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_task_grant.test", "database_name", accName),
resource.TestCheckResourceAttr("snowflake_task_grant.test", "schema_name", accName),
resource.TestCheckResourceAttr("snowflake_task_grant.test", "task_name", accName),
resource.TestCheckResourceAttr("snowflake_task_grant.test", "with_grant_option", "false"),
resource.TestCheckResourceAttr("snowflake_task_grant.test", "privilege", "OPERATE"),
resource.TestCheckResourceAttr("snowflake_warehouse.test", "max_concurrency_level", "10"),
resource.TestCheckResourceAttr("snowflake_warehouse.test", "statement_timeout_in_seconds", "86400"),
),
},
// IMPORT
{
ResourceName: "snowflake_task_grant.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func taskGrantConfig(name string) string {
func taskGrantConfig(name string, concurrency int32) string {
s := `
resource "snowflake_database" "test" {
name = "%v"
Expand All @@ -47,7 +68,9 @@ resource "snowflake_role" "test" {
}

resource "snowflake_warehouse" "test" {
name = snowflake_database.test.name
name = snowflake_database.test.name
max_concurrency_level = %d
statement_timeout_in_seconds = 86400
}

resource "snowflake_task" "test" {
Expand All @@ -71,5 +94,5 @@ resource "snowflake_task_grant" "test" {
privilege = "OPERATE"
}
`
return fmt.Sprintf(s, name, name)
return fmt.Sprintf(s, name, name, concurrency)
}
67 changes: 56 additions & 11 deletions pkg/resources/warehouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resources
import (
"database/sql"
"log"
"strconv"
"strings"

"github.com/chanzuckerberg/terraform-provider-snowflake/pkg/snowflake"
Expand Down Expand Up @@ -105,7 +106,7 @@ var warehouseSchema = map[string]*schema.Schema{
"statement_timeout_in_seconds": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Default: 172800,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default value for this parameter is 172800 (https://docs.snowflake.com/en/sql-reference/parameters.html#statement-timeout-in-seconds). I think provider defaults should be the same as Snowflake defaults. What do you think?

Description: "Specifies the time, in seconds, after which a running SQL statement (query, DDL, DML, etc.) is canceled by the system",
},
"statement_queued_timeout_in_seconds": {
Expand All @@ -117,7 +118,7 @@ var warehouseSchema = map[string]*schema.Schema{
"max_concurrency_level": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Default: 8,
Description: "Object parameter that specifies the concurrency level for SQL statements (i.e. queries and DML) executed by a warehouse.",
},
"tag": tagReferenceSchema,
Expand All @@ -141,13 +142,22 @@ func Warehouse() *schema.Resource {
// CreateWarehouse implements schema.CreateFunc
func CreateWarehouse(d *schema.ResourceData, meta interface{}) error {
props := append(warehouseProperties, warehouseCreateProperties...)
return CreateResource("warehouse", props, warehouseSchema, snowflake.Warehouse, ReadWarehouse)(d, meta)
return CreateResource(
"warehouse",
props,
warehouseSchema,
func(name string) *snowflake.Builder {
return snowflake.Warehouse(name).Builder
},
ReadWarehouse,
)(d, meta)
}

// ReadWarehouse implements schema.ReadFunc
func ReadWarehouse(d *schema.ResourceData, meta interface{}) error {
db := meta.(*sql.DB)
stmt := snowflake.Warehouse(d.Id()).Show()
warehouseBuilder := snowflake.Warehouse(d.Id())
stmt := warehouseBuilder.Show()

row := snowflake.QueryRow(db, stmt)
w, err := snowflake.ScanWarehouse(row)
Expand Down Expand Up @@ -193,29 +203,64 @@ func ReadWarehouse(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
err = d.Set("statement_timeout_in_seconds", w.StatementTimeoutInSeconds)
err = d.Set("resource_monitor", w.ResourceMonitor)
if err != nil {
return err
}
err = d.Set("statement_queued_timeout_in_seconds", w.StatementQueuedTimeoutInSeconds)

stmt = warehouseBuilder.ShowParameters()
paramRows, err := snowflake.Query(db, stmt)
if err != nil {
return err
}
err = d.Set("max_concurrency_level", w.MaxConcurrencyLevel)

warehouseParams, err := snowflake.ScanWarehouseParameters(paramRows)
if err != nil {
return err
}
err = d.Set("resource_monitor", w.ResourceMonitor)

return err
for _, param := range warehouseParams {
log.Printf("[TRACE] %+v\n", param)

var value interface{} = param.DefaultValue
if strings.EqualFold(param.Type, "number") {
i, err := strconv.ParseInt(param.Value, 10, 64)
if err != nil {
return err
}
value = i
} else {
value = param.Value
}

key := strings.ToLower(param.Key)
err = d.Set(key, value)
if err != nil {
return err
}
}

return nil
}

// UpdateWarehouse implements schema.UpdateFunc
func UpdateWarehouse(d *schema.ResourceData, meta interface{}) error {
return UpdateResource("warehouse", warehouseProperties, warehouseSchema, snowflake.Warehouse, ReadWarehouse)(d, meta)
return UpdateResource(
"warehouse",
warehouseProperties,
warehouseSchema,
func(name string) *snowflake.Builder {
return snowflake.Warehouse(name).Builder
},
ReadWarehouse,
)(d, meta)
}

// DeleteWarehouse implements schema.DeleteFunc
func DeleteWarehouse(d *schema.ResourceData, meta interface{}) error {
return DeleteResource("warehouse", snowflake.Warehouse)(d, meta)
return DeleteResource(
"warehouse", func(name string) *snowflake.Builder {
return snowflake.Warehouse(name).Builder
},
)(d, meta)
}
5 changes: 5 additions & 0 deletions pkg/resources/warehouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func TestWarehouseCreate(t *testing.T) {
func expectReadWarehouse(mock sqlmock.Sqlmock) {
rows := sqlmock.NewRows([]string{"name", "comment", "size"}).AddRow("good_name", "mock comment", "SMALL")
mock.ExpectQuery("SHOW WAREHOUSES LIKE 'good_name'").WillReturnRows(rows)

rows = sqlmock.NewRows(
[]string{"key", "value", "default", "level", "description", "type"},
).AddRow("MAX_CONCURRENCY_LEVEL", 8, 8, "WAREHOUSE", "", "NUMBER")
mock.ExpectQuery("SHOW PARAMETERS IN WAREHOUSE good_name").WillReturnRows(rows)
}

func TestWarehouseRead(t *testing.T) {
Expand Down
Loading