# Upgrading to 5.0.0

## Database Module

* First upgrade the module to the latest 4.x version (4.13.1) and pin the Snowflake provider to 0.92.0. Update the Terraform version as well if not already on the latest.
* Run the [migration script](upgrade_v5.py) to generate an `imports.tf` and `removed.tf` file for the migration.
* Upgrade the module to 5.0.0, leaving the Snowflake provider at version 0.92.0.
  * If `enable_account_roles` is not set, explicitly set it to `true`.
  * If `enable_database_roles` is not set, explicitly set it to `false`. This can always be changed later to create database roles, but will minimise the number of resources changed as part of the upgrade.
  * If successful, the plan should show the following:
    * `58x + 33` to add and to destroy, where `x` is the number of schemas.
    * `62x + 39` imports, where `x` is the number of schemas.

## Warehouse Module

Follow the same steps as the database module.

## Service User Module

* Update the module version to 5.0.1.
* Pin the Snowflake provider to version 0.92.0 and update the Terraform version to the latest.
* Remove any existing `imports.tf` file
* Create a new `imports.tf` file and add the following imports:
  ```hcl
  import {
    for_each = module.service_user.granted_account_roles
  
    to = module.service_user.snowflake_grant_account_role.account_roles[each.value]
    id = "\"${each.value}\"|ROLE|\"${module.service_user.service_role}\""
  }
  
  import {
    to = module.service_user.snowflake_grant_account_role.grant_service_user_role_to_roles
    id = "\"${module.service_user.service_role}\"|ROLE|\"SYSADMIN\""
  }
  
  import {
    to = module.service_user.snowflake_grant_account_role.grant_service_user_role_to_users
    id = "\"${module.service_user.service_role}\"|USER|\"${module.service_user.service_user}\""
  }
  
  import {
    to = module.service_user.snowflake_grant_ownership.service_user_role_ownership_grant
    id = "ToAccountRole|USERADMIN|COPY|OnObject|ROLE|${module.service_user.service_role}"
  }
  import {
    to = module.service_user.snowflake_grant_ownership.service_user_user_ownership_grant
    id = "ToAccountRole|USERADMIN|COPY|OnObject|USER|${module.service_user.service_user}"
  }
  ```
* If done correctly, the plan should show only imports and no changes.
