Last active
May 5, 2022 14:35
-
-
Save mikepietruszka/5812a01964e28e4fa5576bcee0c5227e to your computer and use it in GitHub Desktop.
Google Cloud Platform API Gateway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an API resource. It will hold our API config and API | |
# gateway. API gateway will have a URL that we will be able to hit. | |
resource "google_api_gateway_api" "api" { | |
provider = google-beta | |
api_id = "api" | |
} | |
# Create an API config that points the API at various | |
# Cloud Functions, Cloud Run instances, and their | |
# configurations. The config will be in openapi2-functions.yaml | |
# Note the limit of one config per gateway. | |
resource "google_api_gateway_api_config" "api_cfg" { | |
provider = google-beta | |
api = google_api_gateway_api.api.api_id | |
api_config_id = "api-config" | |
openapi_documents { | |
document { | |
path = "openapi2-functions.yaml" | |
contents = filebase64("openapi2-functions.yaml") | |
} | |
} | |
lifecycle { | |
create_before_destroy = true | |
} | |
gateway_config { | |
backend_config { | |
# Execute using an IAM Service Account | |
google_service_account = google_service_account.service_account.email | |
} | |
} | |
} | |
# API gateway resource will provide us with an endpoint (URL) and resource | |
# to access. We will get a gateway with the "gateway.dev" domain. | |
resource "google_api_gateway_gateway" "api_gw" { | |
provider = google-beta | |
api_config = google_api_gateway_api_config.api_cfg.id | |
gateway_id = "api-gw" | |
region = var.region | |
project = var.project_id | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment