#!/bin/bash # Script to wait for ch2 termination and then create additional storage for A1 echo "Waiting for ch2 instance to be fully terminated..." # Wait for ch2 to be fully terminated while true; do ch2_status=$(oci --profile korea compute instance list --compartment-id ocid1.tenancy.oc1..aaaaaaaawfv2wd54ly75ppfjgdgap7rtd3vhtziz25dwx23xo4rbkxnxlapq --all --raw-output --query 'data[?contains("display-name", `ch2`)][?"lifecycle-state"].lifecycle-state' --output text 2>/dev/null) if [ "$ch2_status" = "" ] || [ "$ch2_status" = "TERMINATED" ]; then echo "ch2 instance is fully terminated." break else echo "ch2 still in $ch2_status state, waiting 30 seconds..." sleep 30 fi done echo "Now creating additional storage for A1 instance..." # Since we cannot easily import existing resources to Terraform state, # we will create a new volume and attach it to A1 instance via Terraform TF_CLI_CONFIG_FILE=.terraformrc terraform apply -var ch2_enabled=false -var ch3_enabled=true -var a1_storage_size_gb=200 -auto-approve if [ $? -eq 0 ]; then echo "Additional storage successfully allocated to A1 instance" else echo "Failed to allocate additional storage to A1 instance" exit 1 fi echo "Storage reallocation completed successfully!"