By mwisniowski
I’m trying to create a Terraform config that will set up a load balancer with Let’s encrypt’s certificate installed for the particular domain.
The configuration I have resulted in
“Error: Cycle: digitalocean_record.static, digitalocean_certificate.cert, digitalocean_loadbalancer.www-lb”
Is there any other way to handle it?
resource "digitalocean_domain" "default" {
// Note: in reality, the domain name is not "example.com".
name = "example.com"
}
resource "digitalocean_record" "static" {
domain = digitalocean_domain.default.name
type = "A"
name = "static"
value = digitalocean_loadbalancer.www-lb.ip
}
resource "digitalocean_certificate" "cert" {
name = "examplecert"
type = "lets_encrypt"
domains = [digitalocean_record.static.fqdn]
lifecycle {
create_before_destroy = true
}
}
resource "digitalocean_loadbalancer" "www-lb" {
name = "example-lb"
region = var.region
vpc_uuid = digitalocean_vpc.vpc.id
forwarding_rule {
entry_port = 443
entry_protocol = "https"
target_port = 80
target_protocol = "http"
certificate_id = digitalocean_certificate.cert.id
}
healthcheck {
port = 80
protocol = "http"
}
droplet_ids = digitalocean_droplet.www.*.id
}
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.
I’ve sorted this out by hardcoding the “static” subdomain name like this:
domains = [“static.${digitalocean_domain.default.id}”]
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.
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.
