OpenMCF logoOpenMCF

Loading...

GCP Cloud Function

Deploys a Google Cloud Function (Gen 2) from source code stored in a GCS bucket, with full control over runtime, compute resources, scaling, networking, secrets, and trigger configuration. Gen 2 functions are built on Cloud Run and Eventarc, supporting both HTTP and event-driven invocation patterns.

What Gets Created

When you deploy a GcpCloudFunction resource, OpenMCF provisions:

  • Cloud Function (Gen 2) — a cloudfunctionsv2.Function in the specified project and region, built from a source archive in GCS, with the configured runtime, entry point, service config, and labels applied
  • Service Configuration — compute resources (memory, timeout, concurrency), environment variables, secret references, VPC connector, ingress/egress settings, and scaling limits applied to the underlying Cloud Run service
  • Event Trigger — an Eventarc trigger created when trigger.triggerType is EVENT_TRIGGER, with event type, filters, Pub/Sub topic, retry policy, and trigger service account configured
  • IAM Policy Binding — a cloudrunv2.ServiceIamMember granting roles/run.invoker to allUsers when serviceConfig.allowUnauthenticated is true (HTTP triggers only)

Prerequisites

  • GCP credentials configured via environment variables or OpenMCF provider config
  • A GCP project where the Cloud Function will be created
  • A GCS bucket containing the source code archive (.zip file with function code and dependencies)
  • Cloud Functions API and Cloud Build API enabled in the target project
  • A VPC connector if connecting the function to a VPC network (optional)
  • Secret Manager secrets if using secretEnvironmentVariables (optional)

Quick Start

Create a file cloud-function.yaml:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudFunction
metadata:
  name: my-http-handler
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: dev.GcpCloudFunction.my-http-handler
spec:
  projectId: my-gcp-project-123
  region: us-central1
  buildConfig:
    runtime: python312
    entryPoint: hello_http
    source:
      bucket: my-functions-source
      object: functions/hello-v1.0.0.zip

Deploy:

openmcf apply -f cloud-function.yaml

This creates a Gen 2 Cloud Function with an HTTP trigger, 256 MB memory, 60-second timeout, and default scaling (0-100 instances).

Configuration Reference

Required Fields

FieldTypeDescriptionValidation
projectIdstring or valueFromGCP project ID where the function is created. Can be a literal value or a reference to a GcpProject resource.Required
regionstringRegion where the function is deployed (e.g., us-central1, europe-west1).Required, pattern ^[a-z]+-[a-z]+[0-9]$
buildConfigGcpCloudFunctionBuildConfigBuild configuration for the function.Required
buildConfig.runtimestringRuntime environment. Examples: python312, nodejs22, go122, java21, dotnet8.Required, must be a supported Gen 2 runtime
buildConfig.entryPointstringName of the function in source code that is executed.Required, 1-128 chars
buildConfig.sourceGcpCloudFunctionSourceSource code location in GCS.Required
buildConfig.source.bucketstringGCS bucket name containing the source archive.Required, pattern ^[a-z0-9][a-z0-9._-]{1,61}[a-z0-9]$
buildConfig.source.objectstringObject path of the source archive in the bucket (e.g., functions/my-func-v1.zip).Required, min 1 char

Optional Fields

