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]: Issue creating snowflake alert #3117

Closed
1 task
NaveenAutomate opened this issue Oct 8, 2024 · 9 comments
Closed
1 task

[Bug]: Issue creating snowflake alert #3117

NaveenAutomate opened this issue Oct 8, 2024 · 9 comments
Labels
category:resource general-usage General help/usage questions resource:alert Issue connected to the snowflake_alert resource

Comments

@NaveenAutomate
Copy link

Terraform CLI Version

1.9.5

Terraform Provider Version

0.92.0

Terraform Configuration

I am trying to create snowflake_alert, the alert is created in the snowflake but the terraform apply failed with error 

Error: Provider produced inconsistent result after apply
│
│ When applying changes to module.snowflake_alerts.snowflake_alert.slack_alert, provider "provider[\"registry.terraform.io/snowflake-labs/snowflake\"]" produced an unexpected new value:
│ Root object was present, but now absent.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker. 


//code
resource "snowflake_alert" "slack_alert" {
  database  = var.snowflake_database
  name      = upper("${var.db_site}SlackEmailNotificationAlert")
  schema    = var.snowflake_schema
  warehouse = var.warehouse

  alert_schedule {
    interval = 1 #check every minute for new alerts
  }

  action    = "CALL SYSTEM$SEND_EMAIL(integration_name => 'EMAIL_INTEGRATION', recipients => ARRAY_CONSTRUCT(${join(",", formatlist("'%s'", var.email_recipients))}), subject => 'Snowflake Alert Notification', content => 'New alerts have been logged in ${var.alert_table_name} table.');"

  condition  = "SELECT * FROM ${var.snowflake_database}.${var.snowflake_schema}.${snowflake_table.alert_table.name} WHERE alert_timestamp BETWEEN SNOWFLAKE.ALERT.LAST_SUCCESSFUL_SCHEDULED_TIME() AND SNOWFLAKE.ALERT.SCHEDULED_TIME()"

  enabled   = true
  comment   = "Slack Notification alert for new entries in the alert table"
}


I have observed one thing in snowflake for alert, when I try to describe the alert with the same user who created the alert,

DESC ALERT DBNAME.SCHEMA.ALERTNAME;-- throws an error not exists or unauthorized
DESC ALERT DBNAME.SCHEMA."ALERTNAME";-- when wrapped the alert name in quotes it works

Category

category:resource

Object type(s)

resource:alert

Expected Behavior

Alert should be created successfully and apply should not fail

Actual Behavior

Alert is created but terraform failed with

Error: Provider produced inconsistent result after apply

│ When applying changes to module.snowflake_alerts.snowflake_alert.slack_alert, provider "provider["registry.terraform.io/snowflake-labs/snowflake"]" produced an unexpected new value:
│ Root object was present, but now absent.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Steps to Reproduce

  1. use the following resource
    `resource "snowflake_alert" "slack_alert" {
    database = var.snowflake_database
    name = upper("${var.db_site}SlackEmailNotificationAlert")
    schema = var.snowflake_schema
    warehouse = var.warehouse

alert_schedule {
interval = 1 #check every minute for new alerts
}

action = "CALL SYSTEM$SEND_EMAIL(integration_name => 'EMAIL_INTEGRATION', recipients => ARRAY_CONSTRUCT(${join(",", formatlist("'%s'", var.email_recipients))}), subject => 'Snowflake Alert Notification', content => 'New alerts have been logged in ${var.alert_table_name} table.');"

condition = "SELECT * FROM ${var.snowflake_database}.${var.snowflake_schema}.${snowflake_table.alert_table.name} WHERE alert_timestamp BETWEEN SNOWFLAKE.ALERT.LAST_SUCCESSFUL_SCHEDULED_TIME() AND SNOWFLAKE.ALERT.SCHEDULED_TIME()"

enabled = true
comment = "Slack Notification alert for new entries in the alert table"
}`
2. terraform apply

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

