Guest User

Untitled

a guest
Mar 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # written by Diego Gutierrez
  4. # This script will associate a vpc with a route53 hosted zone in another account
  5.  
  6. printf "Details for the originating account and vpc:\n\n"
  7. printf "Enter the credential profile for that account, followed by [ENTER]:"
  8. read originatingAccountCredProfile
  9. printf "Enter the hosted zone id for the created domain, followed by [ENTER]:"
  10. read hostedZoneId
  11. printf "\n\n"
  12.  
  13. printf "Details associating account and vpc:\n\n"
  14. printf "Enter the VPC ID that will be associated, followed by [ENTER]:"
  15. read associatedAccountVpcId
  16. printf "Enter the region for that vpc, followed by [ENTER]:"
  17. read associatedAccountVPCRegion
  18. printf "Enter the credential profile for that account, followed by [ENTER]:"
  19. read associatedAccountCredProfile
  20. printf "\n\n"
  21.  
  22.  
  23. # create the association authorization
  24. printf "Creating association authorization for hosted zone: ${hostedZoneId}, vpc: ${associatedAccountVpcId}"
  25. aws route53 create-vpc-association-authorization --hosted-zone-id ${hostedZoneId} --vpc VPCRegion=${associatedAccountVPCRegion},VPCId=${associatedAccountVpcId} \
  26. --profile ${originatingAccountCredProfile}
  27.  
  28. if [[ $? -eq 0 ]]; then
  29. printf "SUCCESS\n\n"
  30. else
  31. printf "FAILED\n\n"
  32. exit 1
  33. fi
  34.  
  35. # associate hosted zone with the vpc
  36. echo "Associating vpc ${associatedAccountVpcId}, with hosted zone: ${hostedZoneId}"
  37. aws route53 associate-vpc-with-hosted-zone --hosted-zone-id ${hostedZoneId} --vpc VPCRegion=${associatedAccountVPCRegion},VPCId=${associatedAccountVpcId} \
  38. --profile ${associatedAccountCredProfile}
  39.  
  40. if [[ $? -eq 0 ]]; then
  41. printf "SUCCESS\n\n"
  42. else
  43. printf "FAILED\n\n"
  44. exit 1
  45. fi
  46.  
  47. # delete the association authorization
  48. echo "Cleaning up the authorization"
  49. aws route53 delete-vpc-association-authorization --hosted-zone-id ${hostedZoneId} --vpc VPCRegion=${associatedAccountVPCRegion},VPCId=${associatedAccountVpcId} \
  50. --profile ${originatingAccountCredProfile}
  51.  
  52. if [[ $? -eq 0 ]]; then
  53. printf "SUCCESS\n\n"
  54. else
  55. printf "FAILED\n\n"
  56. exit 1
  57. fi
  58.  
  59. exit 0
Add Comment
Please, Sign In to add comment