skip to Main Content

I try to deploy a backend and frontend as container apps in azure with terraform.
The frontend needs to have the URL of the backend as environment variable.

Is this possible in one go?

Like for example with docker-compose where the internal hostname of a container is predetermined or a service in kubernetes.

The only thing I can think of right now is to apply the plan, wait for the container apps to get created and receive a hostname and then afterwards change my .tf file and apply again. But there has to be a better solution.

2

Answers


  1. In terraform you can set the property depends_on = [] to each resource to define dependencies that are not clear from code side. But in your case, you should be able to reference the fqdn of the backend using the variable of the backend-container-app: latest_revision_fqdn

    The reference should be something like:

    azurerm_container_app.<your-backend-object-name>.latest_revision_fqdn
    

    By using this variable in the frontend you don’t need to define any dependencies on your own because terraform will know them.

    Login or Signup to reply.
  2. As mentioned by De_The_Mi you can reference the url of the latest revision deployed using:

    azurerm_container_app.<your-backend-object-name>.latest_revision_fqdn
    

    However that changes with every deployment, if you want the "Application Url" as it’s called in the Portal you can use the following as mentioned in the Github issue (https://github.com/hashicorp/terraform-provider-azurerm/issues/20696)

    azurerm_container_app.<your-backend-object-name>.ingress[0].fqdn
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search