No response

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@NaveenAutomate NaveenAutomate added the bug Used to mark issues with provider's incorrect behavior label Oct 8, 2024
@sfc-gh-asawicki
Copy link
Collaborator

Hey @NaveenAutomate. Thanks for reaching out to us.

snowflake_alert is a resource that has not yet been reworked. However, some changes occurred between v0.92 and the current (v0.96) version.

  1. Please check if the problem is reproducible in v0.96.
  2. It seems that there is a problem with the identifier. What value does ${var.db_site} have? I am interested here in special characters, casing, etc.

@NaveenAutomate
Copy link
Author

@sfc-gh-asawicki
I cannot really upgrade to 0.96, looks like all the grant resources are removed from this version, we have too many of them and takes some time to use new resrouces

Regarding the ${var.db_site}, its just chars and upper case

@sfc-gh-asawicki
Copy link
Collaborator

I will try to reproduce this behavior this week. Just keep in mind, that in case of discovering a problem in the provider logic, the fix will come in the next minor version. We are not providing backward bug fixes for old minor versions because of the experimental state of the project.

@sfc-gh-asawicki
Copy link
Collaborator

Hey @NaveenAutomate. I tried to reproduce this error multiple ways and I haven't reached such an error.

Could you please provide a full minimal working sample with all the attributes filled out (i.e. without vars)?

sfc-gh-asawicki added a commit that referenced this issue Oct 10, 2024
- Prove #2679; documentation added, fix will be done with the stage
resource rework
- Try to prove #3117; could not reproduce the error, test left for now
@NaveenAutomate
Copy link
Author

NaveenAutomate commented Oct 10, 2024

This is the plan, just to give an idea on values

# module.snowflake_alerts.snowflake_alert.slack_alert will be created resource "snowflake_alert" "slack_alert" { action = "CALL SYSTEM$SEND_EMAIL(integration_name => 'EMAIL_INTEGRATION', recipients => ARRAY_CONSTRUCT('data-delivery-qa-aler-aaaaibwsrvrsdaz2o2ijzxfpbe@tenable.org.slack.com'), subject => 'Snowflake Alert Notification', content => 'New alerts have been logged in ALERTS_LOG table.');" comment = "Slack Notification alert for new entries in the alert table" condition = "SELECT * FROM TOOLS.STATS.ALERTS_LOG WHERE alert_timestamp BETWEEN SNOWFLAKE.ALERT.LAST_SUCCESSFUL_SCHEDULED_TIME() AND SNOWFLAKE.ALERT.SCHEDULED_TIME()" database = "TOOLS" enabled = true id = (known after apply) name = "all_slackEmailNotificationAlert" schema = "STATS" alert_schedule { interval = 1 } }

@sfc-gh-asawicki
Copy link
Collaborator

