Get started with Pulumi and Google Cloud
Create a new project
A project is a program in your chosen language that defines a collection of related cloud resources. In this step, you will create a new project.
Initializing your project
Each project lives in its own directory. Create a new one:
$ mkdir quickstart
> mkdir quickstart
Change into the new directory:
$ cd quickstart
> cd quickstart
Now initialize a new Pulumi project for Google Cloud using the pulumi new command:
$ pulumi new gcp-typescript
> pulumi new gcp-typescript
$ pulumi new gcp-python
> pulumi new gcp-python
$ pulumi new gcp-go
> pulumi new gcp-go
$ pulumi new gcp-csharp
> pulumi new gcp-csharp
$ pulumi new gcp-java
> pulumi new gcp-java
$ pulumi new gcp-yaml
> pulumi new gcp-yaml
The pulumi new command interactively walks through initializing a new project, as well as creating a
stack and configuring it. A stack is an instance of your
project and you may have many of them – like dev, staging, and prod – each with different configuration settings.
You will be prompted for configuration values such as a Google Cloud project ID. You can hit ENTER to accept the defaults, or can type in your values:
gcp:project: The Google Cloud project to deploy into: my-gcp-project
After some dependency installations from npm, the project and stack will be ready.
After the command completes, the project and stack will be ready.
After the command completes, the project and stack will be ready.
After the command completes, the project and stack will be ready.
After the command completes, the project and stack will be ready.
After the command completes, the project and stack will be ready.
Review your new project’s contents
If you list the contents of your directory, you’ll see some key files:
src/main/java/myprojectis the project’s Java package root
contains your project’s main code that declares a Google Cloud Storage bucketindex.jsindex.tsmain.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlPulumi.yamlis a project file containing metadata about your project like its name
Pulumi.yamlis a project file containing metadata about your project, like its name, as well as declaring your project’s resources
Pulumi.dev.yamlcontains configuration values for the stack you just initialized
Now examine the code in index.jsindex.ts__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yaml
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
// Create a Google Cloud resource (Storage Bucket)
const bucket = new gcp.storage.Bucket("my-bucket", {
location: "US",
});
// Export the DNS name of the bucket
export const bucketName = bucket.url;
import pulumi
from pulumi_gcp import storage
# Create a Google Cloud resource (Storage Bucket)
bucket = storage.Bucket("my-bucket", location="US")
# Export the DNS name of the bucket
pulumi.export("bucket_name", bucket.url)
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/storage"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create a Google Cloud resource (Storage Bucket)
bucket, err := storage.NewBucket(ctx, "my-bucket", &storage.BucketArgs{
Location: pulumi.String("US"),
})
if err != nil {
return err
}
// Export the DNS name of the bucket
ctx.Export("bucketName", bucket.Url)
return nil
})
}
using Pulumi;
using Pulumi.Gcp.Storage;
using System.Collections.Generic;
return await Pulumi.Deployment.RunAsync(() =>
{
// Create a Google Cloud resource (Storage Bucket).
var bucket = new Bucket("my-bucket", new BucketArgs
{
Location = "US",
});
// Export the DNS name of the bucket.
return new Dictionary<string, object?>
{
["bucketName"] = bucket.Url,
};
});
package myproject;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.storage.Bucket;
import com.pulumi.gcp.storage.BucketArgs;
public class App {
public static void main(String[] args) {
Pulumi.run(ctx -> {
// Create a Google Cloud resource (Storage Bucket)
var bucket = new Bucket("my-bucket", BucketArgs.builder()
.location("US")
.build());
// Export the DNS name of the bucket
ctx.export("bucketName", bucket.url());
});
}
}
name: quickstart
runtime: yaml
description: A minimal Google Cloud Pulumi YAML program
resources:
# Create a Google Cloud resource (Storage Bucket)
my-bucket:
type: gcp:storage:Bucket
properties:
location: US
outputs:
# Export the DNS name of the bucket
bucketName: ${my-bucket.url}
This Pulumi program creates a new storage bucket resource and exports the DNS name of the bucket as a stack output. Resources are just objects in our language of choice with properties capturing their inputs and outputs. Exporting the bucket’s ID makes it convenient to use afterwards.
Next, you’ll deploy your stack, which will provision your storage bucket.
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.
