FIX: correct shell script error

This commit is contained in:
xpk 2022-08-05 15:08:37 +08:00
parent 3c5c56737f
commit 6044f17540
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86

View File

@ -1,17 +1,14 @@
#!/bin/bash
region=$1
# get default vpc
vpc=$(aws ec2 --region ${region} \
describe-vpcs --filter Name=isDefault,Values=true \
| jq -r .Vpcs[0].VpcId)
if [ "${vpc}" = "null" ]; then
echo "No default vpc found"
continue
exit 0
fi
echo "Found default vpc ${vpc}"
# get internet gateway
igw=$(aws ec2 --region ${region} \
describe-internet-gateways --filter Name=attachment.vpc-id,Values=${vpc} \
| jq -r .InternetGateways[0].InternetGatewayId)
@ -23,7 +20,6 @@ region=$1
delete-internet-gateway --internet-gateway-id ${igw}
fi
# get subnets
subnets=$(aws ec2 --region ${region} \
describe-subnets --filters Name=vpc-id,Values=${vpc} \
| jq -r .Subnets[].SubnetId)
@ -35,13 +31,8 @@ region=$1
done
fi
# https://docs.aws.amazon.com/cli/latest/reference/ec2/delete-vpc.html
# - You can't delete the main route table
# - You can't delete the default network acl
# - You can't delete the default security group
# delete default vpc
echo "Deleting vpc ${vpc}"
aws ec2 --region ${region} \
delete-vpc --vpc-id ${vpc}