I still can't reproduce this with 0.96 or 0.92 versions. Please:

  1. Double-check if you are really using the 0.92 version of the provider.
  2. Run the plan+apply with TF_LOG=DEBUG environment variables and check the SQL statements that are run against Snowflake (I am interested in CREATE ALERT ... and SHOW ALERTS LIKE ...). Do not modify the name, schema, and database when pasting the output.
  3. I see that you are using underscore (the pasted plan) and not only chars. Underscore is a special character in SHOW (it's a wildcard). We had such problems in much earlier versions of the provider (e.g., two objects differed slightly, for example, prefix1 versus prefix_and SHOW output was not filtered on the provider side correctly, so the object found was a different object than anticipated, which resulted in similar errors). However, the alert resource is already immune to this problem (and I made sure by checking such a situation in v0.92). Nevertheless, you can try verifying what other alerts you have in that schema.
  4. Check if you have QUOTED_IDENTIFIERS_IGNORE_CASE set on ACCOUNT, DATABASE, or SCHEMA level. Having it set to true may cause the provider to misbehave if not used correctly (i.e. all identifiers in the configs have to be capitalized).
  5. Try reproducing the same error on your side with simplified config for action and condition (e.g. set the both to "select 0 as c"). Let's exclude the possibility of the problem lying there.

One more note: the initial config you pasted have name = upper("${var.db_site}SlackEmailNotificationAlert") and the plan output has name = "all_slackEmailNotificationAlert" (not uppercased), so it seems that these two are not parts of the same execution.

sfc-gh-asawicki added a commit that referenced this issue Oct 13, 2024
@NaveenAutomate
Copy link
Author

Hi @sfc-gh-asawicki ,

Thanks for the reply!

  1. I have validated we are using 0.92 version
  2. Partial Debug output for the commands

00 [DEBUG] provider.terraform-provider-snowflake_v0.92.0: 2024/10/13 22:52:18 [DEBUG] sql-conn-query: [query SELECT CURRENT_ACCOUNT() as CURRENT_ACCOUNT err duration 140.165583ms args {}] ()
2024-10-13T22:52:18.538+0100 [DEBUG] provider.terraform-provider-snowflake_v0.92.0: 2024/10/13 22:52:18 [DEBUG] sql-conn-query: [query SELECT CURRENT_SESSION() as CURRENT_SESSION err duration 384.819334ms args {}] ()
2024-10-13T22:52:18.538+0100 [DEBUG] provider.terraform-provider-snowflake_v0.92.0: 2024/10/13 22:52:18 [DEBUG] connection success! Account: , Session identifier: 531095852186894
module.snowflake_alerts.snowflake_alert.slack_alert: Creating...
2024-10-13T22:52:18.546+0100 [INFO] Starting apply for module.snowflake_alerts.snowflake_alert.slack_alert
2024-10-13T22:52:18.547+0100 [DEBUG] module.snowflake_alerts.snowflake_alert.slack_alert: applying the planned Create change
2024-10-13T22:52:18.755+0100 [DEBUG] provider.terraform-provider-snowflake_v0.92.0: 2024/10/13 22:52:18 [DEBUG] sql-conn-exec: [query CREATE ALERT "TOOLS"."STATS"."all_slackEmailNotificationAlert" SCHEDULE = '1 MINUTE' COMMENT = 'Slack Notification alert for new entries in the alert table' IF (EXISTS (SELECT * FROM TOOLS.STATS.ALERTS_LOG WHERE alert_timestamp BETWEEN SNOWFLAKE.ALERT.LAST_SUCCESSFUL_SCHEDULED_TIME() AND SNOWFLAKE.ALERT.SCHEDULED_TIME())) THEN CALL SYSTEM$SEND_EMAIL(integration_name => 'EMAIL_INTEGRATION', recipients => ARRAY_CONSTRUCT(''), subject => 'Snowflake Alert Notification', content => 'New alerts have been logged in ALERTS_LOG table.'); err duration 206.803292ms args {}] ()
2024-10-13T22:52:18.988+0100 [DEBUG] provider.terraform-provider-snowflake_v0.92.0: 2024/10/13 22:52:18 [DEBUG] sql-conn-exec: [query ALTER ALERT "TOOLS"."STATS"."all_slackEmailNotificationAlert" RESUME err duration 232.921417ms args {}] ()
2024-10-13T22:52:19.164+0100 [DEBUG] provider.terraform-provider-snowflake_v0.92.0: 2024/10/13 22:52:19 [DEBUG] sql-conn-query: [query SHOW ALERTS LIKE 'all_slackEmailNotificationAlert' IN SCHEMA "TOOLS"."STATS" err duration 175.638709ms args {}] ()
2024-10-13T22:52:19.164+0100 [DEBUG] provider.terraform-provider-snowflake_v0.92.0: 2024/10/13 22:52:19 [DEBUG] err: sql: Scan error on column index 6, name "warehouse": converting NULL to string is unsupported
2024-10-13T22:52:19.164+0100 [DEBUG] provider.terraform-provider-snowflake_v0.92.0: 2024/10/13 22:52:19 [DEBUG] alert (TOOLS|STATS|all_slackEmailNotificationAlert) not found

  1. The config and actual plan are different as the alert was created before, I have updated the name to try create again!
  2. The parameter QUOTED_IDENTIFIERS_IGNORE_CASE is set to false for account, database and schema
  3. even with this its the same issue
    While writing this I realized the error from the debug output, and warehouse value is null which is causing this issue!

After adding warehouse parameter it works fine now!

@sfc-gh-asawicki
Copy link
Collaborator

Great to hear! So we can close the issue?

@sfc-gh-asawicki sfc-gh-asawicki added general-usage General help/usage questions resource:alert Issue connected to the snowflake_alert resource category:resource and removed bug Used to mark issues with provider's incorrect behavior labels Oct 14, 2024
@NaveenAutomate
Copy link
Author

not sure if the null needs to be handled, but yea this can be closed!
Thanks for the support @sfc-gh-asawicki!

sfc-gh-asawicki added a commit that referenced this issue Oct 15, 2024
- Document two tests for #3117
- Bump acceptance tests build time
sfc-gh-jcieslak pushed a commit that referenced this issue Oct 22, 2024
- Document two tests for #3117
- Bump acceptance tests build time
sfc-gh-jmichalak pushed a commit that referenced this issue Nov 8, 2024
##
[0.98.0](v0.97.0...v0.98.0)
(2024-11-08)

Feature scope readiness for V1:
[link](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/v1-preparations/ESSENTIAL_GA_OBJECTS.MD)
([Roadmap
reference](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#wrap-up-the-functional-scope)).
:exclamation: Migration guide: [v0.97.0 ->
v0.98.0](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0970--v0980)

### 🎉 What's new
- New resources:
- authentication_policy
([#3098](#3098)),
references
[#2880](#2880)
- external_volume
([#3106](#3106)),
partially references
[#2980](#2980)
- stream_on_directory_table
([#3129](#3129))
- stream_on_view
([#3150](#3150))
- primary_connection, secondary_connection
([#3162](#3162))
- secret_with_basic_authentication, secret_with_generic_string,
secret_with_oauth_authorization_code_grant,
secret_with_oauth_client_credentials
([#3110](#3110)),
([#3141](#3141))
- New data sources:
- connections
([#3155](#3155)),
([#3173](#3173))
- secrets
([#3131](#3131))
- Reworked:
- provider configuration hierarchy
([#3166](#3166)),
references
[#1881](#1881),
[#2145](#2145),
[#2925](#2925),
[#2983](#2983),
[#3104](#3104)
- provider configuration fields
([#3152](#3152))
streams data source
([#3151](#3151))
- SDK upgrades:
- Upgrade tag SDK
([#3126](#3126))
- Recreate streams when they are stale
([#3129](#3129))
### 🔧  Misc
- Add object renaming research summary
([#3172](#3172))
- Test support for object renaming
([#3130](#3130)),
([#3147](#3147)),
([#3154](#3154))
- Add tests to issue
[#3117](#3117)
([#3133](#3133))
- New roadmap entry
([#3158](#3158))
- Test more authentication methods
([#3178](#3178))
- Minor fixes
([#3174](#3174))
### 🐛  Bug fixes
- Apply various fixes
([#3176](#3176)),
this addresses BCR 2024_08, references
[#2717](#2717),
[#3005](#3005),
[#3125](#3125),
[#3127](#3127),
[#3153](#3153)
- Connection and secret data sources tests
([#3177](#3177))
- Fix grant import docs
([#3183](#3183)),
resolves
[#3179](https://github.com/Snowflake-Labs/terraform-provider-snowflake/discussions/3179)
- Fix user resource import
([#3181](#3181))
- Handle external type changes in stream resources
([#3164](#3164))
- Do not use OR REPLACE on initial creation in resources with
copy_grants
([#3129](#3129))
- Address issue
[#2201](#2201)
by introducing new stream resources

Co-authored-by: snowflake-release-please[bot] <105954990+snowflake-release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:resource general-usage General help/usage questions resource:alert Issue connected to the snowflake_alert resource
Projects
None yet
Development

No branches or pull requests

2 participants