Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Accepted Answer
Hey there! 👋
Setting up DNS records with Terraform on DigitalOcean is super straightforward and can save you a lot of time.
If you just want a basic setup, you can manage your domain and add an A record to point to your Droplet’s IP without needing any extra configurations.
Here’s an example:
# Create the domain in DigitalOcean
resource "digitalocean_domain" "example" {
name = "example.com" # Replace with your domain name
}
# Add an A record for www.example.com
resource "digitalocean_record" "www" {
domain = digitalocean_domain.example.id
type = "A"
name = "www" # This makes www.example.com
value = "192.168.0.11" # Replace with your Droplet's IP
}
This will create a domain (example.com) and set up an A record for www.example.com to point to your Droplet’s IP address. Once it’s applied, your DNS will be good to go!
If you want the A record to automatically use your Droplet’s IP address, you can reference the Droplet’s IP in the value field.
Just replace the IP with your Droplet’s ipv4_address like this:
resource "digitalocean_droplet" "my_droplet" {
name = "example-droplet"
region = "nyc3"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
}
resource "digitalocean_record" "www" {
domain = digitalocean_domain.example.id
type = "A"
name = "www"
value = digitalocean_droplet.my_droplet.ipv4_address # Auto-updates with Droplet IP
}
Here are a couple of resources to help you out:
Let me know if this helps!
If you’re new to Terraform, I would also suggest this Terraform ebook here.
- Bobby