This page explains how to provision API hub using Terraform for Google Cloud in Cloud Shell.
Terraform is an infrastructure-as-code tool that enables you to predictably create, change, and improve your cloud infrastructure by using code. For more information about using Terraform to provision infrastructure on Google Cloud, see Terraform on Google Cloud.
Register a host project. A host project is a Google Cloud project in your Apigee organization that you designate as the consumer project for all API hub resources. You can provision only one API hub instance per host project.
Replace PROJECT_ID with the ID of the Google Cloud project.
Grant the apihub.admin and apihub.runtimeProjectServiceAgent roles to the API hub default service account:
resource "google_project_iam_member" "apihub_service_identity_permission" {
for_each = toset([
"roles/apihub.admin",
"roles/apihub.runtimeProjectServiceAgent"
])
role = each.key
member = "serviceAccount:${google_project_service_identity.apihub_service_identity.email}"
depends_on = [google_project_service_identity.apihub_service_identity]
}
Optional: Grant the API hub service identity access to the CMEK key.
If you plan to provision an API hub instance with Custom Managed Encryption Keys (CMEK), you must enable the Cloud KMS API and grant the API hub service identity access to the CMEK key using:
API_HUB_INSTANCE_ID: the ID of the API hub instance.
DESCRIPTION: a description of the API hub instance.
HUB_LOCATION: the location of the API hub instance.
KEY_RING_ID: the ID of the CMEK key ring.
KEY_ID: the ID of the CMEK key.
SEMANTIC_SEARCH_BOOLEAN: false if you want to enable semantic search, true otherwise. For information about semantic search, see Search APIs.
VERTEX_AI_LOCATION: the location of the Vertex AI instance where the data is stored. See Vertex AI Locations for a list of supported locations.
Deploy the Terraform configuration by initializing Terraform, generating the planned changes, and applying these changes. After deploying the Terraform configuration, you can access the API hub instance in the Google Cloud console.
If you have recently deprovisioned API hub, you must wait 7 days before provisioning a new instance in the same Google Cloud project. This is because deprovisioning moves the associated Apigee organization (if any) to a soft-delete state for 7 days, and API hub can only be reprovisioned after the Apigee org is permanently deleted.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-02-23 UTC."],[],[]]