Snowflake-Labs / terraform-provider-snowflake

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

[General Usage]: Migrate `snowflake_role` to `snowflake_account_role` #3037

Open myshon opened 2 weeks ago

myshon commented 2 weeks ago

Terraform CLI Version

1.8.5

Terraform Provider Version

0.94.1

Terraform Configuration

resource "snowflake_role" "rag_ingestion" {
  name = local.snowflake.role
}

resource "snowflake_account_role" "rag_ingestion" {
  name = local.snowflake.role
}

import {
  id = snowflake_role.rag_ingestion.id
  to = snowflake_account_role.rag_ingestion
}

Category

category:resource

Object type(s)

No response

Expected Behavior

Migration snowflake_role -> snowflake_account_role without DROP ROLE. I would like to avoid state manipulation using CLI.

Actual Behavior

Removing resource snowflake_role caused resource destroy and drop role.

{"@level":"info","@message":"snowflake_role.rag_ingestion: Destroying... [id=rag_ingestion]","@module":"terraform.ui","@timestamp":"2024-09-03T10:09:48.561785Z","hook":{"resource":{"addr":"snowflake_role.rag_ingestion","module":"","resource":"snowflake_role.rag_ingestion","implied_provider":"snowflake","resource_type":"snowflake_role","resource_name":"rag_ingestion","resource_key":null},"action":"delete","id_key":"id","id_value":"rag_ingestion"},"type":"apply_start"}
{"@level":"info","@message":"snowflake_role.rag_ingestion: Destruction complete after 0s","@module":"terraform.ui","@timestamp":"2024-09-03T10:09:49.449801Z","hook":{"resource":{"addr":"snowflake_role.rag_ingestion","module":"","resource":"snowflake_role.rag_ingestion","implied_provider":"snowflake","resource_type":"snowflake_role","resource_name":"rag_ingestion","resource_key":null},"action":"delete","elapsed_seconds":0},"type":"apply_complete"}

Steps to Reproduce

I've used snowflake role resource

resource "snowflake_role" "rag_ingestion" {
  name = local.snowflake.role
}

After updating to 0.94.x resource has been deprecated in favor of snowflake_account_role. Therefore, I added new resource with proper import.

resource "snowflake_role" "rag_ingestion" {
  name = local.snowflake.role
}

resource "snowflake_account_role" "rag_ingestion" {
  name = local.snowflake.role
}

import {
  id = snowflake_role.rag_ingestion.id
  to = snowflake_account_role.rag_ingestion
}

Resource has been imported correctly.

{"@level":"info","@message":"Apply complete! Resources: 1 imported, 0 added, 1 changed, 0 destroyed.","@module":"terraform.ui","@timestamp":"2024-09-02T07:18:52.956116Z","changes":{"add":0,"change":1,"import":1,"remove":0,"operation":"apply"},"type":"change_summary"}

In the next run, I tried to remove deprecated resources along with import statement. It ended with

resource "snowflake_account_role" "rag_ingestion" {
  name = local.snowflake.role
}

However, removing resource snowflake_role caused resource destroy and drop role.

{"@level":"info","@message":"snowflake_role.rag_ingestion: Destroying... [id=rag_ingestion]","@module":"terraform.ui","@timestamp":"2024-09-03T10:09:48.561785Z","hook":{"resource":{"addr":"snowflake_role.rag_ingestion","module":"","resource":"snowflake_role.rag_ingestion","implied_provider":"snowflake","resource_type":"snowflake_role","resource_name":"rag_ingestion","resource_key":null},"action":"delete","id_key":"id","id_value":"rag_ingestion"},"type":"apply_start"}
{"@level":"info","@message":"snowflake_role.rag_ingestion: Destruction complete after 0s","@module":"terraform.ui","@timestamp":"2024-09-03T10:09:49.449801Z","hook":{"resource":{"addr":"snowflake_role.rag_ingestion","module":"","resource":"snowflake_role.rag_ingestion","implied_provider":"snowflake","resource_type":"snowflake_role","resource_name":"rag_ingestion","resource_key":null},"action":"delete","elapsed_seconds":0},"type":"apply_complete"}

How to migrate snowflake_role -> snowflake_account_role without DROP ROLE? I would like to avoid state manipulation using CLI.

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

No response

sfc-gh-asawicki commented 2 weeks ago

Hey @myshon. Thanks for reaching out to us.

If you don't want to use terraform rm as described in our resource migration guide, you can use the equivalent: removed block (https://developer.hashicorp.com/terraform/language/resources/syntax#removing-resources).