Snowflake-Labs / terraform-provider-snowflake

Terraform provider for managing Snowflake accounts
https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest
MIT License
554 stars 422 forks source link

[Bug]: snowflake_tag_association failed to associate tag to schema #3235

Open harukitake opened 4 days ago

harukitake commented 4 days ago

Terraform CLI Version

1.9.5

Terraform Provider Version

0.99.0

Company Name

No response

Terraform Configuration

resource "snowflake_tag_association" "schema" {
  object_identifier {
    database = "database_name"
    name     = "schema_name"
  }
  object_type = "schema"
  tag_id      = "tag_id"
  tag_value   = "tag_value"
}

Category

category:resource

Object type(s)

No response

Expected Behavior

successful plan and apply

Actual Behavior

Error: tagging for object type schema is not supported

Steps to Reproduce

  1. Replace "database_name", "schema_name", "tag_id", and "tag_value" with actual existing values in your Snowflake account.
  2. plan

How much impact is this issue causing?

High

Logs

No response

Additional Information

No response

Would you like to implement a fix?

sfc-gh-jmichalak commented 4 days ago

Hi @harukitake 👋

Please use uppercase type "SCHEMA" for now. We'll make the object types case insensitive.

harukitake commented 4 days ago

Hi @sfc-gh-jmichalak . It fails if I use uppercase type "SCHEMA". It works well until v0.96.0, but after upgrading to v0.99.0 it has failed with the above error.

sfc-gh-jmichalak commented 4 days ago

Could you provide provider logs with TF_LOG=DEBUG?

harukitake commented 4 days ago
Log

```tf 2024-11-28T18:28:41.389+0900 [DEBUG] provider.terraform-provider-snowflake_v0.99.0: 2024/11/28 18:28:41 [DEBUG] sql-conn-query: [query SELECT CURRENT_ACCOUNT() as CURRENT_ACCOUNT err duration 70.869541ms args {}] () 2024-11-28T18:28:41.445+0900 [DEBUG] provider.terraform-provider-snowflake_v0.99.0: 2024/11/28 18:28:41 [DEBUG] sql-conn-query: [query SELECT CURRENT_SESSION() as CURRENT_SESSION err duration 56.130792ms args {}] (MV33919) 2024-11-28T18:28:41.445+0900 [DEBUG] provider.terraform-provider-snowflake_v0.99.0: 2024/11/28 18:28:41 [DEBUG] connection success! 2024-11-28T18:28:41.445+0900 [DEBUG] ReferenceTransformer: "snowflake_tag_association.schema_fivetran_log" references: [] 2024-11-28T18:28:41.446+0900 [DEBUG] ReferenceTransformer: "snowflake_tag_association.schema_github_zucks" references: [] snowflake_tag_association.schema_fivetran_log: Refreshing state... [id=VISION_MINDSTONE|TAG|OWNER] snowflake_tag_association.schema_github_zucks: Refreshing state... [id=VISION_MINDSTONE|TAG|OWNER] 2024-11-28T18:28:41.448+0900 [ERROR] provider.terraform-provider-snowflake_v0.99.0: Response contains error diagnostic: @module=sdk.proto diagnostic_severity=ERROR diagnostic_summary="tagging for object type schema is not supported" diagnostic_detail="" tf_proto_version=6.4 tf_provider_addr=registry.terraform.io/Snowflake-Labs/snowflake tf_req_id=269e8f43-33e7-e8e0-69fa-8678030c3e37 @caller=github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/internal/diag/diagnostics.go:58 tf_resource_type=snowflake_tag_association tf_rpc=ReadResource timestamp="2024-11-28T18:28:41.448+0900" 2024-11-28T18:28:41.448+0900 [ERROR] provider.terraform-provider-snowflake_v0.99.0: Response contains error diagnostic: @caller=github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/internal/diag/diagnostics.go:58 @module=sdk.proto diagnostic_severity=ERROR diagnostic_summary="tagging for object type schema is not supported" diagnostic_detail="" tf_proto_version=6.4 tf_provider_addr=registry.terraform.io/Snowflake-Labs/snowflake tf_req_id=1df529a7-9d67-4d25-2817-a40aa3db1de7 tf_resource_type=snowflake_tag_association tf_rpc=ReadResource timestamp="2024-11-28T18:28:41.448+0900" 2024-11-28T18:28:41.448+0900 [ERROR] vertex "snowflake_tag_association.schema_fivetran_log" error: tagging for object type schema is not supported 2024-11-28T18:28:41.448+0900 [ERROR] vertex "snowflake_tag_association.schema_github_zucks" error: tagging for object type schema is not supported 2024-11-28T18:28:41.448+0900 [ERROR] vertex "snowflake_tag_association.schema_fivetran_log (expand)" error: tagging for object type schema is not supported 2024-11-28T18:28:41.448+0900 [ERROR] vertex "snowflake_tag_association.schema_github_zucks (expand)" error: tagging for object type schema is not supported 2024-11-28T18:28:41.448+0900 [WARN] Planning encountered errors, so plan is not applyable 2024-11-28T18:28:41.448+0900 [INFO] backend/local: plan operation completed Planning failed. Terraform encountered an error while generating this plan. ╷ │ Warning: Argument is deprecated │ │ with provider["registry.terraform.io/snowflake-labs/snowflake"], │ on provider.tf line 17, in provider "snowflake": │ 17: provider "snowflake" { │ │ Use `account_name` and `organization_name` instead of `account` ╵ ╷ │ Error: tagging for object type schema is not supported │ │ with snowflake_tag_association.schema_fivetran_log, │ on schema_tagging.tf line 2, in resource "snowflake_tag_association" "schema_fivetran_log": │ 2: resource "snowflake_tag_association" "schema_fivetran_log" { │ ╵ ╷ │ Error: tagging for object type schema is not supported │ │ with snowflake_tag_association.schema_github_zucks, │ on schema_tagging.tf line 13, in resource "snowflake_tag_association" "schema_github_zucks": │ 13: resource "snowflake_tag_association" "schema_github_zucks" { │ ╵ ```

