By Analytium
If I own and configured example.com, I would like for all new droplets to be added on as second level domain. For example, if a new droplet called dev, could it not be automatically added as dev.example.com?
I can see this questions: https://www.digitalocean.com/community/questions/automaticaly-add-new-droplet-to-digitalocean-dns but it is three years old. Has anything been developed since then?
Regards, Analytium
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This is possible, but you would need to do it through the API. There isn’t (and probably will never be) a option to do this in the portal. Here’s the link to the documentation: https://developers.digitalocean.com/documentation/v2/#domain-records
To follow on what @MichaelOjeda said, once you have an API Token, the curl request to add a domain via the API is:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer APITOKEN" -d '{"name":"example.com","ip_address":"1.2.3.4"}' "https://api.digitalocean.com/v2/domains"
For NEW droplets, you can automate this by pasting a user-data cloud-config script in the User Data field on the Droplet Create page:
#cloud-config
runcmd:
- export DROPLET_NAME=$(curl -s http://169.254.169.254/metadata/v1/hostname)
- export DROPLET_IP=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
- 'curl -X POST -H ''Content-Type: application/json'' -d ''{"name":"''"$DROPLET_NAME"''.example.com", "ip_address":"''"$DROPLET_IP"''"}'' -H "Authorization: Bearer API_TOKEN" https://api.digitalocean.com/v2/domains'
replace example.com and API_TOKEN
The #cloud-config line specifies that you are using cloud-init language (which interprets this as YAML), runcmd: specifies that the following lines should be run in shell when server first starts.
The two export lines set the droplet’s IP address and name as environment variables, and the final line makes the HTTP request to create a new domain via the API.
(All the extra quotation marks are due to making YAML and JSON play nice together)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.