Skip to content

GCP.ServiceUsage reference

Source: packages/gcp/src/ServiceUsage/ProjectService.ts

Enables a Google Cloud API for a project — the GCP analog of a Terraform google_project_service.

Service Usage has no per-caller ownership marker, so an API that is already enabled (by another stack, the console, or a dependent service) is adopted as-is. By default destroy only releases Alchemy state and leaves the API enabled. Set disableOnDestroy only for APIs this stack alone relies on: it disables the API project-wide, even if it was enabled before this stack adopted it.

Enable Compute Engine before creating a network

const computeApi = yield* GCP.ServiceUsage.ProjectService("ComputeApi", {
service: "compute.googleapis.com",
});

Disable the API on destroy

yield* GCP.ServiceUsage.ProjectService("TranslateApi", {
service: "translate.googleapis.com",
disableOnDestroy: true,
});

ProjectService: Looking up an existing project service

Section titled “ProjectService: Looking up an existing project service”

ProjectService.lookup references a project service Alchemy doesn’t manage (created in the console or by another stack). It is read during plan/deploy, never created, updated or deleted, and binds like a declared project service.

const projectService = GCP.ServiceUsage.ProjectService.lookup({
service: "my-service",
});