Skip to content

Instantly share code, notes, and snippets.

@synchrone
Created October 27, 2018 09:53
Show Gist options
  • Save synchrone/71794b712ddc95889398ffa44d7a7221 to your computer and use it in GitHub Desktop.
Save synchrone/71794b712ddc95889398ffa44d7a7221 to your computer and use it in GitHub Desktop.
#!/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