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

feat: Resource monitor v1 readiness part 2 #3064

Merged
merged 8 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ This document is meant to help you migrate your Terraform config to the new newe
describe deprecations or breaking changes and help you to change your configuration to keep the same (or similar) behavior
across different versions.

## v0.95.0 ➞ v0.96.0

### *(breaking change)* resource_monitor resource
Removed fields:
- `set_for_account` (will be settable on account resource, right now, the preferred way is to set it through unsafe_execute resource)
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
- `warehouses` (can be set on warehouse resource, optionally through unsafe_execute resource)
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
- `suspend_triggers` (now, `suspend_trigger` should be used)
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
- `suspend_immediate_triggers` (now, `suspend_immediate_trigger` should be used)

### *(breaking change)* resource_monitor data source
Changes:
- New filtering option `like`
- Now, the output of `SHOW RESOURCE MONITORS` is now inside `resource_monitors.*.show_output`. Here's the list of currently available fields:
- `name`
- `credit_quota`
- `used_credits`
- `remaining_credits`
- `level`
- `frequency`
- `start_time`
- `end_time`
- `suspend_at`
- `suspend_immediate_at`
- `created_on`
- `owner`
- `comment`

## v0.94.x ➞ v0.95.0

### *(breaking change)* database roles data source; field rename, schema structure changes, and adding missing filtering options
Expand Down
61 changes: 57 additions & 4 deletions docs/data-sources/database_roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,73 @@
page_title: "snowflake_database_roles Data Source - terraform-provider-snowflake"
subcategory: ""
description: |-
Datasource used to get details of filtered database roles. Filtering is aligned with the current possibilities for SHOW DATABASE ROLES https://docs.snowflake.com/en/sql-reference/sql/show-database-roles query (like and limit are supported). The results of SHOW is encapsulated in show_output collection.
---

!> **V1 release candidate** This data source 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 data source if needed. Any errors reported will be resolved with a higher priority. We encourage checking this data source out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0920--v0930) to use it.

# snowflake_database_roles (Data Source)


Datasource used to get details of filtered database roles. Filtering is aligned with the current possibilities for [SHOW DATABASE ROLES](https://docs.snowflake.com/en/sql-reference/sql/show-database-roles) query (`like` and `limit` are supported). The results of SHOW is encapsulated in show_output collection.

## Example Usage

```terraform
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"
}
}
```

Expand Down
69 changes: 64 additions & 5 deletions docs/data-sources/resource_monitors.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,93 @@
page_title: "snowflake_resource_monitors Data Source - terraform-provider-snowflake"
subcategory: ""
description: |-
Datasource used to get details of filtered resource monitors. Filtering is aligned with the current possibilities for SHOW RESOURCE MONITORS https://docs.snowflake.com/en/sql-reference/sql/show-resource-monitors query (like is supported). The results of SHOW is encapsulated in show_output collection.
---

# snowflake_resource_monitors (Data Source)
!> **V1 release candidate** This data source 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 data source if needed. Any errors reported will be resolved with a higher priority. We encourage checking this data source out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0950--v0960) to use it.

# snowflake_resource_monitors (Data Source)

Datasource used to get details of filtered resource monitors. Filtering is aligned with the current possibilities for [SHOW RESOURCE MONITORS](https://docs.snowflake.com/en/sql-reference/sql/show-resource-monitors) query (`like` is supported). The results of SHOW is encapsulated in show_output collection.

## Example Usage

```terraform
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"
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `like` (String) Filters the output with **case-insensitive** pattern, with support for SQL wildcard characters (`%` and `_`).

### Read-Only

- `id` (String) The ID of this resource.
- `resource_monitors` (List of Object) The resource monitors in the database (see [below for nested schema](#nestedatt--resource_monitors))
- `resource_monitors` (List of Object) Holds the aggregated output of all resource monitor details queries. (see [below for nested schema](#nestedatt--resource_monitors))

<a id="nestedatt--resource_monitors"></a>
### Nested Schema for `resource_monitors`

Read-Only:

- `show_output` (List of Object) (see [below for nested schema](#nestedobjatt--resource_monitors--show_output))

<a id="nestedobjatt--resource_monitors--show_output"></a>
### Nested Schema for `resource_monitors.show_output`

Read-Only:

- `comment` (String)
- `credit_quota` (String)
- `created_on` (String)
- `credit_quota` (Number)
- `end_time` (String)
- `frequency` (String)
- `level` (String)
- `name` (String)
- `owner` (String)
- `remaining_credits` (Number)
- `start_time` (String)
- `suspend_at` (Number)
- `suspend_immediate_at` (Number)
- `used_credits` (Number)
28 changes: 20 additions & 8 deletions docs/resources/resource_monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,41 @@ description: |-

---

!> **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#v0950--v0960) to use it.

**! Warning !** Due to Snowflake limitations, the following actions are not supported:
- Cannot create resource monitors with only triggers set, any other attribute has to be set.
- Once a resource monitor has at least one trigger assigned, it cannot fully unset them (has to have at least one trigger, doesn't matter of which type). It has to be re-created without triggers to fully unset them.

# snowflake_resource_monitor (Resource)



## Example Usage

```terraform
resource "snowflake_resource_monitor" "monitor" {
name = "monitor"
resource "snowflake_resource_monitor" "minimal" {
name = "resource-monitor-name"
credit_quota = 100
suspend_trigger = 100
notify_users = ["USERONE", "USERTWO"]
}

resource "snowflake_resource_monitor" "complete" {
name = "resource-monitor-name"
credit_quota = 100

frequency = "DAILY"
start_timestamp = "2020-12-07 00:00"
end_timestamp = "2021-12-07 00:00"
start_timestamp = "2030-12-07 00:00"
end_timestamp = "2035-12-07 00:00"

notify_triggers = [40, 50]
suspend_triggers = 50
suspend_immediate_triggers = 90
notify_triggers = [40, 50]
suspend_trigger = 50
suspend_immediate_trigger = 90

notify_users = ["USERONE", "USERTWO"]
}
```

-> **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-->

Expand Down
59 changes: 56 additions & 3 deletions examples/data-sources/snowflake_database_roles/data-source.tf
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)
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
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 examples/data-sources/snowflake_resource_monitors/data-source.tf
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"
}
}
21 changes: 14 additions & 7 deletions examples/resources/snowflake_resource_monitor/resource.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
resource "snowflake_resource_monitor" "monitor" {
name = "monitor"
resource "snowflake_resource_monitor" "minimal" {
name = "resource-monitor-name"
credit_quota = 100
suspend_trigger = 100
notify_users = ["USERONE", "USERTWO"]
}

resource "snowflake_resource_monitor" "complete" {
name = "resource-monitor-name"
credit_quota = 100

frequency = "DAILY"
start_timestamp = "2020-12-07 00:00"
end_timestamp = "2021-12-07 00:00"
start_timestamp = "2030-12-07 00:00"
end_timestamp = "2035-12-07 00:00"

notify_triggers = [40, 50]
suspend_triggers = 50
suspend_immediate_triggers = 90
notify_triggers = [40, 50]
suspend_trigger = 50
suspend_immediate_trigger = 90

notify_users = ["USERONE", "USERTWO"]
}
Loading
Loading