Google Cloud YAML Starter
A minimal Google Cloud Pulumi YAML program
Before you begin#
For this walkthrough, you'll need:
- The Pulumi CLI
- The gcloud CLI (optional, but recommended and used in this guide)
- Permission to manage Cloud Storage
Create a new project#
This starter creates a Google Cloud Storage bucket in the US multi-region and exports the bucket’s gs:// URL.
mkdir my-project; cd my-projectpulumi new gcp-yamlmkdir my-project; cd my-projectpulumi new gcp-yamlThe pulumi new command walks you through creating and configuring the new project and stack. A stack is an instance of a project, and you can have many of them (dev, staging, prod), each with its own configuration settings. Depending on the language, you may also be asked for your preferred package manager or toolchain.
It also asks for the template’s setting, gcp:project. It has no default, so enter the ID of the Google Cloud project to deploy into:
| Key | Description | Default |
|---|---|---|
| gcp:project | The Google Cloud project to deploy into | — |
pulumi config set
:
pulumi config set gcp:project <value>pulumi config set gcp:project "<value>"Review the code#
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the resources it declares.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.
Take a moment to open them up and have a look. Here’s what’s in Pulumi.yaml:
name: my-projectdescription: A minimal Google Cloud Pulumi YAML programruntime: yamlresources: # Create a GCP resource (Storage Bucket) my-bucket: type: gcp:storage:Bucket properties: location: US
outputs: # Export the bucket's gs:// URL bucketName: ${my-bucket.url}Deploy the project#
Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.
Pulumi adds a random suffix to most resource names, so my-bucket becomes something like my-bucket-4f8a2c1. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
pulumi uppulumi upWhen it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist. This program exports the bucket’s gs:// URL. Read it any time with pulumi stack output <name>, or pass it to another command. This one prints the bucket’s details, including its name and location:
gcloud storage buckets describe $(pulumi stack output bucketName)gcloud storage buckets describe $(pulumi stack output bucketName)Need help?
If pulumi up reports failed to load application credentials, sign in again:
gcloud auth application-default logingcloud auth application-default loginStill stuck? Let us know.
Customize the project#
Put a file in the bucket. In Pulumi.yaml, add this below the bucket:
resources: # ... hello: type: gcp:storage:BucketObject properties: bucket: ${my-bucket.name} name: hello.txt content: Hello, Pulumi!Deploy again. The preview shows one object to create:
pulumi uppulumi upThen read the file back from the bucket. It prints Hello, Pulumi!:
gcloud storage cat "$(pulumi stack output bucketName)/hello.txt"gcloud storage cat "$(pulumi stack output bucketName)/hello.txt"To see what else you can add, browse the Google Cloud provider in the Pulumi Registry.
Cleaning up#
You can destroy the stack and all of its infrastructure with pulumi destroy, then remove the stack with pulumi stack rm:
pulumi destroypulumi stack rmpulumi destroypulumi stack rm