-
Notifications
You must be signed in to change notification settings - Fork 418
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
feat: Add option to create streams which reference EXTERNAL TABLEs #661
Changes from 7 commits
d1b7887
d57e4a0
e279033
d73326f
02267a3
eb335a8
c58be0c
b467077
8377023
a356e27
7b71972
c95a50f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,19 @@ func TestAcc_Stream(t *testing.T) { | |
checkBool("snowflake_stream.test_stream", "show_initial_rows", false), | ||
), | ||
}, | ||
{ | ||
Config: externalTableStreamConfig(accName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "name", accName), | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "database", accName), | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "schema", accName), | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "on_table", fmt.Sprintf("%s.%s.%s", accName, accName, "STREAM_ON_EXTERNAL_TABLE")), | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "comment", "Terraform acceptance test"), | ||
checkBool("snowflake_stream.test_stream", "on_external_table", true), | ||
checkBool("snowflake_stream.test_stream", "append_only", false), | ||
checkBool("snowflake_stream.test_stream", "show_initial_rows", false), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
@@ -90,3 +103,67 @@ resource "snowflake_stream" "test_stream" { | |
` | ||
return fmt.Sprintf(s, name, name, name, append_only_config) | ||
} | ||
|
||
func externalTableStreamConfig(name string) string { | ||
// Refer to external_table_acceptance_test.go for the original source on | ||
// external table resources and dependents (modified slightly here). | ||
locations := []string{"s3://com.example.bucket/prefix"} | ||
s := ` | ||
resource "snowflake_database" "test" { | ||
name = "%v" | ||
comment = "Terraform acceptance test" | ||
} | ||
|
||
resource "snowflake_schema" "test" { | ||
name = "%v" | ||
database = snowflake_database.test.name | ||
comment = "Terraform acceptance test" | ||
} | ||
|
||
resource "snowflake_stage" "test" { | ||
name = "%v" | ||
url = "s3://com.example.bucket/prefix" | ||
database = snowflake_database.test.name | ||
schema = snowflake_schema.test.name | ||
comment = "Terraform acceptance test" | ||
storage_integration = snowflake_storage_integration.external_table_stream_integration.name | ||
} | ||
|
||
resource "snowflake_storage_integration" "external_table_stream_integration" { | ||
name = "%v" | ||
storage_allowed_locations = %q | ||
storage_provider = "S3" | ||
storage_aws_role_arn = "arn:aws:iam::000000000001:/role/test" | ||
} | ||
|
||
resource "snowflake_external_table" "test_external_stream_table" { | ||
database = snowflake_database.test.name | ||
schema = snowflake_schema.test.name | ||
name = "STREAM_ON_EXTERNAL_TABLE" | ||
comment = "Terraform acceptance test" | ||
column { | ||
name = "column1" | ||
type = "STRING" | ||
as = "TO_VARCHAR(TO_TIMESTAMP_NTZ(value:unix_timestamp_property::NUMBER, 3), 'yyyy-mm-dd-hh')" | ||
} | ||
column { | ||
name = "column2" | ||
type = "TIMESTAMP_NTZ(9)" | ||
as = "($1:'CreatedDate'::timestamp)" | ||
} | ||
file_format = "TYPE = CSV" | ||
location = "@${snowflake_database.test.name}.${snowflake_schema.test.name}.${snowflake_stage.test.name}" | ||
} | ||
|
||
resource "snowflake_stream" "test_external_table_stream" { | ||
database = snowflake_database.test_database.name | ||
momer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
schema = snowflake_schema.test_schema.name | ||
momer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = "%s" | ||
comment = "Terraform acceptance test" | ||
on_external_table = true | ||
on_table = "${snowflake_database.test_database.name}.${snowflake_schema.test_schema.name}.${snowflake_external_table.test_external_stream_table.name}" | ||
momer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
` | ||
|
||
return fmt.Sprintf(s, name, name, name, name, locations, name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you don't want to reuse the config above, you'll have to create another random string to pass in so that the names are different. Just put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then replace the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see - thank you again, see the most recent commits! |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's not happy with this... Is this written correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, should be; I grabbed it directly from the
external_table_acceptance_test.go
test. I can dig in a bit tonight hopefully, sorry for the many issues with this test