-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Task datasource and fixes (#3195)
## Changes - Fixed the need to enclose `config` with $$ - Added full datasource support with tests - Documentation and examples (v1 candidates; added for resource and datasource) - Migration guide (now only for datasource) - Extracted schema for regular `in` filtering - Describe wasn't added on purpose, because it seems to mirror values from what we get from the SHOW command (can also add it, but for now it doesn't provide any benefits) ## List from previous prs - [ ] Apply comments #3170 - [ ] Apply comments from #3113 - [x] Cron #3113 (comment) - [ ] Resource logic #3113 (comment) - [ ] Refactor SDK suspend root logic for tasks (and overall suspend logic in SDK/resource) #3113 (comment) - [ ] Move some of the logic to SDK (if possible) - [ ] #3170 (comment) - [ ] Refactor task resuming in task resource (most likely with the use of defer) because currently, there may be cases that error can cause tasks to be not resumed. - [ ] Tests - [ ] External changes - #3113 (comment) - [ ] Add more complicated DAG structures to show the resource can handle more complex structures - [ ] Calling (`as` field) - #3113 (comment) - [ ] For showing how the DAG of tasks could be owned by a role other than the one created with Terraform (also with less privileges, only to run the task). - [x] Check in one acceptance test why finalizer task in show_output is not set (is that Snowflake or mapping error). - [x] Data source - [ ] Examples, documentation, and migration guide - [ ] Keep manually changed files after regeneration #3113 (comment) - [x] Make config without $$ escapes needed - [ ] Support session paramters - [ ] Analyze non-deterministic test cases - [ ] Check test tasks_gen_integration_test.go:937 (and see why it's non deterministic). - [ ] Re-generate and list all the issues with asserts and models
- Loading branch information
1 parent
af50770
commit cb27cae
Showing
21 changed files
with
1,647 additions
and
144 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,120 @@ | ||
data "snowflake_tasks" "current" { | ||
database = "MYDB" | ||
schema = "MYSCHEMA" | ||
} | ||
# Simple usage | ||
data "snowflake_tasks" "simple" { | ||
} | ||
|
||
output "simple_output" { | ||
value = data.snowflake_tasks.simple.tasks | ||
} | ||
|
||
# Filtering (like) | ||
data "snowflake_tasks" "like" { | ||
like = "task-name" | ||
} | ||
|
||
output "like_output" { | ||
value = data.snowflake_tasks.like.tasks | ||
} | ||
|
||
# Filtering (in - account - database - schema - application - application package) | ||
data "snowflake_tasks" "in_account" { | ||
in { | ||
account = true | ||
} | ||
} | ||
|
||
data "snowflake_tasks" "in_database" { | ||
in { | ||
database = "<database_name>" | ||
} | ||
} | ||
|
||
data "snowflake_tasks" "in_schema" { | ||
in { | ||
schema = "<database_name>.<schema_name>" | ||
} | ||
} | ||
|
||
data "snowflake_tasks" "in_application" { | ||
in { | ||
application = "<application_name>" | ||
} | ||
} | ||
|
||
data "snowflake_tasks" "in_application_package" { | ||
in { | ||
application_package = "<application_package_name>" | ||
} | ||
} | ||
|
||
output "in_output" { | ||
value = { | ||
"account" : data.snowflake_tasks.in_account.tasks, | ||
"database" : data.snowflake_tasks.in_database.tasks, | ||
"schema" : data.snowflake_tasks.in_schema.tasks, | ||
"application" : data.snowflake_tasks.in_application.tasks, | ||
"application_package" : data.snowflake_tasks.in_application_package.tasks, | ||
} | ||
} | ||
|
||
# Filtering (root only tasks) | ||
data "snowflake_tasks" "root_only" { | ||
root_only = true | ||
} | ||
|
||
output "root_only_output" { | ||
value = data.snowflake_tasks.root_only.tasks | ||
} | ||
|
||
# Filtering (starts_with) | ||
data "snowflake_tasks" "starts_with" { | ||
starts_with = "task-" | ||
} | ||
|
||
output "starts_with_output" { | ||
value = data.snowflake_tasks.starts_with.tasks | ||
} | ||
|
||
# Filtering (limit) | ||
data "snowflake_tasks" "limit" { | ||
limit { | ||
rows = 10 | ||
from = "task-" | ||
} | ||
} | ||
|
||
output "limit_output" { | ||
value = data.snowflake_tasks.limit.tasks | ||
} | ||
|
||
# Without additional data (to limit the number of calls make for every found task) | ||
data "snowflake_tasks" "only_show" { | ||
# with_parameters is turned on by default and it calls SHOW PARAMETERS FOR task for every task found and attaches its output to tasks.*.parameters field | ||
with_parameters = false | ||
} | ||
|
||
output "only_show_output" { | ||
value = data.snowflake_tasks.only_show.tasks | ||
} | ||
|
||
# Ensure the number of tasks is equal to at least one element (with the use of postcondition) | ||
data "snowflake_tasks" "assert_with_postcondition" { | ||
starts_with = "task-name" | ||
lifecycle { | ||
postcondition { | ||
condition = length(self.tasks) > 0 | ||
error_message = "there should be at least one task" | ||
} | ||
} | ||
} | ||
|
||
# Ensure the number of tasks is equal to at exactly one element (with the use of check block) | ||
check "task_check" { | ||
data "snowflake_tasks" "assert_with_check_block" { | ||
like = "task-name" | ||
} | ||
|
||
assert { | ||
condition = length(data.snowflake_tasks.assert_with_check_block.tasks) == 1 | ||
error_message = "tasks filtered by '${data.snowflake_tasks.assert_with_check_block.like}' returned ${length(data.snowflake_tasks.assert_with_check_block.tasks)} tasks where one was expected" | ||
} | ||
} |
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
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.