petoju / terraform-provider-mysql

Terraform MySQL provider – unofficial fork
https://registry.terraform.io/providers/petoju/mysql
Mozilla Public License 2.0
73 stars 48 forks source link

How to migrate from terraform-provider-mysql to this provider. #24

Closed kaykhan closed 1 year ago

kaykhan commented 2 years ago

HI friends ive been using https://github.com/hashicorp/terraform-provider-mysql to create mysql users in my aws rds mysql database.

That provider is no longer available and i can see this is a fork on that provider. How do i migrate to this provider ( im fairly new to terraform)

versions.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
    mysql = {
      source  = "terraform-providers/mysql"
      version = ">= 1.9.0"
    }
  }
}

users.tf

I then hae a bunch of resources like this...

provider "mysql" {
  endpoint = aws_db_instance.master.endpoint
  username = aws_db_instance.master.username
  password = var.root_password
}

resource "mysql_user" "some_user" {
  user               = "some_user"
  plaintext_password = "some_password!"
  host               = "%"
}

resource "mysql_grant" "some_user" {
  user       = mysql_user.some_user.user
  host       = mysql_user.some_user.host
  database   = "%"
  privileges = ["ALL"]
}

Is it possible to migrate over without affecting the users in the mysql database.

petoju commented 2 years ago

@kaykhan it should be possible to just replace provider: https://www.terraform.io/cli/commands/state/replace-provider like terraform state replace-provider terraform-providers/mysql petoju/mysql

However, I don't and cannot guarantee you it will work without affecting any user. That's because this provider has a bit better state refresh and it may find and try to fix some issues. Also, this provider has deprecated some variables.

So the recommended way to replace provider would be:

  1. Take a backup of your state.
  2. terraform state replace-provider
  3. Check terraform plan for any changes. Any change could affect the users, so you should check, how they look like.