Lorenzo
Lorenzo

Reputation: 21

Google cloud dns CNAME creation example

I had been not able to create a new CNAME for a specific managed-zone.

I can see there are examples for A and TXT entries like:

$ gcloud dns record-sets transaction add -z MANAGED_ZONE \
            --name my.domain. --ttl 1234 --type A "1.2.3.4"

$ gcloud dns record-sets transaction add -z MANAGED_ZONE \
            --name my.domain. --ttl 2345 --type TXT "Hello world" "Bye \
            world"

But I keep getting too few arguments error. Currently I'm issuing:

$ gcloud dns record-sets -z=MYZONE transaction add\
            --name="NAME" --type=CNAME --ttl 3600 --rrdatas="DEST"

I guess the issue is related to the rrdatas field but I have been unable to find any documentation.

Upvotes: 2

Views: 2155

Answers (3)

Eric L
Eric L

Reputation: 21

I just ran into this and was able to create CNAME records with the following steps. You begin by starting a transaction:

gcloud dns record-sets transaction start --zone=domain-com

Then, add records to the transaction (add as many as you need):

gcloud dns record-sets transaction add "subdomain.domain.com." --name="cnamelocation.com." --ttl=3600 --type=CNAME --zone=domain-com

Lastly, execute the transaction:

gcloud dns record-sets transaction execute --zone=domain-com

If you mess up at some point along the way, you can abort the transaction and start over:

gcloud dns record-sets transaction abort --zone=domain-com

Upvotes: 0

mimming
mimming

Reputation: 13954

The command does not have a rrdatas flag. You can just put the value you want for rrdatas at the end of the command as a positional argument. Also, note that the -z zone flag should be provided after all the commands. So:

$ gcloud dns record-sets -z=MYZONE transaction add --type=CNAME \
  --name="www.example.com." --ttl 3600 --rrdatas="target.example.com."

should be changed to this:

$ gcloud dns record-sets transaction add -z=MYZONE --type=CNAME \
  --name="www.example.com." --ttl 3600 "target.example.com."

Upvotes: 5

Ricardo Lorenzo
Ricardo Lorenzo

Reputation: 9

According to the record types documented on the API, note that the rrdatas value should point to a valid record or must end with periods (.) in the case of fully-qualified DNS names.

Upvotes: 0

Related Questions