Eliminazione di massa delle risorse ed eliminazione degli stack

Per il compartimento specificato, utilizzare lo script seguente per eliminare tutti gli stack in Resource Manager ed eliminare tutte le risorse associate agli stack corrispondenti.

Questo script esegue i job di eliminazione su tutte le risorse di cui è stato eseguito il provisioning in un compartimento e quindi elimina tutti gli stack associati.

  1. Aggiornare l'OCID del compartimento nello script seguente.
    Script per l'eliminazione automatica di job e stack
    #!/bin/bash
    echo ""
    echo ""
    echo ""
    echo "This script destroys all provisioned resources and deletes all associated stacks in a compartment. "
    echo "Update the compartment OCID before you run the script."
    echo " "
    echo "**************************************************"
    echo "STACK DELETIONS CANNOT BE UNDONE."
    echo "**************************************************"
    echo ""
    echo "Starting to delete stacks from compartment id " $1
    echo "Are you sure you want to continue ?"
    select yn in "Yes" "No"; do
        case $yn in
            Yes )  break;;
            No ) echo "Exiting...";exit;;
        esac
    done
    
    stacks_to_be_deleted=$(oci resource-manager stack  list --compartment-id $1  --lifecycle-state=ACTIVE | jq -r ".data[].id")
    
    #stacks_to_be_deleted=$(oci resource-manager stack list -c ocid1.tenancy.oc1..<unique_ID> --lifecycle-state=ACTIVE)
    
    echo "Destroying Stacks"
    echo
    failedStackArr=()
    for stack in $stacks_to_be_deleted
    do
            echo "Creating a job to destroy stack : $stack"
            #stack_destroyed=$(oci resource-manager job create-destroy-job --stack-id $stack --execution-plan-strategy AUTO_APPROVED)      
    
            #echo "oci resource-manager stack delete --force --stack-id $stack.id"
    
            job_id_destroy_stack=$(oci resource-manager job create-destroy-job --stack-id $stack  --execution-plan-strategy AUTO_APPROVED | jq -r ".data.id")
            #poll for the status
            
    	echo "Destroy job OCID : $job_id_destroy_stack"
    	echo "Destroying resources provisioned by stack : $stack"
            
    	#poll for destroy job
            destroy_job_status="STARTED"
            while [ $destroy_job_status != "SUCCEEDED" -a  $destroy_job_status != "FAILED" ]
            do
                    sleep 5s
                    destroy_job_status=$(oci resource-manager job get --job-id $job_id_destroy_stack  | jq -r '.data."lifecycle-state"')
    
            done
    
            if [ $destroy_job_status == "SUCCEEDED" ]; then
                echo "Stack resources destroyed. Now deleting the stack $stack"
    	    echo		
                stack_deleted=$(oci resource-manager stack delete --stack-id $stack --force   | jq -r ".data.id")
            fi
    
            if [ $destroy_job_status == "FAILED" ]; then
                echo "Not able to destroy resources from stack $stack"
                failedStackArr+=($stack)
            fi
    done
    
    if [ ${#failedStackArr[@]} -gt 0 ]; then
    	echo "Not able to destroy resources and delete these stacks. Please run destroy jobs and delete stacks manually."
    	echo ${failedStackArr[@]}
    else
    	echo "Success. All resources have been destroyed and associated stacks have been deleted."
    fi 
    
    echo "done "
  2. Eseguire lo script utilizzando il comando seguente.
    ./destroy_delete_stacks_bulk_cloud_shell.sh <compartment_id>