digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
509 stars 278 forks source link

Is there a better way to get `default_ingress` from `digitalocean_app`? #1207

Closed bartekpacia closed 2 months ago

bartekpacia commented 2 months ago

My app has a top-level domain bee-ci.pacia.tech, and I set the zone of my digitalocean_app.app to that that domain (=bee-ci.pacia.tech).

I want for my app to be available at subdomain backend.bee-ci.pacia.tech. For this I create a new digitalocean_record.backend, but to get the ingress address for my app, I have to write this which I think is a bit convoluted:

format("%s.", split("://", digitalocean_app.app.default_ingress)[1])

Is there a better way?

Here's my full main.tf:

resource "digitalocean_project" "project" {
  name        = "bee-ci-proj-tf"
  description = "A simple container-based CI system"
  environment = "Development"
  resources = [
    digitalocean_app.app.urn,
    digitalocean_database_cluster.main-db-cluster.urn,
    digitalocean_domain.main.urn,
  ]
}

resource "digitalocean_app" "app" {
  spec {
    name   = "bee-ci-tf"
    region = "sfo"

    domain {
      name = "backend.bee-ci.pacia.tech"
      type = "PRIMARY"
      zone = digitalocean_domain.main.name
    }

    # ...
}

resource "digitalocean_domain" "main" {
  name = "bee-ci.pacia.tech"
}

resource "digitalocean_record" "backend" {
  domain = digitalocean_domain.main.id
  type   = "CNAME"
  name   = "backend"
  value  = format("%s.", split("://", digitalocean_app.app.default_ingress)[1])
  # value  = "bee-ci.pacia.tech." # this is the value I want
}
andrewsomething commented 2 months ago

Hi @bartekpacia,

The API has actually added a live_domain attribute that should give you exactly what you want. We'll get that added here.

bartekpacia commented 2 months ago

That's great to hear! Thanks so much! 💙