Created
October 27, 2018 09:53
-
-
Save synchrone/71794b712ddc95889398ffa44d7a7221 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
[ -z "$4" ] && echo "Usage: $0 <gc-project> <zone-name> <domain-name> <value>" && exit 1 | |
TYPE=A | |
PROJECT=$1 | |
ZONE=$2 | |
TARGET=$3 | |
IP=$4 | |
RS="gcloud --project=$PROJECT dns record-sets" | |
EXISTING=`$RS list --zone="$ZONE" | grep "$TARGET" | grep " $TYPE " | awk '{print $4}'` | |
echo using zone $PROJECT/$ZONE to set $TARGET type $TYPE to $IP | |
TX="$RS transaction" | |
$TX start -z=$ZONE | |
echo removing $EXISTING... | |
$TX remove -z=$ZONE \ | |
--name="$TARGET" \ | |
--type=$TYPE \ | |
--ttl=30 "$EXISTING" || ($TX abort -z=$ZONE && exit 1) | |
echo setting $TARGET=$IP... | |
$TX add -z=$ZONE \ | |
--name="$TARGET" \ | |
--type=$TYPE \ | |
--ttl=30 "$IP" || ($TX abort -z=$ZONE && exit 1) | |
echo committing... | |
TXID=$($TX execute -z=$ZONE --format json | jq -r '.id') | |
status=pending | |
while [ ! "$status" == "done" ]; do | |
echo waiting for gcdns to update; | |
status=$($RS changes describe $TXID -z syn-im --format json | jq -r '.status') | |
done | |
echo All done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment