Can't simply add a custom domain to an app with Terraform

Hello team, it seems that we can’t use Terraform to set a domain correctly since we can’t restart an application after a domain is added :disappointed:

Terraform example :arrow_down:

# ....

# create and deploy app with custom domain
resource "qovery_application" "backend" {
  environment_id = qovery_environment.production.id
  name           = "backend"
  cpu            = 500
  memory         = 256
  state          = "RUNNING"
  git_repository = {
    url       = "https://github.com/evoxmusic/ShortMe-URL-Shortener.git"
    branch    = "main"
    root_path = "/"
  }
  build_mode            = "DOCKER"
  dockerfile_path       = "Dockerfile"
  min_running_instances = 1
  max_running_instances = 1
  custom_domains        = [
    {
      domain = var.qovery_custom_domain
    }
  ]
  ports = [
    {
      internal_port       = 5555
      external_port       = 443
      protocol            = "HTTP"
      publicly_accessible = true
    }
  ]
  environment_variables = [
    {
      key   = "DEBUG"
      value = "false"
    }
  ]

  depends_on = [
    qovery_environment.production,
  ]
}

# create custom domain record
resource "cloudflare_record" "foobar" {
  zone_id = var.cloudflare_zone_id
  name    = var.cloudflare_record_name
  value   = one(qovery_application.backend.custom_domains[*].validation_domain)
  type    = "CNAME"
  ttl     = 3600
}
  1. Create the application with a custom domain, but the resource needs to be created to have access to the validation_domain
  2. The validation_domain is used to create a Cloudflare record
  3. But to apply this change, I need to restart the application :confused:

It’s okay with the web UI, but with Terraform, it does not work since the application’s state has not actually changed.

Potential solutions

I see 2 potential solutions that are not mutually exclusive:

  1. Supporting Wildcard domain
  2. Supporting dynamic domain change when a domain is added/changed.

Update: one valid solution we found is using this API call to detect application change and proceed to a redeployment.