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

Resource Monitor start_timestamp string format. #1175

Open
abrougher1-rbi opened this issue Aug 16, 2022 · 4 comments
Open

Resource Monitor start_timestamp string format. #1175

abrougher1-rbi opened this issue Aug 16, 2022 · 4 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

@abrougher1-rbi
Copy link

Provider Version

0.37.1

Terraform Version

v1.1.9

Describe the bug

The resource_monitor start_timestamp never matches forcing TF to replace the resource on each run.

# module.account.snowflake_resource_monitor.ingestion_monitor[0] must be replaced -/+ resource "snowflake_resource_monitor" "ingestion_monitor" { ~ id = "INGESTION_MONITOR" -> (known after apply) name = "INGESTION_MONITOR" ~ start_timestamp = "2022-08-17T00:00:00Z" -> "2022-08-17 00:00" # forces replacement - suspend_immediate_triggers = [] -> null - suspend_triggers = [] -> null # (5 unchanged attributes hidden) }

The issue looks like it might be due to the format of the start_timestamp when read from Snowflake vs the timestamp required to set the value in snowflake.

ResourceMonitor Show is likely returning the format "2022-08-17T00:00:00Z" while we set the string to "2022-08-17 00:00" in the config.
https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/pkg/resources/resource_monitor.go#L189

Expected behavior

The snowflake_resource_monitor resource should be created once and not be replaced on every plan.

Additional context

This issue is similar to a previously fixed resource_monitor type bug.
#145

@abrougher1-rbi abrougher1-rbi added the bug Used to mark issues with provider's incorrect behavior label Aug 16, 2022
@culpgrant
Copy link

Hey @abrougher1-rbi did you ever come up with a workaround?

@funes79
Copy link
Contributor

funes79 commented Feb 24, 2023

Hi,
it looks like that the provider is generating a command like this:

CREATE OR REPLACE RESOURCE MONITOR "MY_WH" FREQUENCY='MONTHLY' START_TIMESTAMP='2023-03-01T00:00:000Z' CREDIT_QUOTA=100 TRIGGERS ON 130 PERCENT DO SUSPEND ON 135 PERCENT DO SUSPEND_IMMEDIATE ON 80 PERCENT DO NOTIFY ON 100 PERCENT DO NOTIFY

But it throws a Snowflake error:

Invalid date/time format string '2023-03-01T00:00:000Z': Invalid format: "2023-03-01T00:00:000Z" is malformed at "T00:00:000Z"

Workaround is to create the resource monitor WITH the start_time, and after apply, remove the start_time from the tf code. :-/

@MartinGuindon
Copy link

I'm also experiencing this bug.

I can create a resource monitor successfully with the following code:

resource "snowflake_resource_monitor" "daily_quota_monitor" {
  name                       = "Daily Quota Monitor"
  warehouses                 = toset(keys(local.warehouses))
  credit_quota               = 5
  frequency                  = "DAILY"
  start_timestamp            = "2023-03-01 00:00"
  notify_triggers            = [50, 75]
  suspend_triggers           = [95]
  suspend_immediate_triggers = [100]
  depends_on                 = [snowflake_warehouse.warehouse]
}

But any subsequent runs of the TF project will report non-matching values:

  ~ resource "snowflake_resource_monitor" "daily_quota_monitor" {
        id                         = "Daily Quota Monitor"
        name                       = "Daily Quota Monitor"
      ~ start_timestamp            = "2023-03-01T00:00:00Z" -> "2023-03-01 00:00"
        # (7 unchanged attributes hidden)
    }

Which obviously fails.

Right now the workaround is to update the TF code to use the value 2023-03-01T00:00:00Z. That value doesn't work on creation:

│ Error: error creating resource monitor Daily Quota Monitor err = 002105 (42601): SQL compilation error:
│ Invalid date/time format string '2023-03-01T00:00:00Z': Invalid format: "2023-03-01T00:00:00Z" is malformed at "T00:00:00Z"
│ 
│   with snowflake_resource_monitor.daily_quota_monitor,
│   on resource_monitors.tf line 14, in resource "snowflake_resource_monitor" "daily_quota_monitor":
│   14: resource "snowflake_resource_monitor" "daily_quota_monitor" {
│ 
╵
Operation failed: failed running terraform apply (exit 1)

@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

sfc-gh-jcieslak commented Sep 5, 2024

Hi all 👋
I'm currently working on the resource monitor as part of preparing GA objects for V1. This is a tricky issue to solve on the provider as Snowflake accepts multiple timestamp formats. In the refactored resource monitor (that should be available in v0.96.0), the format of RRRR-MM-DD hh:mm should not produce any plans, and it will most likely be the recommended format (but potentially every timestamp format will be accepted and shouldn't produce any plans). Everything will be documented; I'll let you know here when the v0.96.0 will be available so you can try the refreshed resource monitor.

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

5 participants