sfc-gh-jmichalak commented 4 days ago

I can't reproduce the issue for "SCHEMA". From your logs, it looks like "schema" is still in the configuration.

harukitake commented 3 days ago

@sfc-gh-jmichalak This state was created with v0.96.0. It might be the cause of the issue.

{
  "version": 4,
  "terraform_version": "1.7.5",
  "serial": 3,
  "lineage": "65303413-352e-8c89-d724-e86bb1ffc396",
  "outputs": {},
  "resources": [
    {
      "mode": "data",
      "type": "terraform_remote_state",
      "name": "vision_mindstone",
      "provider": "provider[\"terraform.io/builtin/terraform\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "backend": "s3",
            "config": {
              "value": {
                "bucket": "bucket",
                "key": "/terraform.tfstate"
              },
              "type": [
                "object",
                {
                  "bucket": "string",
                  "key": "string"
                }
              ]
            },
            "defaults": null,
            "outputs": {
              "value": {
                "cost_tag_id": "VISION_MINDSTONE|TAG|OWNER"
              },
              "type": [
                "object",
                {
                  "cost_tag_id": "string"
                }
              ]
            },
            "workspace": null
          },
          "sensitive_attributes": []
        }
      ]
    },
    {
      "mode": "managed",
      "type": "snowflake_tag_association",
      "name": "schema_fivetran_log",
      "provider": "provider[\"registry.terraform.io/snowflake-labs/snowflake\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "VISION_MINDSTONE|TAG|OWNER",
            "object_identifier": [
              {
                "database": "RAW",
                "name": "FIVETRAN_LOG",
                "schema": ""
              }
            ],
            "object_name": null,
            "object_type": "schema",
            "skip_validation": true,
            "tag_id": "VISION_MINDSTONE|TAG|OWNER",
            "tag_value": "aaaaa",
            "timeouts": null
          },
          "sensitive_attributes": [],
          "dependencies": [
            "data.terraform_remote_state.vision_mindstone"
          ]
        }
      ]
    },
    {
      "mode": "managed",
      "type": "snowflake_tag_association",
      "name": "schema_github_zucks",
      "provider": "provider[\"registry.terraform.io/snowflake-labs/snowflake\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "VISION_MINDSTONE|TAG|OWNER",
            "object_identifier": [
              {
                "database": "RAW",
                "name": "GITHUB_ZUCKS",
                "schema": ""
              }
            ],
            "object_name": null,
            "object_type": "schema",
            "skip_validation": true,
            "tag_id": "VISION_MINDSTONE|TAG|OWNER",
            "tag_value": "@g_vision_developers",
            "timeouts": null
          },
          "sensitive_attributes": [],
          "dependencies": [
            "data.terraform_remote_state.vision_mindstone"
          ]
        }
      ]
    }
  ],
  "check_results": null
}
harukitake commented 3 days ago

I will try the following step.

  1. fix "schema" -> "SCHEMA" with v0.96.0
  2. upgrade to v0.99.0
  3. plan
harukitake commented 3 days ago
  # snowflake_tag_association.schema_zucks_vision_sandbox_snowpipe must be replaced
-/+ resource "snowflake_tag_association" "schema_zucks_vision_sandbox_snowpipe" {
      ~ id              = "VISION_MINDSTONE|TAG|OWNER" -> (known after apply)
      ~ object_type     = "schema" -> "SCHEMA" # forces replacement
        # (3 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

I fixed "schema" -> "SCHEMA" with v0.96.0 and upgraded to v0.99.0. The plan was successful.