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
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_fqdnThe reference should be something like:
By using this variable in the frontend you don’t need to define any dependencies on your own because terraform will know them.
As mentioned by De_The_Mi you can reference the url of the latest revision deployed using:
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)