Question

Terraform config to create domain, record, certificate and loadbalancer at once results in a cycle error

Posted June 3, 2020 419 views
Load BalancingTerraform

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: digitaloceanrecord.static, digitaloceancertificate.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
}

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.

×
1 answer
Show answer This answer has been marked as resolved by mwisniowski.
Submit an Answer