UpdateARecord.sh
#!/usr/bin/env bash echo "My public IP:$(curl -s ipinfo.io/ip)" ZONE_NAME='example-com'DOMAIN_NAME='somefacysubdomain.example.com.'
gcloud dns record-sets transaction abort -z=$ZONE_NAME
gcloud dns record-sets transaction start -z=$ZONE_NAME
#show current A record
gcloud dns record-sets list --zone $ZONE_NAME --name "$DOMAIN_NAME" --type=A #remove old record
OLD_IP=$(gcloud dns record-sets list --zone $ZONE_NAME --name "$DOMAIN_NAME" --type=A | sed -n 2p | awk '{print $4}') gcloud dns record-sets transaction remove -z=$ZONE_NAME \ --name="$DOMAIN_NAME" \ --type=A \ --ttl=300 "$OLD_IP" #add new record
gcloud dns record-sets transaction add -z=$ZONE_NAME \ --name="$DOMAIN_NAME" \ --type=A \ --ttl=300 "$(curl -s ipinfo.io/ip)"
#check incoming changes
gcloud dns record-sets transaction describe -z=$ZONE_NAME
#make changes
gcloud dns record-sets transaction execute -z=$ZONE_NAME
#display updated DNS records
gcloud dns record-sets list --zone $ZONE_NAME