diff --git a/runbooks/source/move-components-module.html.md.erb b/runbooks/source/move-components-module.html.md.erb index ddd15ca7..e371ff01 100644 --- a/runbooks/source/move-components-module.html.md.erb +++ b/runbooks/source/move-components-module.html.md.erb @@ -7,58 +7,19 @@ review_in: 6 months # Moving `components` modules into `core` -## Step 1 - Migrating resources - -Pause pipelines. - -Move the module from `core/components.tf` into it's own file e.g. `gatekeeper.tf` in `core`. - -Remove any dependencies from `core/components.tf` - -Run `terraform plan -out=$dir.tfplan` on both `core` and `components` there should be the same number of resources being removed as applied. - -Commit the changes and create a pull request. - -## Step 2 - Get state - -Get a list of all resources being added in `core` - -``` -terraform show -no-color -json core.tfplan | jq -r '.resource_changes[] | select(.change.actions[0]=="update" or .change.actions[0]=="create" or .change.actions[0]=="create") | .address' -``` -[Source](https://www.reddit.com/r/Terraform/comments/10m7jdd/comment/jjcihv4/) - -Pull `core` and `components` terraform state: - -``` -terraform state pull > $dir.tfstate -``` - -Create a copy of each tfstate file as a backup in case something goes wrong. - -Copy each resource state block from `components.tfstate` into `core.tfstate`. - -## Step 3 - Core - -Run `terraform state push -force core.tfstate` this will overwrite the remote state file with our updated state with the additional resources from components. - -Run `terraform plan` this should show no changes. - -## Step 4 - Components - -Once cores state has been updated with the new state file we need to remove the duplicated resources in components. - -``` -terraform state rm $resource -``` - -Do this for each resource from step 2. - -Run `terraform plan` and confirm there are no changes. - -## Step 4 - Cleanup - -Unpause the pipelines there should be no changes. +1. Raise PR with migrated module +2. Update #cloud-platform informing the team about the module migration and to not make new PRs against `cloud-platform-infrastructure`. +3. Pause pipelines +3. Update pipelines with module name and cluster name: + `fly -t moj-cp set-pipeline --pipeline migrate-module --config migrate-module.yaml -v cluster_name=$CLUSTER_NAME -v module=$MODULE_NAME` +4. Run `migrate-module` pipeline from the Concourse UI. +5. Unpause pipelines +6. Re-run PR plan - the plan should show "No changes. Your infrastructure matches the configuration." +7. Pause pipelines +8. Get approval for the PR and merge. +9. Un-pause `live-2` and check for a clean apply +10. Repeat 9. with `manager` and `live` +11. Update #cloud-platform informing the team of the completed migration and that pipelines are unpaused. ## Disaster Recovery