Because the resource addresses for IAM accounts changed in version 15.0.0 (from using the email string to using the new id string), you must migrate your existing Terraform state to avoid resource destruction and recreation.
Option 1: Using moved blocks (Recommended)
Add moved blocks to your Terraform configuration to explicitly migrate the state. This is the safest and most declarative method.
Option 2: Using terraform state mv
If you prefer manual migration, use the terraform state mv command. First, identify the current state addresses using:
terraform state list | grep google_sql_user.iam_account
Then, move the resources manually. For example:
terraform state mv \
'module.pg.google_sql_user.iam_account["test-sa@$my-project-id.iam.gserviceaccount.com true"]' \
'module.pg.google_sql_user.iam_account["test-sa"]'
# Example moved blocks for SQL DB 15.0.0 migration
moved {
from = module.pg.google_sql_user.iam_account["test-sa@${var.project_id}.iam.gserviceaccount.com true"]
to = module.pg.google_sql_user.iam_account["test-sa"]
}
moved {
from = module.pg.google_sql_user.iam_account["john.doe@gmail.com false"]
to = module.pg.google_sql_user.iam_account["john.doe"]
}