Snowflake-Labs / terraform-provider-snowflake

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

[Bug]: migrating snowflake_user to snowflake_service_user forces recreation #3216

Open jrobison-sb opened 10 hours ago

jrobison-sb commented 10 hours ago

Terraform CLI Version

v1.9.1

Terraform Provider Version

v0.98.0

Company Name

No response

Terraform Configuration

resource "snowflake_user" "old" {
  ...
}

resource "snowflake_service_user" "new" {
  ...
}

Category

category:import

Object type(s)

resource:user

Expected Behavior

I should be able to migrate the old way of using snowflake_user to the new way of using snowflake_service_user by way of terraform state rm && terraform import, and the end result should be 0 terraform plan diffs, 0 resource recreations, and 0 effect on the deployed resources. The only changes should be entirely within the HCL and the terraform state.

Actual Behavior

  # snowflake_service_user.new must be replaced
-/+ resource "snowflake_service_user" "new" {
      + user_type                                     = "<changed externally>" # forces replacement
        ...
}

Steps to Reproduce

  1. Use HCL similar to what is seen above.
  2. terraform state rm the old resource to delete it from the state to start the migration
  3. terraform import the new resource to import it into state to finish the migration
  4. terraform plan to see the diffs and see that your new resource will be re-created, defeating the purpose of the migration.

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

I see the same behavior when migration from snowflake_user to snowflake_legacy_service_user too.

Using jq to inspect my state file from prior to this migration, I see "user_type": "" as one of the attributes.

https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/3119

Would you like to implement a fix?