FieldTypeDefaultDescription
functionNamestringmetadata.nameOverride the Cloud Function name. Must be 1-63 chars, lowercase, start with a letter.
buildConfig.source.generationint64latestSpecific GCS object generation number. If omitted, uses the latest version.
buildConfig.buildEnvironmentVariablesmap<string, string>{}Environment variables available during the build process.
serviceConfigGcpCloudFunctionServiceConfigsee defaultsRuntime service configuration.
serviceConfig.serviceAccountEmailstringdefault compute SAService account the function runs as. Format: {id}@{project}.iam.gserviceaccount.com.
serviceConfig.availableMemoryMbint32256Memory in MB. Valid: 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768.
serviceConfig.timeoutSecondsint3260Execution timeout in seconds. Range: 1-3600.
serviceConfig.maxInstanceRequestConcurrencyint3280Max concurrent requests per instance. Range: 1-1000.
serviceConfig.environmentVariablesmap<string, string>{}Plain-text environment variables injected at runtime.
serviceConfig.secretEnvironmentVariablesmap<string, string>{}Secret Manager references as KEY: secret_name. Version latest is used automatically.
serviceConfig.vpcConnectorstring""VPC connector resource path. Format: projects/{project}/locations/{region}/connectors/{name}.
serviceConfig.vpcConnectorEgressSettingsenumPRIVATE_RANGES_ONLYVPC egress routing. One of: PRIVATE_RANGES_ONLY, ALL_TRAFFIC.
serviceConfig.ingressSettingsenumALLOW_ALLIngress control. One of: ALLOW_ALL, ALLOW_INTERNAL_ONLY, ALLOW_INTERNAL_AND_GCLB.
serviceConfig.scalingGcpCloudFunctionScalingConfig{}Scaling limits.
serviceConfig.scaling.minInstanceCountint320Minimum warm instances. Range: 0-100. Set > 0 to eliminate cold starts.
serviceConfig.scaling.maxInstanceCountint32100Maximum instances. Range: 1-3000.
serviceConfig.allowUnauthenticatedboolfalseIf true, grants roles/run.invoker to allUsers (HTTP triggers only).
triggerGcpCloudFunctionTriggerHTTPTrigger configuration. Defaults to HTTP trigger if omitted.
trigger.triggerTypeenumHTTPTrigger type. One of: HTTP, EVENT_TRIGGER.
trigger.eventTriggerGcpCloudFunctionEventTrigger—Event trigger config. Required when triggerType is EVENT_TRIGGER.
trigger.eventTrigger.eventTypestring—CloudEvents event type (e.g., google.cloud.pubsub.topic.v1.messagePublished). Required for event triggers.
trigger.eventTrigger.pubsubTopicstring""Pub/Sub topic resource name. Format: projects/{project}/topics/{topic}.
trigger.eventTrigger.eventFiltersGcpCloudFunctionEventFilter[][]Event attribute filters.
trigger.eventTrigger.eventFilters[].attributestring—Attribute name (e.g., bucket for Storage events).
trigger.eventTrigger.eventFilters[].valuestring—Value to match. Supports wildcards.
trigger.eventTrigger.eventFilters[].operatorstringexact matchMatch operator. Use match-path-pattern for Firestore document paths.
trigger.eventTrigger.triggerRegionstringsame as regionRegion where the event trigger listens.
trigger.eventTrigger.retryPolicyenumRETRY_POLICY_DO_NOT_RETRYRetry behavior. One of: RETRY_POLICY_DO_NOT_RETRY, RETRY_POLICY_RETRY.
trigger.eventTrigger.serviceAccountEmailstringdefault Eventarc SAService account used by Eventarc to invoke the function.

Examples

HTTP Function with Custom Memory and Timeout

A Python function with increased memory, a longer timeout, and a dedicated service account:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudFunction
metadata:
  name: image-resizer
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: dev.GcpCloudFunction.image-resizer
spec:
  projectId: my-gcp-project-123
  region: us-central1
  buildConfig:
    runtime: python312
    entryPoint: resize_image
    source:
      bucket: my-functions-source
      object: functions/image-resizer-v2.1.0.zip
  serviceConfig:
    serviceAccountEmail: image-resizer@my-gcp-project-123.iam.gserviceaccount.com
    availableMemoryMb: 1024
    timeoutSeconds: 300
    maxInstanceRequestConcurrency: 10
    environmentVariables:
      OUTPUT_BUCKET: processed-images-dev
      MAX_WIDTH: "1920"
    scaling:
      minInstanceCount: 1
      maxInstanceCount: 50

Pub/Sub Event-Driven Function

A Node.js function triggered by messages published to a Pub/Sub topic, with retry enabled:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudFunction
metadata:
  name: order-processor
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: prod.GcpCloudFunction.order-processor
spec:
  projectId: my-gcp-project-123
  region: us-central1
  buildConfig:
    runtime: nodejs22
    entryPoint: processOrder
    source:
      bucket: my-functions-source
      object: functions/order-processor-v3.0.1.zip
  serviceConfig:
    serviceAccountEmail: order-processor@my-gcp-project-123.iam.gserviceaccount.com
    availableMemoryMb: 512
    timeoutSeconds: 120
    environmentVariables:
      DB_HOST: 10.0.0.5
    secretEnvironmentVariables:
      DB_PASSWORD: order-db-password
    scaling:
      minInstanceCount: 2
      maxInstanceCount: 200
  trigger:
    triggerType: EVENT_TRIGGER
    eventTrigger:
      eventType: google.cloud.pubsub.topic.v1.messagePublished
      pubsubTopic: projects/my-gcp-project-123/topics/new-orders
      retryPolicy: RETRY_POLICY_RETRY

Cloud Storage Event Function with VPC and Secrets

