terraform-provider-snowflake
terraform-provider-snowflake copied to clipboard
Add support for tagging Snowflake Alert
Terraform CLI and Provider Versions
Provider: v0.87.1 CLI: 1.7.4
Use Cases or Problem Statement
I am trying to add tags to Snowflake Alerts to identify the environment in which they are running. However, I discovered that neither snowflake_alert nor snowflake_tag_association resources in the Terraform Snowflake Provider support tagging for Alerts.
Currently, the only workaround is to manage the tagging of Alerts using a method other than the Terraform Snowflake Provider, which is not ideal.
By adding support for tagging Alerts in the Terraform Snowflake Provider, it would greatly simplify the management and organization of Alerts across different environments, making it easier to identify and track Alerts based on their associated tags.
Proposal
To address this issue, I propose extending the snowflake_tag_association resource to support tagging for Snowflake Alerts. This would be the most straightforward and consistent approach, as snowflake_tag_association is already used for tagging other Snowflake resources.
By updating the snowflake_tag_association resource to include support for Alerts, users would be able to easily manage and organize their Alerts using tags within the Terraform Snowflake Provider. This would provide a native, integrated solution for tagging Alerts, eliminating the need to rely on external methods or workarounds.
Implementing this solution would involve updating the provider's codebase to accept Alerts as a supported resource type for the snowflake_tag_association resource, along with any necessary modifications to handle the tagging process for Alerts specifically.
How much impact is this issue causing?
Medium
Additional Information
No response
Hey @pei0804. Thanks for reaching out to us.
This is a good suggestion. We are in the process of redesigning the existing resources and adding the missing functionalities as part of https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#supporting-all-snowflake-ga-features). We will address it then.
For the time being, you can also use the https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/unsafe_execute resource. This is a dangerous resource, though. Please make sure to read the docs and familiarize yourself with the resource's limitations before using it.
I implemented the code as follows and it worked successfully:
locals {
database_name = "my_database"
schema_name = "my_schema"
}
resource "snowflake_alert" "this" {
...
}
resource "snowflake_unsafe_execute" "production_environment_tag_association" {
count = var.is_production_environment ? 1 : 0
execute = "ALTER ALERT ${local.database_name}.${local.schema_name}.${snowflake_alert.this.name} SET TAG SAMPLE_DATABASE.TAG.ENVIRONMENT = 'prod'"
revert = "ALTER ALERT ${local.database_name}.${local.schema_name}.${snowflake_alert.this.name} UNSET TAG SAMPLE_DATABASE.TAG.ENVIRONMENT"
depends_on = [ snowflake_alert.this ]
}