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

Bug report: Resource Monitors can not change triggers arguments without changing the credit_quota argument #1500

Closed
MikkelKrabbeNielsen opened this issue Jan 30, 2023 · 5 comments
Assignees
Labels
bug Used to mark issues with provider's incorrect behavior category:resource resource:resource_monitor Issue connected to the snowflake_resource_monitor resource

Comments

@MikkelKrabbeNielsen
Copy link

MikkelKrabbeNielsen commented Jan 30, 2023

Provider Version

v0.55.0

Terraform Version

1.28

Describe the bug

The snowflake provider 0.55.0 allows for Resource Monitors to change the "credit_quota" argument without running a drop/create command. However, when changing the following arguments:

  • "notify_triggers"
  • "suspend_triggers"
  • "suspend_immediate_triggers"
    the compiled SnowSQL returns an error.

Expected behavior

Terraform apply will be successful.

Code samples and commands

The Resource Monitor resource, using a user assigned the accountadmin role:
resource "snowflake_resource_monitor" "resource_monitor" { name = "resource_monitor_test" credit_quota = 100 notify_triggers = [ 50 ] suspend_triggers = [ 100 ] suspend_immediate_triggers = [ 105 ] }
Changing "notify_trigger" argument
resource "snowflake_resource_monitor" "resource_monitor" { name = "resource_monitor_test" credit_quota = 100 notify_triggers = [ 55 ] suspend_triggers = [ 100 ] suspend_immediate_triggers = [ 105 ] }

Returns the following error message:
│ 001003 (42000): SQL compilation error:
│ syntax error line 1 at position 57 unexpected 'ON'.
│ syntax error line 1 at position 72 unexpected 'DO'.
│ syntax error line 1 at position 83 unexpected 'ON'.
│ syntax error line 1 at position 98 unexpected 'DO'.
│ syntax error line 1 at position 119 unexpected 'ON'.
│ syntax error line 1 at position 133 unexpected 'DO'.
│ syntax error line 1 at position 143 unexpected 'ON'.
│ syntax error line 1 at position 157 unexpected 'DO'.
│ syntax error line 1 at position 166 unexpected ''.

Additional context

Investigation into the compiled SnowSQL:

ALTER RESOURCE MONITOR "RESOURCE_MONITOR_TEST" SET TRIGGERS ON 100 PERCENT DO SUSPEND ON 105 PERCENT DO SUSPEND_IMMEDIATE ON 55 PERCENT DO NOTIFY ;
A possible solution, is to have the compiled SnowSQL to have the "credit_quota" present, even if the the argument has not changed:
ALTER RESOURCE MONITOR "RESOURCE_MONITOR_TEST" SET CREDIT_QUOTA = 100 TRIGGERS ON 100 PERCENT DO SUSPEND ON 105 PERCENT DO SUSPEND_IMMEDIATE ON 55 PERCENT DO NOTIFY ;

@MikkelKrabbeNielsen MikkelKrabbeNielsen added the bug Used to mark issues with provider's incorrect behavior label Jan 30, 2023
@bennylu2
Copy link
Contributor

@sfc-gh-jlove this appears to be a syntax issue when modifying resource monitors triggers only, it adds SET to the ALTER statement. If only altering triggers, SET should not be included. Re-using the credit quota is one way to solve but I believe it'd be cleaner to optionally add the SET depending if attributes are altered or only triggers

@betclicadri
Copy link

betclicadri commented Dec 13, 2023

I have a similar issue using TF Snowflake Provider v0.70.1 when I would like to update an existing Ressource Monitor with "notify_triggers", "notify_users", and "supend_immediate_trigger".

Before:

resource "snowflake_resource_monitor" "my_monitor" {
  name                      = "MY_MONITOR"
  credit_quota              = 44 # per month
  warehouses                = "MY_WAREHOUSE"
}

After:

