-
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: Resource monitor v1 readiness part 2 (#3064)
## Changes - Refactor data source - Update examples and documentation for resource and data source - Update examples for database role ## Test Plan <!-- detail ways in which this PR has been tested or needs to be tested --> * [x] acceptance tests ## References <!-- issues documentation links, etc --> * [SHOW RESOURCE MONITORS](https://docs.snowflake.com/en/sql-reference/sql/show-resource-monitors)
- Loading branch information
1 parent
0981bfc
commit 7c7ef99
Showing
18 changed files
with
709 additions
and
93 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
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
59 changes: 56 additions & 3 deletions
59
examples/data-sources/snowflake_database_roles/data-source.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 |
---|---|---|
@@ -1,3 +1,56 @@ | ||
data "snowflake_database_roles" "db_roles" { | ||
database = "MYDB" | ||
} | ||
# Simple usage | ||
data "snowflake_database_roles" "simple" { | ||
in_database = "database-name" | ||
} | ||
|
||
output "simple_output" { | ||
value = data.snowflake_database_roles.simple.database_roles | ||
} | ||
|
||
# Filtering (like) | ||
data "snowflake_database_roles" "like" { | ||
in_database = "database-name" | ||
like = "database_role-name" | ||
} | ||
|
||
output "like_output" { | ||
value = data.snowflake_database_roles.like.database_roles | ||
} | ||
|
||
# Filtering (limit) | ||
data "snowflake_database_roles" "limit" { | ||
in_database = "database-name" | ||
limit { | ||
rows = 10 | ||
from = "prefix-" | ||
} | ||
} | ||
|
||
output "limit_output" { | ||
value = data.snowflake_database_roles.limit.database_roles | ||
} | ||
|
||
# Ensure the number of database roles is equal to at least one element (with the use of postcondition) | ||
data "snowflake_database_roles" "assert_with_postcondition" { | ||
in_database = "database-name" | ||
like = "database_role-name-%" | ||
lifecycle { | ||
postcondition { | ||
condition = length(self.database_roles) > 0 | ||
error_message = "there should be at least one database role" | ||
} | ||
} | ||
} | ||
|
||
# Ensure the number of database roles is equal to at exactly one element (with the use of check block) | ||
check "database_role_check" { | ||
data "snowflake_resource_monitors" "assert_with_check_block" { | ||
in_database = "database-name" | ||
like = "database_role-name" | ||
} | ||
|
||
assert { | ||
condition = length(data.snowflake_database_roles.assert_with_check_block.database_roles) == 1 | ||
error_message = "Database roles filtered by '${data.snowflake_database_roles.assert_with_check_block.like}' returned ${length(data.snowflake_database_roles.assert_with_check_block.database_roles)} database roles where one was expected" | ||
} | ||
} |
41 changes: 39 additions & 2 deletions
41
examples/data-sources/snowflake_resource_monitors/data-source.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 |
---|---|---|
@@ -1,2 +1,39 @@ | ||
data "snowflake_resource_monitors" "current" { | ||
} | ||
# Simple usage | ||
data "snowflake_resource_monitors" "simple" { | ||
} | ||
|
||
output "simple_output" { | ||
value = data.snowflake_resource_monitors.simple.resource_monitors | ||
} | ||
|
||
# Filtering (like) | ||
data "snowflake_resource_monitors" "like" { | ||
like = "resource-monitor-name" | ||
} | ||
|
||
output "like_output" { | ||
value = data.snowflake_resource_monitors.like.resource_monitors | ||
} | ||
|
||
# Ensure the number of resource monitors is equal to at least one element (with the use of postcondition) | ||
data "snowflake_resource_monitors" "assert_with_postcondition" { | ||
like = "resource-monitor-name-%" | ||
lifecycle { | ||
postcondition { | ||
condition = length(self.resource_monitors) > 0 | ||
error_message = "there should be at least one resource monitor" | ||
} | ||
} | ||
} | ||
|
||
# Ensure the number of resource monitors is equal to at exactly one element (with the use of check block) | ||
check "resource_monitor_check" { | ||
data "snowflake_resource_monitors" "assert_with_check_block" { | ||
like = "resource-monitor-name" | ||
} | ||
|
||
assert { | ||
condition = length(data.snowflake_resource_monitors.assert_with_check_block.resource_monitors) == 1 | ||
error_message = "Resource monitors filtered by '${data.snowflake_resource_monitors.assert_with_check_block.like}' returned ${length(data.snowflake_resource_monitors.assert_with_check_block.resource_monitors)} resource monitors where one was expected" | ||
} | ||
} |
Oops, something went wrong.