Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update process for migrating a resource #5490

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 13 additions & 52 deletions runbooks/source/move-components-module.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down