From 43e0fa30c2a6c5fe2a6329aa914b160168b9f3ae Mon Sep 17 00:00:00 2001 From: lex00 <121451605+lex00@users.noreply.github.com> Date: Tue, 20 Oct 2026 22:13:30 -0600 Subject: [PATCH] gcp: CloudRunServiceComposite sets projectRef and location, which RunService requires (#4182) The composite built a RunService with no projectRef and an optional location, so WGC402 refused it, and an as-cast hid the type error. It now takes projectId and location, defaulting to GCP.ProjectId and GCP.Region, and the cast is gone. The doc example named a CloudRunService export that doesn't exist. --- lexicons/gcp/src/composites/catalog.ts | 8 +++++++- .../gcp/src/composites/cloud-run-service.ts | 17 ++++++++++++----- lexicons/gcp/src/composites/composites.test.ts | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lexicons/gcp/src/composites/catalog.ts b/lexicons/gcp/src/composites/catalog.ts index 8e397d0ea2..fd72e5b295 100644 --- a/lexicons/gcp/src/composites/catalog.ts +++ b/lexicons/gcp/src/composites/catalog.ts @@ -119,7 +119,13 @@ export const compositeCatalog: CompositeEntry[] = [ "name": "location", "type": "string", "required": false, - "description": "GCP region." + "description": "GCP region (default: GCP.Region, resolved from GCP_REGION at build)." + }, + { + "name": "projectId", + "type": "string", + "required": false, + "description": "GCP project the service runs in, as `projectRef.external` (default: GCP.ProjectId, resolved from GCP_PROJECT_ID at build)." }, { "name": "port", diff --git a/lexicons/gcp/src/composites/cloud-run-service.ts b/lexicons/gcp/src/composites/cloud-run-service.ts index 0d26770b42..f6116f9279 100644 --- a/lexicons/gcp/src/composites/cloud-run-service.ts +++ b/lexicons/gcp/src/composites/cloud-run-service.ts @@ -7,14 +7,17 @@ import { CloudRunService as CloudRunServiceResource, IAMPolicyMember, } from "../generated"; +import { GCP } from "../pseudo"; export interface CloudRunServiceProps { /** Service name. */ name: string; /** Container image. */ image: string; - /** GCP region. */ + /** GCP region (default: GCP.Region, resolved from GCP_REGION at build). */ location?: string; + /** GCP project the service runs in, as `projectRef.external` (default: GCP.ProjectId, resolved from GCP_PROJECT_ID at build). */ + projectId?: string; /** Port the container listens on (default: 8080). */ port?: number; /** CPU limit (default: "1000m"). */ @@ -47,10 +50,12 @@ export interface CloudRunServiceProps { * * @example * ```ts - * import { CloudRunService } from "@intentius/chant-lexicon-gcp"; + * import { CloudRunServiceComposite } from "@intentius/chant-lexicon-gcp"; * - * const { service, publicIam } = CloudRunService({ + * const { service, publicIam } = CloudRunServiceComposite({ * name: "my-api", + * projectId: "my-project", + * location: "us-central1", * image: "gcr.io/my-project/my-api:latest", * publicAccess: true, * }); @@ -61,6 +66,7 @@ export const CloudRunServiceComposite = Composite((props: CloudRunServiceProps) name, image, location, + projectId, port = 8080, cpuLimit = "1000m", memoryLimit = "512Mi", @@ -97,7 +103,8 @@ export const CloudRunServiceComposite = Composite((props: CloudRunServiceProps) ...(namespace && { namespace }), labels: { ...commonLabels, "app.kubernetes.io/component": "service" }, }, - ...(location && { location }), + location: location ?? GCP.Region, + projectRef: { external: projectId ?? GCP.ProjectId }, template: { maxInstanceRequestConcurrency, scaling: { @@ -106,7 +113,7 @@ export const CloudRunServiceComposite = Composite((props: CloudRunServiceProps) }, containers, }, - } as Record, defs?.service)); + }, defs?.service)); const result: Record = { service }; diff --git a/lexicons/gcp/src/composites/composites.test.ts b/lexicons/gcp/src/composites/composites.test.ts index 4119d8ccb1..b5fd4cb897 100644 --- a/lexicons/gcp/src/composites/composites.test.ts +++ b/lexicons/gcp/src/composites/composites.test.ts @@ -83,6 +83,23 @@ describe("CloudRunServiceComposite", () => { expect(result.service).toBeDefined(); }); + test("sets projectRef and location, which the RunService CRD requires", () => { + const result = CloudRunServiceComposite({ + name: "api", + image: "gcr.io/p/api:1", + projectId: "proj", + location: "us-central1", + }); + expect(p(result.service).projectRef).toEqual({ external: "proj" }); + expect(p(result.service).location).toBe("us-central1"); + }); + + test("defaults projectRef and location to the GCP pseudo-parameters", () => { + const result = CloudRunServiceComposite({ name: "api", image: "gcr.io/p/api:1" }); + expect(JSON.parse(JSON.stringify(p(result.service).projectRef))).toEqual({ external: { Ref: "GCP::ProjectId" } }); + expect(JSON.parse(JSON.stringify(p(result.service).location))).toEqual({ Ref: "GCP::Region" }); + }); + test("no public IAM by default", () => { const result = CloudRunServiceComposite({ name: "api", image: "gcr.io/p/api:1" }); expect(result.publicIam).toBeUndefined();