Search code examples
google-cloud-platformterraformopenapiapi-gateway

Can you use env variables in OpenAPI Spec for Google API Gateway?


I am trying to manage calling a function from different envs. The function addresses look like this

        address: https://us-central1-dev-name.cloudfunctions.net/functionName        
        address: https://us-central1-stg-name.cloudfunctions.net/functionName  
        address: https://us-central1-prd-name.cloudfunctions.net/functionName  

As you can see, the environment name is changing from dev to stg to prd. I would also like to use region variables as well for scalability.

I have consulted this relevant documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/api_gateway_api_config and https://cloud.google.com/api-gateway/docs/openapi-overview

I would like to reference env variables that are configured with my terraform configuration. Is this possible with openapi spec / api gateway?

I am fairly new to this topic so any advice would be greatly appreciated. Thank you.


Solution

  • I suspect that you cannot.

    I'm unfamiliar with Google API Gateway but familiar with Google Cloud Endpoints which is similar and also uses service specs.

    To solve this problem, I've templated my service specs and then I have a bash script that replaces (sed's) the VARIABLES with values before the service is deployed.