Google API Gateway API

This page shows how to write Terraform for API Gateway API and write them securely.

google_api_gateway_api (Terraform)

The API in API Gateway can be configured in Terraform with the resource name google_api_gateway_api. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L1
resource "google_api_gateway_api" "api_baas" {
  provider = google-beta
  api_id = var.api_id
  display_name = var.display_name
  project = var.project_id
  labels = var.labels
api.tf#L1
resource "google_api_gateway_api" "api" {
  provider = google-beta
  api_id   = "api"
}

resource "google_api_gateway_gateway" "api_gateway" {
api_gateway.tf#L7
resource "google_api_gateway_api" "api_gw" {
  provider     = google-beta
  api_id       = local.api_gateway_container_id
  display_name = "The API Gateway"

}
gateway.tf#L1
resource "google_api_gateway_api" "webhook" {
  api_id   = "tfc-notifications"
  display_name = "Terraform Cloud Notifications Webhook API"
  provider = google-beta
}

main.tf#L8
resource "google_api_gateway_api" "shopping-list-api-gateway" {
  provider = google-beta
  api_id = "shopping-list"
}

resource "google_api_gateway_api_config" "shopping-list-api-config" {

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The following arguments are supported:

  • api_id - (Required) Identifier to assign to the API. Must be unique within scope of the parent resource(project)

  • display_name - (Optional) A user-visible name for the API.

  • managed_service - (Optional) Immutable. The name of a Google Managed Service ( https://cloud.google.com/service-infrastructure/docs/glossary#managed). If not specified, a new Service will automatically be created in the same project as this API.

  • labels - (Optional) Resource labels to represent user-provided metadata.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format projects/[[project]]/locations/global/apis/[[api_id]]

  • name - The resource name of the API. Format projects/[[project]]/locations/global/apis/[[apiId]]

  • create_time - Creation timestamp in RFC3339 text format.

Explanation in Terraform Registry

A consumable API that can be used by multiple Gateways.

Warning: This resource is in beta, and should be used with the terraform-provider-google-beta provider. See Provider Versions for more details on beta resources. To get more information about Api, see:

Frequently asked questions

What is Google API Gateway API?

Google API Gateway API is a resource for API Gateway of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google API Gateway API?

For Terraform, the dikshant99/terraform-gcp, adispen/gcp-apigateway-custom-domain and femrtnz/google-cloud-api-gateway source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.