google_api_gateway_test/terraform/gateway.tf

47 lines
1.4 KiB
Terraform
Raw Normal View History

2024-10-16 03:03:52 +00:00
resource "random_uuid" "jwt_client_id" {
}
2024-10-16 01:37:12 +00:00
resource "google_api_gateway_api" "api" {
provider = google-beta
project = google_project.project.project_id
api_id = "the-gateway"
depends_on = [google_project_service.service["apigateway"], ]
}
resource "google_api_gateway_api_config" "api_config" {
provider = google-beta
project = google_project.project.project_id
api = google_api_gateway_api.api.api_id
api_config_id = "api-config"
openapi_documents {
document {
2024-10-16 03:03:52 +00:00
path = "spec.yaml"
contents = base64encode(templatefile("openapi_spec.yaml", { backend_url = google_cloud_run_v2_service.api_server.uri, client_id = random_uuid.jwt_client_id.result }))
2024-10-16 01:37:12 +00:00
}
}
}
resource "google_api_gateway_gateway" "gateway" {
provider = google-beta
project = google_project.project.project_id
api_config = google_api_gateway_api_config.api_config.id
gateway_id = "gateway-to-the-api"
2024-10-16 03:03:52 +00:00
# Delete this when api_config changes, otherwise if api_config needs to be replaced, it errors out because it is "in use" by this gateway. I wish this could be triggered only when api_config is being replaced instead of all edits.
lifecycle {
replace_triggered_by = [
google_api_gateway_api_config.api_config
]
}
2024-10-16 01:37:12 +00:00
}
output "gateway_address" {
value = google_api_gateway_gateway.gateway.default_hostname
}
2024-10-16 03:03:52 +00:00
output "client_id" {
value = random_uuid.jwt_client_id.result
}