Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # written by Diego Gutierrez
- # This script will associate a vpc with a route53 hosted zone in another account
- printf "Details for the originating account and vpc:\n\n"
- printf "Enter the credential profile for that account, followed by [ENTER]:"
- read originatingAccountCredProfile
- printf "Enter the hosted zone id for the created domain, followed by [ENTER]:"
- read hostedZoneId
- printf "\n\n"
- printf "Details associating account and vpc:\n\n"
- printf "Enter the VPC ID that will be associated, followed by [ENTER]:"
- read associatedAccountVpcId
- printf "Enter the region for that vpc, followed by [ENTER]:"
- read associatedAccountVPCRegion
- printf "Enter the credential profile for that account, followed by [ENTER]:"
- read associatedAccountCredProfile
- printf "\n\n"
- # create the association authorization
- printf "Creating association authorization for hosted zone: ${hostedZoneId}, vpc: ${associatedAccountVpcId}"
- aws route53 create-vpc-association-authorization --hosted-zone-id ${hostedZoneId} --vpc VPCRegion=${associatedAccountVPCRegion},VPCId=${associatedAccountVpcId} \
- --profile ${originatingAccountCredProfile}
- if [[ $? -eq 0 ]]; then
- printf "SUCCESS\n\n"
- else
- printf "FAILED\n\n"
- exit 1
- fi
- # associate hosted zone with the vpc
- echo "Associating vpc ${associatedAccountVpcId}, with hosted zone: ${hostedZoneId}"
- aws route53 associate-vpc-with-hosted-zone --hosted-zone-id ${hostedZoneId} --vpc VPCRegion=${associatedAccountVPCRegion},VPCId=${associatedAccountVpcId} \
- --profile ${associatedAccountCredProfile}
- if [[ $? -eq 0 ]]; then
- printf "SUCCESS\n\n"
- else
- printf "FAILED\n\n"
- exit 1
- fi
- # delete the association authorization
- echo "Cleaning up the authorization"
- aws route53 delete-vpc-association-authorization --hosted-zone-id ${hostedZoneId} --vpc VPCRegion=${associatedAccountVPCRegion},VPCId=${associatedAccountVpcId} \
- --profile ${originatingAccountCredProfile}
- if [[ $? -eq 0 ]]; then
- printf "SUCCESS\n\n"
- else
- printf "FAILED\n\n"
- exit 1
- fi
- exit 0
Add Comment
Please, Sign In to add comment