Get app public url via terraform

Is there a way to get the public url of an app via terraform? I want to refer to my app/service in a resource in another provider. I guess I could implement this using domains, but it would be nice if I don’t need to. If not possible via terraform, is it somewhere available via api, so that it could be implemented in terraform?

Hey! The domain should be included in the app resource: Terraform Registry

Hope this helps :slight_smile:

Yep, I know I could use a domain. The point is I don’t need to use domains if I can get the default public url provided by koyeb. However I could not find a way to get that in neither terraform or the api.

I’m not sure I understand. What are you trying to achieve? Do you want a way to know the public url of an app before creating one?

Just to be clear, for every app in Koyeb, an autoassigned domain is automatically created, you don’t need to do it. It’s part of the App model that is returned by the API or Terraform provider.

No I want to get the public url after the creation, so I can assign it to another resource in terraform, something like:

resource "koyeb_app" "my-app" {
  name = "my-app"
}

resource "some-other-provider" "another-resource" {
  env {
    "MY_APP_URL" = "${koyeb_app.my-app.public_url}"
  }
}

You mentioned the autoassigned domain is part of the app model in terraform. What attribute contains that? In other words, what should I put in place of of “public_url” in my example.

Okay, so something like this should work:

resource "koyeb_app" "my-app" {
  name = "my-app"
}

resource "some-other-provider" "another-resource" {
  env {
    "MY_APP_URL" = "https://${koyeb_app.my-app.domains[0].name}/"
  }
}

Got it. I think because in the user interface the auto assigned domain does not appear in domains, I assumed it couldn’t be in the “domains” attribute, hehe. Now your first message makes total sense to me. Thanks for the help.

1 Like