Guest User

Untitled

a guest
Apr 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Parameters
  4. vpcName=$1
  5. AWS_DEFAULT_REGION=$2
  6. AWS_ACCESS_KEY_ID=$3
  7. AWS_SECRET_ACCESS_KEY=$4
  8.  
  9. export AWS_DEFAULT_REGION AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
  10.  
  11. #Get IDs
  12. vpcId=$(aws ec2 describe-vpcs --filters Name=tag-value,Values=$vpcName --query 'Vpcs[*].VpcId' --output text)
  13. echo "VPC ID: "$vpcId
  14.  
  15. rtId=$(aws ec2 describe-route-tables --filters "Name=vpc-id,Values=$vpcId" --query 'RouteTables[?!not_null(Tags[?Key == `Name`].Value)].{id: RouteTableId}' --output text)
  16. if [[ $rtId ]]; then
  17. echo "Default Route Table ID: "$rtId
  18.  
  19. associationId=$(aws ec2 describe-route-tables --filters "Name=vpc-id,Values=$vpcId" --query 'RouteTables[?Associations[0].Main == `true`].{id: Associations[0].RouteTableAssociationId}' --output text)
  20. echo "Association ID: "$associationId
  21.  
  22. rTables=$(aws ec2 describe-route-tables --filters "Name=vpc-id,Values=$vpcId" --query 'RouteTables[?not_null(Tags[?Key == `Name`].Value)].{id: RouteTableId}' --output text)
  23. rTableMain=$(echo $rTables |awk 'BEGIN { FS = " " } ; { print $1 }')
  24. echo "Main Route Rables ID: " $rTableMain
  25.  
  26. #Replace Main Rute Table
  27. aws ec2 replace-route-table-association --association-id $associationId --route-table-id $rTableMain --output text
  28.  
  29. #Delete Route Table
  30. aws ec2 delete-route-table --route-table-id $rtId
  31. fi
Add Comment
Please, Sign In to add comment