|
| 1 | +# Upgrading to SQL DB 15.0.0 |
| 2 | + |
| 3 | +The 15.0.0 release of SQL DB is a backward incompatible release. |
| 4 | +This incompatibility affects `postgresql` submodule that uses IAM authentication. |
| 5 | + |
| 6 | +## Migration Instructions |
| 7 | + |
| 8 | +### `iam_user_emails` moved to `iam_users` and changed to be an list(object) |
| 9 | + |
| 10 | +Prior to the `15.0.0` release, the `postgresql` submodule took a `list(string)` for `iam_user_emails`. |
| 11 | + |
| 12 | +This meant that it was not possible to create a `google_service_account` and corresponding `google_sql_user` |
| 13 | +in a single `terraform apply` because the `email` is `(known after apply)` and was used in the resource address. |
| 14 | +See [issue 413](https://github.com/terraform-google-modules/terraform-google-sql-db/issues/413) for more details. |
| 15 | + |
| 16 | +In the `15.0.0` release, the input/output variable has been renamed from `iam_user_emails` to `iam_users`, and |
| 17 | +now accepts a `list(object({id=string, email=string}))`, where `id` is used in the resource address. |
| 18 | + |
| 19 | +This allows a value that is known at `plan` time to be passed, for example `google_service_account.my_service_account.account_id` |
| 20 | +would be a good candidate for this. |
| 21 | + |
| 22 | +```diff |
| 23 | +module "pg" { |
| 24 | + source = "GoogleCloudPlatform/sql-db/google//modules/postgresql" |
| 25 | + - version = "~> 14.0" |
| 26 | + + version = "~> 15.0" |
| 27 | + |
| 28 | +name = "test" |
| 29 | +database_version = "POSTGRES_14" |
| 30 | +project_id = var.project_id |
| 31 | +zone = "europe-west1-b" |
| 32 | +region = "europe-west1" |
| 33 | +tier = "db-custom-1-3840" |
| 34 | + |
| 35 | +database_flags = [ |
| 36 | + { |
| 37 | + name = "cloudsql.iam_authentication" |
| 38 | + value = "on" |
| 39 | + } |
| 40 | +] |
| 41 | + |
| 42 | +- iam_user_emails = [ |
| 43 | +- "test-sa@${var.project_id}.iam.gserviceaccount.com", |
| 44 | + |
| 45 | +- ] |
| 46 | ++ iam_users = [ |
| 47 | ++ { |
| 48 | ++ id = "test-sa", |
| 49 | ++ email = "test-sa@${var.project_id}.iam.gserviceaccount.com", |
| 50 | ++ }, |
| 51 | ++ { |
| 52 | ++ id = "john.doe", |
| 53 | + |
| 54 | ++ }, |
| 55 | ++ ] |
| 56 | +} |
| 57 | + |
| 58 | ++ moved { |
| 59 | ++ from = module.pg.google_sql_user.iam_account["test-sa@${var.project_id}.iam.gserviceaccount.com true"] |
| 60 | ++ to = module.pg.google_sql_user.iam_account["test-sa"] |
| 61 | ++ } |
| 62 | + |
| 63 | ++ moved { |
| 64 | ++ from = module.pg.google_sql_user.iam_account["[email protected] false"] |
| 65 | ++ to = module.pg.google_sql_user.iam_account["john.doe"] |
| 66 | ++ } |
| 67 | + |
| 68 | +``` |
| 69 | + |
| 70 | +We recommend using `moved` blocks as [documented here](https://developer.hashicorp.com/terraform/language/modules/develop/refactoring) |
| 71 | +to explicitly migrate your state. You can find the list of state addresses to move using: |
| 72 | + |
| 73 | +```shell |
| 74 | +terraform state list | grep google_sql_user.iam_account |
| 75 | +``` |
| 76 | + |
| 77 | +If you do not wish to use `moved` blocks, you can instead migrate your state using `terraform state mv`: |
| 78 | +```shell |
| 79 | +terraform state mv \ |
| 80 | + 'module.pg.google_sql_user.iam_account["test-sa@$my-project-id.iam.gserviceaccount.com true"]' \ |
| 81 | + 'module.pg.google_sql_user.iam_account["test-sa"]' |
| 82 | +``` |
0 commit comments