2

I'm using Terraform to deploy a containerized app on Cloud Run sitting behind API Gateway on GCP.

API Gateway on GCP requires an API spec, in which a backend parameter is used to direct traffic from the gateway to the Cloud Run function.

resource "google_api_gateway_api_config" "api_cfg" {
  provider = google-beta
  api = google_api_gateway_api.api_cfg.api_id
  api_config_id = "cfg"

  openapi_documents {
    document {
      path = "spec.yaml"  // <-- this spec needs the Cloud Run endpoint in it, which I don't know until the Cloud Run module is built...
      contents = filebase64("spec.yaml")
    }
  }
  lifecycle {
    create_before_destroy = true
  }
}

However, in a pure terraform implementation, the value of the backend service endpoint (Cloud Run in this case) is not known until after the apply.

In AWS it's possible to directly reference a backend lambda's ARN via a gateway <> lambda integration in a terraform module. Any ideas on how to emulate this functionality with the GCP equivalent?

I acknowledge the option of deploying the infra once to get the output values, then re-applying with only the gateway and modified api spec targeted. But this is certainly a less-than-ideal approach.

Dan
  • 6,022
  • 3
  • 20
  • 28
  • I've had to go with re-running terraform using cloudrun URLs from first-run output as input to the second pass. Not a pattern I enjoy employing so GCP team please consider adding this to roadmap! – Dan Oct 15 '22 at 07:18

0 Answers0