|
| 1 | +# Region Migration Guide |
| 2 | +For cost saving reasons, you can migrate the Concourse deployment to a different region. This guide will help you restore the Concourse deployment in a new region using the existing configuration. |
| 3 | + |
| 4 | +## Prerequisites |
| 5 | +- Access to the GCP account and the GKE cluster in the current region. |
| 6 | +- "pg_dump" v16 is installed on the local machine. |
| 7 | + |
| 8 | +## Backup Secrets and Databases |
| 9 | +1. Logon to the GCP account and the GKE cluster in the current region. |
| 10 | +1. In the GCP Secret Manager, retrieve and save the following credentials as a backup: |
| 11 | + - `wg-ci[-test]-credhub-encryption-key` |
| 12 | + - `wg-ci[-test]-concourse-github-oauth` |
| 13 | + |
| 14 | + You can also use the following command to retrieve the secrets: |
| 15 | + ```bash |
| 16 | + gcloud secrets versions access latest --secret=<secret-name> |
| 17 | + ``` |
| 18 | +1. Install and start the Cloud SQL Auth Proxy as documented here: https://cloud.google.com/sql/docs/postgres/connect-instance-auth-proxy |
| 19 | +1. The "concourse" database which contains the pipelines must be backed up. Retrieve the password: |
| 20 | + ```bash |
| 21 | + kubectl -n concourse get secret concourse-postgresql-password -o yaml | yq -r .data.password | base64 -d |
| 22 | + ``` |
| 23 | +1. Dump the database content using the `pg_dump` command: |
| 24 | + ```bash |
| 25 | + pg_dump "postgresql://concourse@localhost:5432/concourse" > "concourse_backup.sql" |
| 26 | + ``` |
| 27 | +1. The "credhub" database is encrypted with a key. Migration of the encryption key is not easily possible because upon re-creation, a new key is automatically generated and applied. So we use the CredHub CLI to export the CredHub data. Log on to CredHub with the [start-credhub-cli.sh](../../terragrunt/scripts/concourse/start-credhub-cli.sh) script. Then export all data: |
| 28 | + ```bash |
| 29 | + credhub export --output-file=credhub_backup.json |
| 30 | + ``` |
| 31 | + Copy the file from the pod to the local machine: |
| 32 | + ```bash |
| 33 | + kubectl -n concourse cp credhub-cli-<id>:/credhub_backup.json credhub_backup.json |
| 34 | + ``` |
| 35 | + :warning: The file `credhub_backup.json` contains sensitive data in plaintext, so handle it with care and delete it after the migration. |
| 36 | + |
| 37 | +## Destroy the Current Concourse Deployment |
| 38 | +1. Open file `terraform-modules/concourse/dr_create/credhub_encryption_key.tf`. |
| 39 | +1.1 In resource "google_secret_manager_secret_version", comment the "lifecycle" block (to disable `prevent_destroy = true`). |
| 40 | +1.1 Comment module "assertion_encryption_key_identical" (if you receive `Error: Unsupported OpenTofu Core version`). |
| 41 | +1. In `terraform-modules/concourse/infra/database.tf`, set `deletion_protection` and `deletion_protection_enabled` to `false`. |
| 42 | +1. In `terraform-modules/concourse/infra/gke_cluster.tf` add `deletion_protection = false` (the default is `true`). |
| 43 | +1. Go to folder `terragrunt/concourse-wg-ci[-test]/infra` and run `terragrunt apply`. This updates the deletion protection settings for the Cloud SQL database and the GKE cluster. |
| 44 | +1. Go to folder `terragrunt/concourse-wg-ci[-test]`. Run `terragrunt run-all plan -destroy` to see what will be destroyed. |
| 45 | +1. If there were no errors, run `terragrunt run-all destroy` to destroy the Concourse deployment in the current region. |
| 46 | + |
| 47 | +## Recreate the Concourse Deployment |
| 48 | +1. In the `config.yaml`, change the project's region and zones. Example for `us-east1`: |
| 49 | + ```yaml |
| 50 | + region: us-east1 |
| 51 | + zone: us-east1-b |
| 52 | + secondary_zone: us-east1-c |
| 53 | + ``` |
| 54 | +1. Check the Postgres version in the [Concourse Helm chart](https://github.com/concourse/concourse-chart/blob/master/Chart.yaml). If the database version must be updated, change the `database_version` value: |
| 55 | + ```yaml |
| 56 | + database_version: "POSTGRES_16" |
| 57 | + ``` |
| 58 | +1. Check the [GKE release notes](https://cloud.google.com/kubernetes-engine/docs/release-notes) for the latest supported version. If the GKE version must be updated, change the `gke_version` value: |
| 59 | + ```yaml |
| 60 | + gke_controlplane_version: "1.31" |
| 61 | + ``` |
| 62 | +1. Now you can check the Terraform plan: |
| 63 | + ```bash |
| 64 | + terragrunt run-all plan |
| 65 | + ``` |
| 66 | +1. If you see `Error: Unsupported OpenTofu Core version`, comment module "assertion_encryption_key_identical". |
| 67 | +1. If there are no errors, apply the changes: |
| 68 | + ```bash |
| 69 | + terragrunt run-all apply |
| 70 | + ``` |
| 71 | +1. To make the "e2e_test" pass, you must log on with the fly CLI and run the "apply" step again: |
| 72 | + ```bash |
| 73 | + fly -t wg-ci-test login -c https://concourse-test.app-runtime-interfaces.ci.cloudfoundry.org |
| 74 | + ``` |
| 75 | +1. Log on to CredHub with the [start-credhub-cli.sh](../../terragrunt/scripts/concourse/start-credhub-cli.sh) script. Copy the credential backup file from to the pod: |
| 76 | + ```bash |
| 77 | + kubectl -n concourse cp credhub_backup.json credhub-cli-<id>:/credhub_backup.json |
| 78 | + ``` |
| 79 | + Then import all data: |
| 80 | + ```bash |
| 81 | + credhub import -j -f credhub_backup.json |
| 82 | + ``` |
| 83 | +1. Restart the Cloud SQL Auth Proxy with the new "Connection name". |
| 84 | +1. Restore the Concourse database from the backup: |
| 85 | + ```bash |
| 86 | + psql -h 127.0.0.1 -p 5432 -U concourse -d concourse -f concourse_backup.sql |
| 87 | + ``` |
0 commit comments