Skip to content

Commit

Permalink
generate status messages for resource migration
Browse files Browse the repository at this point in the history
  • Loading branch information
theishshah committed Dec 2, 2024
1 parent b421b1c commit c73979f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions migrate-state.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -e

echo "Starting Terraform state migration..."

# Function to check if a resource exists in terraform state
check_resource() {
terraform state list | grep -q "$1" && return 0 || return 1
}

# Function to migrate a single resource
migrate_resource() {
local OLD_RESOURCE="$1"
local NEW_RESOURCE="$2"

if check_resource "$OLD_RESOURCE"; then
echo "Migrating ${OLD_RESOURCE} to ${NEW_RESOURCE}"
terraform state mv -lock=false "$OLD_RESOURCE" "$NEW_RESOURCE" || {
echo "Failed to migrate ${OLD_RESOURCE}"
return 1
}
else
echo "Resource ${OLD_RESOURCE} not found in state, skipping..."
fi
}

# Backup the current state
echo "Creating state backup..."
terraform state pull > terraform.tfstate.backup.$(date +%Y%m%d-%H%M%S)

# Migrate each resource
echo "Migrating resources..."

# Migrate the operator release
migrate_resource "helm_release.operator" "helm_release.operator[0]"

# Migrate the wandb release
migrate_resource "helm_release.wandb" "helm_release.wandb[0]"

echo "Migration completed!"
echo "Please review the state and run 'terraform plan' to verify the migration"

0 comments on commit c73979f

Please sign in to comment.