Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Sep 9, 2024
1 parent 048b510 commit f49e44e
Show file tree
Hide file tree
Showing 19 changed files with 469 additions and 369 deletions.
38 changes: 27 additions & 11 deletions docs/resources/resource_monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,39 @@ resource "snowflake_resource_monitor" "monitor" {

### Optional

- `credit_quota` (Number) The number of credits allocated monthly to the resource monitor.
- `credit_quota` (Number) The number of credits allocated to the resource monitor per frequency interval. When total usage for all warehouses assigned to the monitor reaches this number for the current frequency interval, the resource monitor is considered to be at 100% of quota.
- `end_timestamp` (String) The date and time when the resource monitor suspends the assigned warehouses.
- `frequency` (String) The frequency interval at which the credit usage resets to 0. If you set a frequency for a resource monitor, you must also set START_TIMESTAMP.
- `notify_triggers` (Set of Number) A list of percentage thresholds at which to send an alert to subscribed users.
- `notify_users` (Set of String) Specifies the list of users to receive email notifications on resource monitors.
- `set_for_account` (Boolean) Specifies whether the resource monitor should be applied globally to your Snowflake account (defaults to false).
- `start_timestamp` (String) The date and time when the resource monitor starts monitoring credit usage for the assigned warehouses.
- `suspend_immediate_trigger` (Number) The number that represents the percentage threshold at which to immediately suspend all warehouses.
- `suspend_immediate_triggers` (Set of Number, Deprecated) A list of percentage thresholds at which to suspend all warehouses.
- `suspend_trigger` (Number) The number that represents the percentage threshold at which to suspend all warehouses.
- `suspend_triggers` (Set of Number, Deprecated) A list of percentage thresholds at which to suspend all warehouses.
- `warehouses` (Set of String) A list of warehouses to apply the resource monitor to.
- `frequency` (String) The frequency interval at which the credit usage resets to 0. Valid values are (case-insensitive): `MONTHLY` | `DAILY` | `WEEKLY` | `YEARLY` | `NEVER`. If you set a `frequency` for a resource monitor, you must also set `start_timestamp`. If you specify `NEVER` for the frequency, the credit usage for the warehouse does not reset. After removing this field from the config, the previously set value will be preserved on the Snowflake side, not the default value. That's due to Snowflake limitation and the lack of unset functionality for this parameter.
- `notify_triggers` (Set of Number)
- `notify_users` (Set of String) Specifies the list of users (their identifiers) to receive email notifications on resource monitors.
- `start_timestamp` (String) The date and time when the resource monitor starts monitoring credit usage for the assigned warehouses. If you set a `start_timestamp` for a resource monitor, you must also set `frequency`. After removing this field from the config, the previously set value will be preserved on the Snowflake side, not the default value. That's due to Snowflake limitation and the lack of unset functionality for this parameter.
- `suspend_immediate_trigger` (Number)
- `suspend_trigger` (Number)

### Read-Only

- `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 RESOURCE MONITORS` for the given resource monitor. (see [below for nested schema](#nestedatt--show_output))

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

Read-Only:

- `comment` (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)

## Import

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/warehouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "snowflake_warehouse" "warehouse" {
- `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.
- `parameters` (List of Object) Outputs the result of `SHOW PARAMETERS IN WAREHOUSE` for the given warehouse. (see [below for nested schema](#nestedatt--parameters))
- `show_output` (List of Object) Outputs the result of `SHOW WAREHOUSE` for the given warehouse. (see [below for nested schema](#nestedatt--show_output))
- `show_output` (List of Object) Outputs the result of `SHOW WAREHOUSES` for the given warehouse. (see [below for nested schema](#nestedatt--show_output))

<a id="nestedatt--parameters"></a>
### Nested Schema for `parameters`
Expand Down
8 changes: 3 additions & 5 deletions framework/provider/resource_monitor_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (r *ResourceMonitorResource) create(ctx context.Context, data *resourceMoni
elements := make([]types.String, 0, len(data.NotifyUsers.Elements()))
var notifiedUsers []sdk.NotifiedUser
for _, e := range elements {
notifiedUsers = append(notifiedUsers, sdk.NotifiedUser{Name: e.ValueString()})
notifiedUsers = append(notifiedUsers, sdk.NotifiedUser{Name: sdk.NewAccountObjectIdentifier(e.ValueString())})
}
with.NotifyUsers = &sdk.NotifyUsers{
Users: notifiedUsers,
Expand Down Expand Up @@ -600,13 +600,11 @@ func (r *ResourceMonitorResource) read(ctx context.Context, data *resourceMonito

data.CreditQuota = types.Float64Value(resourceMonitor.CreditQuota)
data.Frequency = types.StringValue(string(resourceMonitor.Frequency))
switch resourceMonitor.Level {
switch *resourceMonitor.Level {
case sdk.ResourceMonitorLevelAccount:
data.Level = types.StringValue("ACCOUNT")
case sdk.ResourceMonitorLevelWarehouse:
data.Level = types.StringValue("WAREHOUSE")
case sdk.ResourceMonitorLevelNull:
data.Level = types.StringValue("NULL")
}
data.UsedCredits = types.Float64Value(resourceMonitor.UsedCredits)
data.RemainingCredits = types.Float64Value(resourceMonitor.RemainingCredits)
Expand Down Expand Up @@ -734,7 +732,7 @@ func (r *ResourceMonitorResource) update(ctx context.Context, plan *resourceMoni
elements := make([]types.String, 0, len(plan.NotifyUsers.Elements()))
plan.NotifyUsers.ElementsAs(ctx, &elements, false)
for _, e := range elements {
notifiedUsers = append(notifiedUsers, sdk.NotifiedUser{Name: e.ValueString()})
notifiedUsers = append(notifiedUsers, sdk.NotifiedUser{Name: sdk.NewAccountObjectIdentifier(e.ValueString())})
}
opts.Set.NotifyUsers = &sdk.NotifyUsers{
Users: notifiedUsers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resourceassert

import (
"fmt"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"strconv"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
Expand All @@ -28,13 +27,12 @@ func (r *ResourceMonitorResourceAssert) HasNotifyUser(index int, userName string
return r
}

func (r *ResourceMonitorResourceAssert) HasTriggerLen(len int) *ResourceMonitorResourceAssert {
r.AddAssertion(assert.ValueSet("trigger.#", strconv.FormatInt(int64(len), 10)))
func (r *ResourceMonitorResourceAssert) HasNotifyTriggersLen(len int) *ResourceMonitorResourceAssert {
r.AddAssertion(assert.ValueSet("notify_triggers.#", strconv.FormatInt(int64(len), 10)))
return r
}

func (r *ResourceMonitorResourceAssert) HasTrigger(index int, threshold int, action sdk.TriggerAction) *ResourceMonitorResourceAssert {
r.AddAssertion(assert.ValueSet(fmt.Sprintf("trigger.%d.threshold", index), strconv.FormatInt(int64(threshold), 10)))
r.AddAssertion(assert.ValueSet(fmt.Sprintf("trigger.%d.on_threshold_reached", index), string(action)))
func (r *ResourceMonitorResourceAssert) HasNotifyTrigger(index int, threshold int) *ResourceMonitorResourceAssert {
r.AddAssertion(assert.ValueSet(fmt.Sprintf("notify_triggers.%d", index), strconv.Itoa(threshold)))
return r
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions pkg/acceptance/bettertestspoc/config/model/view_model_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f49e44e

Please sign in to comment.