Terraform – API Gateway – How to get internal host of applications

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

Hi @hedgehogs-mind ,

Indeed, it’s a missing parameter, and I will add it to our Terraform provider.

This way is too complex, and it’s good you tried to workaround what we missed to add. But no worries, you don’t need to do this. I will add the internal_host and external_host properties next week.

1 Like

Thanks, looking forward to it! :blush:

Best,
Pierre

1 Like

Hello @hedgehogs-mind

We’ve just added those two fields internal_host & external_host to the application resource in the latest version of our terraform provider (v0.8.0).

The documentation has been updated as well.

Let us know if this works for you.

Kind regards,
Bilel

1 Like

Thanks @bilel !

I will test it later together with this here:

You’ll hear from me :slight_smile:

Best,
Pierre

1 Like