Fixed typos

This commit is contained in:
JustFiesta 2024-05-22 15:50:18 +02:00
parent f116558874
commit e9451c18ae

View file

@ -1,9 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# ------------------- # -------------------
# This script removes AWS environment from previus scripts # This script removes AWS environment from previous scripts
# It removes: VPC, Subnet, Elastic Container Registry (ECR), EC2 instance with a public IP, Security Groups # It removes: VPC, Subnet, Elastic Container Registry (ECR), EC2 instance with a public IP, Security Groups
# #
# Reqiured: configured AWS CLI # Required: configured AWS CLI
# Global variable # Global variable
ERR=0 ERR=0
@ -12,7 +12,7 @@ ERR=0
read -p "Enter region remove resources from: " REGION read -p "Enter region remove resources from: " REGION
read -p "Enter tag key to remove resources from: " TAG_KEY read -p "Enter tag key to remove resources from: " TAG_KEY
read -p "Enter tag value to remove resources from: " TAG_VALUE read -p "Enter tag value to remove resources from: " TAG_VALUE
read -p "Enter ECR name to remove it from aws: " ECR_NAME read -p "Enter ECR name to remove it from AWS: " ECR_NAME
echo "---------------------------------------" echo "---------------------------------------"
@ -22,7 +22,7 @@ echo "Deleting EC2 Instances..."
instances=$(aws ec2 describe-instances --region "$REGION" --query "Reservations[].Instances[?Tags[?Key=='$TAG_KEY'&&Value=='$TAG_VALUE']].InstanceId" --output text) instances=$(aws ec2 describe-instances --region "$REGION" --query "Reservations[].Instances[?Tags[?Key=='$TAG_KEY'&&Value=='$TAG_VALUE']].InstanceId" --output text)
if [ -z "$instances" ]; then if [ -z "$instances" ]; then
echo "There is no EC2 instances for tag $TAG_KEY:$TAG_VALUE." echo "There are no EC2 instances for tag $TAG_KEY:$TAG_VALUE."
else else
for instance_id in $instances; do for instance_id in $instances; do
aws ec2 terminate-instances --region "$REGION" --instance-ids "$instance_id" aws ec2 terminate-instances --region "$REGION" --instance-ids "$instance_id"
@ -41,12 +41,16 @@ echo ""
# Deleting Elastic Container Registry (ECR) # Deleting Elastic Container Registry (ECR)
echo "Deleting Elastic Container Registries (ECR)..." echo "Deleting Elastic Container Registries (ECR)..."
aws ecr delete-repository --region "$REGION" --repository-name "$ECR_NAME" --force if aws ecr describe-repositories --repository-names "$ECR_NAME" --region "$REGION" > /dev/null 2>&1; then
if [ $? -eq 0 ]; then aws ecr delete-repository --region "$REGION" --repository-name "$ECR_NAME" --force
echo "ECR repository $ECR_NAME deleted successfully." if [ $? -eq 0 ]; then
echo "ECR repository $ECR_NAME deleted successfully."
else
echo "Error deleting ECR repository $ECR_NAME."
ERR=$((ERR+1))
fi
else else
echo "Error deleting ECR repository $ECR_NAME." echo "ECR repository $ECR_NAME does not exist."
ERR=$((ERR+1))
fi fi
echo "" echo ""
echo "---------------------------------------" echo "---------------------------------------"
@ -70,7 +74,7 @@ echo "---------------------------------------"
echo "" echo ""
if [ $ERR -gt 0 ]; then if [ $ERR -gt 0 ]; then
echo "Not all recources were delted successfully. Please check them manuanlly." echo "Not all resources were deleted successfully. Please check them manually."
else else
echo "All resources with tag $TAG_KEY:$TAG_VALUE have been successfully deleted from AWS." echo "All resources with tag $TAG_KEY:$TAG_VALUE have been successfully deleted from AWS."
fi fi