resource "snowflake_resource_monitor" "my_monitor" {
  name                      = "MY_MONITOR"
  credit_quota              = 44 # per month
  warehouses                = "MY_WAREHOUSE"
  notify_triggers           = [50, 100]            # Add
  notify_users              = ["MY_USER"]      # Add
  suspend_immediate_trigger = 100        # Add
}

Error:

error updating resource monitor MY_MONITOR
001003 (42000): SQL compilation error:
syntax error line 1 at position 62 unexpected 'ON'.
syntax error line 1 at position 77 unexpected 'DO'.
syntax error line 1 at position 98 unexpected 'ON'.
syntax error line 1 at position 112 unexpected 'DO'.
syntax error line 1 at position 122 unexpected 'ON'.
syntax error line 1 at position 137 unexpected 'DO'.
syntax error line 1 at position 146 unexpected '<EOF>'.�[0m
with snowflake_resource_monitor.my_monitor,
  on resource_monitors.tf line 1, in resource "snowflake_resource_monitor" "my_monitor":
   1: resource "snowflake_resource_monitor" "my_monitor" 

As temporary solution, destroy and recreate the RessourceMonitor works but you can loose Ressource Monitor current quota usage.

@sfc-gh-jcieslak sfc-gh-jcieslak added category:resource resource:resource_monitor Issue connected to the snowflake_resource_monitor resource labels May 20, 2024
@sfc-gh-jcieslak
Copy link
Collaborator

Hi all 👋
I'm currently working on the resource monitor as part of preparing GA objects for V1. As you already the root cause it's more of a Snowflake limitation rather than the provider one. When refactoring the resource monitor, I'll make sure it will be clearer on how to interact with the resource and apply the mentioned workarounds to make it work. The updated resource should be available in the v0.96.0 version of the provider, but I'll let you know here when it will be available.

@sfc-gh-jcieslak sfc-gh-jcieslak self-assigned this Sep 5, 2024
sfc-gh-jcieslak added a commit that referenced this issue Sep 11, 2024
## Changes
- Add ValuePresent assert to our custom assertions
- Add ToConfigValues function for every model
- Update Resource Monitor SDK + unit and integration tests
- Update Resource Monitor Resource + acc tests
- Handle issues connected to the resource monitor (mostly timestamp
format difference causing infinite plan or only trigger updates causing
SQL compilation error):
  -  #1500 
  - #1624 
  - #1716 
  - #1754 
  - #1821 
  - #1832 
  - #1990

## Next pr
- Adjust examples and update migration notes
- Data source (impl, tests, examples, migration notes)

## References
* [CREATE RESOURCE
MONITOR](https://docs.snowflake.com/en/sql-reference/sql/create-resource-monitor)
sfc-gh-fbudzynski pushed a commit that referenced this issue Sep 19, 2024
## Changes
- Add ValuePresent assert to our custom assertions
- Add ToConfigValues function for every model
- Update Resource Monitor SDK + unit and integration tests
- Update Resource Monitor Resource + acc tests
- Handle issues connected to the resource monitor (mostly timestamp
format difference causing infinite plan or only trigger updates causing
SQL compilation error):
  -  #1500 
  - #1624 
  - #1716 
  - #1754 
  - #1821 
  - #1832 
  - #1990

## Next pr
- Adjust examples and update migration notes
- Data source (impl, tests, examples, migration notes)

## References
* [CREATE RESOURCE
MONITOR](https://docs.snowflake.com/en/sql-reference/sql/create-resource-monitor)
@sfc-gh-jcieslak
Copy link
Collaborator

Hey 👋
The new and refactored resource monitor was released yesterday in version 0.96.0 of the provider. Please migrate with migration guide and let me know if the issue has been resolved so we could close the ticket. Thanks in advance 🙏.

@sfc-gh-jcieslak
Copy link
Collaborator

Closing due to long inactivity. Please, create another issue if you think the problem is still not resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to mark issues with provider's incorrect behavior category:resource resource:resource_monitor Issue connected to the snowflake_resource_monitor resource
Projects
None yet
Development

No branches or pull requests

4 participants