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.

GOAL:
I’m using terraform to quickly and easily setup a Kubernetes cluster. I have a LoadBalancer service that should expose my blog-backend service with a custom domain (I have already added DNS NS entries in my Cloudflare that redirects base domain to DigitalOcean’s servers).
resource "kubernetes_service" "blog-backend-lb" {
metadata {
name = "blog-backend-lb"
labels = {
app = "blog-backend"
}
annotations = {
"service.beta.kubernetes.io/do-loadbalancer-name" = "blog.mydomain.com"
"service.beta.kubernetes.io/do-loadbalancer-hostname" = "blog.mydomain.com"
}
}
spec {
type = "LoadBalancer"
selector = {
app = "blog-backend"
}
port {
port = 8080
target_port = 8080
}
}
}
PROBLEM: The service is being create properly and I can see Kubernetes picked up a domain.
However, I cannot access it unless I manually create a domain entry in the DigitalOcean dashboard: Networking -> Domains -> Add Domain -> Create Record for my subdomain redirecting to a LoadBalancer.
This is a bit cumbersome, because I want to clean everything up using terraform without touching anything by hand.
QUESTION: How can I automate it using a Terraform?
I thought about using a domain resource, but I don’t know where to get the ip address from.
resource "digitalocean_domain" "blog-backend-domain" {
name = "blog.mydomain.com"
ip_address = "<WHERE TO GET THE IP FROM?>"
}
72e571841e7f4a6881090a2f3e93c0
dom77a6e2e9d3a2
Christoffer Braathen
Jaimin Joshi
099d155dd62c45078c85bd5b98d003
82488cefb7d74db1ad87250ea4f452
Mrugesh Mohapatra
828c1c19bec3419eb032d05c128960
Rumyana Rumenova
Ben Roberts
garry55441234