Skip to main content

Google Cloud Functions in Go deployed with Go

A minimal Go Pulumi program using Google Cloud Functions.

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set gcp-go-functions
cd pulumi-examples/gcp-go-functions

This example deploys a Google Cloud Function implemented in Go. The Pulumi program is also implemented in Go.

Prerequisites#

  1. Install Pulumi
  2. Configure GCP credentials and set up a service account
  3. Install Go

Deploying the example#

  1. Create a new stack, which is an isolated deployment target for this example:

    Terminal window
    pulumi stack init dev
  2. Set the GCP project and region:

    Terminal window
    pulumi config set gcp:project <gcp-project>
    pulumi config set gcp:region <gcp-region>
  3. Install dependencies:

    Terminal window
    go mod download
  4. Execute the Pulumi program to deploy your function:

    Terminal window
    pulumi up
  5. Test your function by curl-ing the trigger URL:

    Terminal window
    curl $(pulumi stack output function)
    "Hello World!"
  6. From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your function.

Cleaning up#

Once you are done, you can destroy all of the resources, and the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.