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]: snowflake_tag_association failed to associate tag to schema #3235

Closed
1 task
harukitake opened this issue Nov 28, 2024 · 11 comments
Closed
1 task

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

harukitake opened this issue Nov 28, 2024 · 11 comments
Assignees
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@harukitake
Copy link

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?

  • Yeah, I'll take it 😎
@harukitake harukitake added the bug Used to mark issues with provider's incorrect behavior label Nov 28, 2024
@sfc-gh-jmichalak
Copy link
Collaborator

Hi @harukitake 👋

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

@harukitake
Copy link
Author

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
Copy link
Collaborator

Could you provide provider logs with TF_LOG=DEBUG?

@harukitake
Copy link
Author

Log

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 <nil> 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 <nil> 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
Copy link
Collaborator

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

@harukitake
Copy link
Author

@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
Copy link
Author

I will try the following step.

  1. fix "schema" -> "SCHEMA" with v0.96.0
  2. upgrade to v0.99.0
  3. plan

@harukitake
Copy link
Author

  # 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.

@harukitake harukitake changed the title [Bug]: snowfalke_tag_association failed to associate tag to schema [Bug]: snowflake_tag_association failed to associate tag to schema Dec 2, 2024
sfc-gh-jmichalak added a commit that referenced this issue Dec 5, 2024
<!-- Feel free to delete comments as you fill this in -->
- rework `tag_association` resource
- return `nil` from GetTag instead of failing
- add more tests regarding tag/masking policy: assert that `ALTER
MASKING POLICY SET TAG` differs from `ALTER TAG SET MASKING POLICY`
- support tagging account for identifiers with org name
- support `IF EXISTS` for unsetting tags
- add notes about manually unassigning policies from objects, add a todo
with an issue number
- fix a wrong issue number in essential objects list
<!-- summary of changes -->

## Test Plan
<!-- detail ways in which this PR has been tested or needs to be tested
-->
* [x] acceptance tests
<!-- add more below if you think they are relevant -->
* [ ] …

## References
<!-- issues documentation links, etc  -->
https://docs.snowflake.com/en/user-guide/object-tagging
https://docs.snowflake.com/en/sql-reference/functions/system_get_tag
#3145 
#1910 
#2943
#3235

## TODO
- use generated config and asserts, remove old test `tf` files

## Ideas
- extract a separate resource for tagging accounts?
@sfc-gh-jmichalak sfc-gh-jmichalak self-assigned this Dec 9, 2024
@sfc-gh-jmichalak
Copy link
Collaborator

Hi @harukitake 👋

We've just released v0.100.0 (release, migration guide) in which we support lowercase object types. Please upgrade to this version and let us know if you have any issues.

@harukitake
Copy link
Author

@sfc-gh-jmichalak
Thanks.
It works good in my environment.

@sfc-gh-asawicki
Copy link
Collaborator

Great! Closing then.

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
Projects
None yet
Development

No branches or pull requests

3 participants