-
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 stream on directory table #3129
Open
sfc-gh-jmichalak
wants to merge
9
commits into
main
Choose a base branch
from
stream-v1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6f6e10c
Add stream on directory table
sfc-gh-jmichalak 3fb35cd
Cleanup
sfc-gh-jmichalak 3d01087
Merge remote-tracking branch 'origin/main' into stream-v1
sfc-gh-jmichalak 949ecac
pre push
sfc-gh-jmichalak 25dc08b
Add jira ticket
sfc-gh-jmichalak 95c61bc
After review
sfc-gh-jmichalak 052543d
Merge remote-tracking branch 'origin/main' into stream-v1
sfc-gh-jmichalak d031de6
Minor fixes
sfc-gh-jmichalak 92137e6
Use ignore after creation for copy_grants
sfc-gh-jmichalak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,56 @@ across different versions. | |
> [!TIP] | ||
> We highly recommend upgrading the versions one by one instead of bulk upgrades. | ||
## v0.97.0 ➞ v0.98.0 | ||
|
||
### *(new feature)* snowflake_stream_on_directory_table resource | ||
Continuing changes made in v0.96, to enhance clarity and functionality, the new resource `snowflake_stream_on_directory_table` has been introduced to replace the previous `snowflake_stream`. Recognizing that the old resource carried multiple responsibilities within a single entity, we opted to divide it into more specialized resources. | ||
The newly introduced resources are aligned with the latest Snowflake documentation at the time of implementation, and adhere to our [new conventions](#general-changes). | ||
This segregation was based on the object on which the stream is created. The mapping between SQL statements and the resources is the following: | ||
- `ON TABLE <table_name>` -> `snowflake_stream_on_table` (added in v0.96) | ||
- `ON EXTERNAL TABLE <external_table_name>` -> `snowflake_stream_on_external_table` (this was previously not supported, added in v0.96) | ||
- `ON STAGE <stage_name>` -> `snowflake_stream_on_directory_table` | ||
|
||
To use the new `stream_on_directory_table`, change the old `stream` from | ||
```terraform | ||
resource "snowflake_stream" "stream" { | ||
name = "stream" | ||
schema = "schema" | ||
database = "database" | ||
on_stage = snowflake_stage.stage.fully_qualified_name | ||
comment = "A stream." | ||
} | ||
``` | ||
|
||
to | ||
|
||
```terraform | ||
resource "snowflake_stream_on_directory_table" "stream" { | ||
name = "stream" | ||
schema = "schema" | ||
database = "database" | ||
stage = snowflake_stage.stage.fully_qualified_name | ||
comment = "A stream." | ||
} | ||
``` | ||
|
||
Then, follow our [Resource migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md). | ||
|
||
|
||
## v0.96.0 ➞ v0.97.0 | ||
|
||
### *(new feature)* snowflake_stream_on_table, snowflake_stream_on_external_table resource | ||
|
||
To enhance clarity and functionality, the new resources `snowflake_stream_on_table` and `snowflake_stream_on_external_table` have been introduced to replace the previous `snowflake_stream`. Recognizing that the old resource carried multiple responsibilities within a single entity, we opted to divide it into more specialized resources. | ||
To enhance clarity and functionality, the new resources `snowflake_stream_on_table`, `snowflake_stream_on_external_table` and `snowflake_stream_on_directory_table` have been introduced to replace the previous `snowflake_stream`. Recognizing that the old resource carried multiple responsibilities within a single entity, we opted to divide it into more specialized resources. | ||
The newly introduced resources are aligned with the latest Snowflake documentation at the time of implementation, and adhere to our [new conventions](#general-changes). | ||
This segregation was based on the object on which the stream is created. The mapping between SQL statements and the resources is the following: | ||
- `ON TABLE <table_name>` -> `snowflake_stream_on_table` | ||
- `ON EXTERNAL TABLE <external_table_name>` -> `snowflake_stream_on_external_table` (this was previously not supported) | ||
- `ON STAGE <stage_name>` -> `snowflake_stream_on_directory_table` | ||
|
||
The resources for streams on directory tables and streams on views will be implemented in the future releases. | ||
|
||
|
@@ -35,7 +76,7 @@ resource "snowflake_stream" "stream" { | |
|
||
to | ||
|
||
``` | ||
```terraform | ||
resource "snowflake_stream_on_table" "stream" { | ||
name = "stream" | ||
schema = "schema" | ||
|
@@ -48,6 +89,7 @@ resource "snowflake_stream_on_table" "stream" { | |
} | ||
``` | ||
|
||
|
||
Then, follow our [Resource migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md). | ||
|
||
### *(new feature)* new snowflake_service_user and snowflake_legacy_service_user resources | ||
|
@@ -83,7 +125,7 @@ resource "snowflake_user" "service_user" { | |
lifecycle { | ||
ignore_changes = [user_type] | ||
} | ||
name = "Snowflake Service User" | ||
login_name = "service_user" | ||
email = "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
--- | ||
page_title: "snowflake_stream_on_directory_table Resource - terraform-provider-snowflake" | ||
subcategory: "" | ||
description: |- | ||
Resource used to manage streams on directory tables. For more information, check stream documentation https://docs.snowflake.com/en/sql-reference/sql/create-stream. | ||
--- | ||
|
||
!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0970--v0980) to use it. | ||
|
||
# snowflake_stream_on_directory_table (Resource) | ||
|
||
Resource used to manage streams on directory tables. For more information, check [stream documentation](https://docs.snowflake.com/en/sql-reference/sql/create-stream). | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "snowflake_stage" "example_stage" { | ||
name = "EXAMPLE_STAGE" | ||
url = "s3://com.example.bucket/prefix" | ||
database = "EXAMPLE_DB" | ||
schema = "EXAMPLE_SCHEMA" | ||
credentials = "AWS_KEY_ID='${var.example_aws_key_id}' AWS_SECRET_KEY='${var.example_aws_secret_key}'" | ||
} | ||
# basic resource | ||
resource "snowflake_stream_on_directory_table" "stream" { | ||
name = "stream" | ||
schema = "schema" | ||
database = "database" | ||
stage = snowflake_stage.stage.fully_qualified_name | ||
} | ||
# resource with more fields set | ||
resource "snowflake_stream_on_directory_table" "stream" { | ||
name = "stream" | ||
schema = "schema" | ||
database = "database" | ||
copy_grants = true | ||
stage = snowflake_stage.stage.fully_qualified_name | ||
at { | ||
statement = "8e5d0ca9-005e-44e6-b858-a8f5b37c5726" | ||
} | ||
comment = "A stream." | ||
} | ||
``` | ||
-> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). | ||
<!-- TODO(SNOW-1634854): include an example showing both methods--> | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `database` (String) The database in which to create the stream. Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `(`, `)`, `"` | ||
- `name` (String) Specifies the identifier for the stream; must be unique for the database and schema in which the stream is created. Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `(`, `)`, `"` | ||
- `schema` (String) The schema in which to create the stream. Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `(`, `)`, `"` | ||
- `stage` (String) Specifies an identifier for the stage the stream will monitor. Due to Snowflake limitations, the provider can not read the stage's database and schema. For stages, Snowflake returns only partially qualified name instead of fully qualified name. Please use stages located in the same schema as the stream. Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `(`, `)`, `"` | ||
|
||
### Optional | ||
|
||
- `comment` (String) Specifies a comment for the stream. | ||
- `copy_grants` (Boolean) Retains the access permissions from the original stream when a stream is recreated using the OR REPLACE clause. That is sometimes used when the provider detects changes for fields that can not be changed by ALTER. This value will not have any effect when creating a new stream. | ||
|
||
### Read-Only | ||
|
||
- `describe_output` (List of Object) Outputs the result of `DESCRIBE STREAM` for the given stream. (see [below for nested schema](#nestedatt--describe_output)) | ||
- `fully_qualified_name` (String) Fully qualified name of the resource. For more information, see [object name resolution](https://docs.snowflake.com/en/sql-reference/name-resolution). | ||
- `id` (String) The ID of this resource. | ||
- `show_output` (List of Object) Outputs the result of `SHOW STREAMS` for the given stream. (see [below for nested schema](#nestedatt--show_output)) | ||
- `stale` (Boolean) Indicated if the stream is stale. When Terraform detects that the stream is stale, the stream is recreated with `CREATE OR REPLACE`. Read more on stream staleness in Snowflake [docs](https://docs.snowflake.com/en/user-guide/streams-intro#data-retention-period-and-staleness). | ||
|
||
<a id="nestedatt--describe_output"></a> | ||
### Nested Schema for `describe_output` | ||
|
||
Read-Only: | ||
|
||
- `base_tables` (List of String) | ||
- `comment` (String) | ||
- `created_on` (String) | ||
- `database_name` (String) | ||
- `invalid_reason` (String) | ||
- `mode` (String) | ||
- `name` (String) | ||
- `owner` (String) | ||
- `owner_role_type` (String) | ||
- `schema_name` (String) | ||
- `source_type` (String) | ||
- `stale` (String) | ||
- `stale_after` (String) | ||
- `table_name` (String) | ||
- `type` (String) | ||
|
||
|
||
<a id="nestedatt--show_output"></a> | ||
### Nested Schema for `show_output` | ||
|
||
Read-Only: | ||
|
||
- `base_tables` (List of String) | ||
- `comment` (String) | ||
- `created_on` (String) | ||
- `database_name` (String) | ||
- `invalid_reason` (String) | ||
- `mode` (String) | ||
- `name` (String) | ||
- `owner` (String) | ||
- `owner_role_type` (String) | ||
- `schema_name` (String) | ||
- `source_type` (String) | ||
- `stale` (String) | ||
- `stale_after` (String) | ||
- `table_name` (String) | ||
- `type` (String) | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
terraform import snowflake_stream_on_directory_table.example '"<database_name>"."<schema_name>"."<stream_name>"' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/resources/snowflake_stream_on_directory_table/import.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import snowflake_stream_on_directory_table.example '"<database_name>"."<schema_name>"."<stream_name>"' |
33 changes: 33 additions & 0 deletions
33
examples/resources/snowflake_stream_on_directory_table/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
resource "snowflake_stage" "example_stage" { | ||
name = "EXAMPLE_STAGE" | ||
url = "s3://com.example.bucket/prefix" | ||
database = "EXAMPLE_DB" | ||
schema = "EXAMPLE_SCHEMA" | ||
credentials = "AWS_KEY_ID='${var.example_aws_key_id}' AWS_SECRET_KEY='${var.example_aws_secret_key}'" | ||
} | ||
|
||
# basic resource | ||
resource "snowflake_stream_on_directory_table" "stream" { | ||
name = "stream" | ||
schema = "schema" | ||
database = "database" | ||
|
||
stage = snowflake_stage.stage.fully_qualified_name | ||
} | ||
|
||
|
||
# resource with more fields set | ||
resource "snowflake_stream_on_directory_table" "stream" { | ||
name = "stream" | ||
schema = "schema" | ||
database = "database" | ||
|
||
copy_grants = true | ||
stage = snowflake_stage.stage.fully_qualified_name | ||
|
||
at { | ||
statement = "8e5d0ca9-005e-44e6-b858-a8f5b37c5726" | ||
} | ||
|
||
comment = "A stream." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is already present at line 10
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.
Fixed.