I am able to edit DNS records with gcloud tool by interactively editing JSON file from vi/mate using the command:
gcloud dns records --zone=myzone edit
However, I would like to be able to do bulk updates, something like this:
gcloud dns records --zone=myzone edit < my-additional-records.txt
...where my-additional-records.txt contain the DNS records I want to add.
I think it is not so simple as the JSON file to edit contains both addition and deletion of DNS records. So, any tips will be appreciated.
I think you could try using the linux line editor 'ed' like this:
EDITOR=ed gcloud dns records --zone=myzone edit <<-EOF
12i
, {
"kind": "dns#resourceRecordSet",
"name": "a.mydomain.org.",
"rrdatas": [
"111.222.111.222"
],
"ttl": 21600,
"type": "A"
}
.
,wq
EOF
This assumes that the top of the edit file looks something like this (so you an append your addition to the 12th line)
{
"additions": [
{
"kind": "dns#resourceRecordSet",
"name": "mydomain.org.",
"rrdatas": [
"ns-cloud-c1.googledomains.com. dns-admin.google.com. 2 21600 3600 1209600 300"
],
"ttl": 21600,
"type": "SOA"
},
More details on how to use ed here: http://www.gnu.org/software/ed/manual/ed_manual.html
Providing this new answer since gcloud dns ...
has been significantly improved since this question was asked. There are now two ways in which you can edit record-sets.
Using export/import commands as follows:
gcloud dns record-sets export --zone my-zone RECORDS-FILE
By default, RECORDS-FILE
is in yaml format. You can also get it in zone file format by using the --zone-file-format
flag.
You can then edit RECORDS-FILE
using any editor of your choice, and import the changed records using:
gcloud dns record-sets import --zone my-zone --delete-all-existing RECORDS-FILE
Import also accepts --zone-file-format
. If you want to just add/edit some records but not all of them, you can omit the --delete-all-existing
flag.
Using the transaction command group as follows:
gcloud dns record-sets transaction start # Start transaction
gcloud dns record-sets transaction add/remove # Add remove records
gcloud dns record-sets transaction execute # Execute transaction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With