Heyho!
I want to deploy my environment with terraform. As we rely on an API Gateway (an NGINX application itself), I need to set the internal hosts for the upstream services correctly.
According to https://registry.terraform.io/providers/Qovery/qovery/latest/docs/data-sources/application I can not access the internal_host
directly like with databases.
I then tried to get the internal host from the built_in_environment_variables
, but this get’s quite complicated.
I would need to search for the variable QOVERY_APPLICATION_{SOME_ID_BACKEND}_HOST_INTERNAL
, but there’s also QOVERY_APPLICATION_{SOME_ID_FRONTEND}_HOST_INTERNAL
.
As I do not know where to get that {SOME_ID_BACKEND}
value from, I can not use the terraform index function like:
value = element(
qovery_application.backend.built_in_environment_variables,
index(qovery_application.backend.built_in_environment_variables.*.key, "QOVERY_APPLICATION_${that_mysterious_identifier}_HOST_INTERNAL")
).value
But as I do not have that mysterious identifier, I need to use some crazy trick: I first fetch the env var of the application name (as I have that one), then replace “_NAME” by “_HOST_INTERNAL” in the key … and then I can search for the env var object.
Looks something like:
# this finds the "QOVERY_APPLICATION_{SOME_ID}_HOST_INTERNAL" env var based on the constructed _HOST_INTERNAL variable
element(
tolist(qovery_application.backend.built_in_environment_variables),
index(
tolist(qovery_application.backend.built_in_environment_variables.*.key),
replace(
# this finds the "QOVERY_APPLICATION_{SOME_ID}_NAME" env var
element(
tolist(qovery_application.backend.built_in_environment_variables),
index(
tolist(qovery_application.backend.built_in_environment_variables.*.value),
qovery_application.backend.name
)
).key,
"_NAME",
"_HOST_INTERNAL"
)
)
)
As I am quite new to terraform and qovery, I want to ask you: Is there a better way?
Thanks in advance!
Best,
Pierre