A Go function triggered when objects are created in a GCS bucket, connected to a VPC for private database access, with secrets from Secret Manager:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudFunction
metadata:
  name: file-indexer
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: prod.GcpCloudFunction.file-indexer
spec:
  projectId: my-gcp-project-123
  region: us-central1
  functionName: prod-file-indexer
  buildConfig:
    runtime: go122
    entryPoint: IndexFile
    source:
      bucket: my-functions-source
      object: functions/file-indexer-v1.4.0.zip
      generation: 1708012345678
    buildEnvironmentVariables:
      GOOGLE_BUILDPACKS_GO_BUILD_FLAGS: "-ldflags=-s -w"
  serviceConfig:
    serviceAccountEmail: file-indexer@my-gcp-project-123.iam.gserviceaccount.com
    availableMemoryMb: 2048
    timeoutSeconds: 540
    maxInstanceRequestConcurrency: 1
    environmentVariables:
      INDEX_TABLE: file_metadata
      LOG_LEVEL: info
    secretEnvironmentVariables:
      DB_CONNECTION_STRING: file-indexer-db-conn
      API_KEY: file-indexer-api-key
    vpcConnector: projects/my-gcp-project-123/locations/us-central1/connectors/main-connector
    vpcConnectorEgressSettings: PRIVATE_RANGES_ONLY
    ingressSettings: ALLOW_INTERNAL_ONLY
    scaling:
      minInstanceCount: 0
      maxInstanceCount: 500
    allowUnauthenticated: false
  trigger:
    triggerType: EVENT_TRIGGER
    eventTrigger:
      eventType: google.cloud.storage.object.v1.finalized
      eventFilters:
        - attribute: bucket
          value: incoming-documents-prod
      retryPolicy: RETRY_POLICY_RETRY
      serviceAccountEmail: eventarc-trigger@my-gcp-project-123.iam.gserviceaccount.com

Public HTTP Function with Foreign Key Reference

A publicly accessible function that references an OpenMCF-managed GcpProject for the project ID:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudFunction
metadata:
  name: webhook-receiver
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: prod.GcpCloudFunction.webhook-receiver
spec:
  projectId:
    valueFrom:
      kind: GcpProject
      name: my-project
      fieldPath: status.outputs.project_id
  region: europe-west1
  buildConfig:
    runtime: java21
    entryPoint: com.example.WebhookHandler
    source:
      bucket: my-functions-source
      object: functions/webhook-receiver-v2.0.0.zip
  serviceConfig:
    availableMemoryMb: 512
    timeoutSeconds: 30
    maxInstanceRequestConcurrency: 200
    ingressSettings: ALLOW_ALL
    scaling:
      minInstanceCount: 1
      maxInstanceCount: 100
    allowUnauthenticated: true

Stack Outputs

After deployment, the following outputs are available in status.outputs:

OutputTypeDescription
functionIdstringFully qualified resource name of the function. Format: projects/{project}/locations/{region}/functions/{name}
functionUrlstringHTTPS URL of the function. Only populated for HTTP-triggered functions; empty for event-driven functions.
serviceAccountEmailstringEmail of the service account the function runs as.
statestringCurrent state of the function. Possible values: ACTIVE, OFFLINE, DEPLOY_IN_PROGRESS, DELETE_IN_PROGRESS, UNKNOWN.
cloudRunServiceIdstringCloud Run service name backing this Gen 2 function. Format: projects/{project}/locations/{region}/services/{name}
eventarcTriggerIdstringEventarc trigger ID. Only populated for event-driven functions; empty for HTTP-triggered functions.

Related Components

  • GcpProject — provides the GCP project where the function is created
  • GcpServiceAccount — creates service accounts for serviceConfig.serviceAccountEmail and event trigger identity
  • GcpSecretsManager — manages secrets referenced in serviceConfig.secretEnvironmentVariables
  • GcpGcsBucket — stores the function source code archive and can be an event trigger source
  • GcpVpc — network for VPC connector used by serviceConfig.vpcConnector

Next article

GCP Cloud Run

GCP Cloud Run Deploys a Google Cloud Run v2 service with configurable container resources, autoscaling, VPC egress, and optional custom domain mapping with DNS verification. The component supports environment variables, Secret Manager references, and configurable ingress controls. What Gets Created When you deploy a GcpCloudRun resource, OpenMCF provisions: Cloud Run v2 Service — a googlecloudrunv2service with the specified container image, resource limits, scaling configuration, and ingress...
Read next article
Presets
2 ready-to-deploy configurationsView presets →