How do I build a GCP storage bucket with Pulumi?
In this guide, we will create a Google Cloud Storage bucket using Pulumi in TypeScript. We will define the necessary resources, including the storage bucket, and configure it with some basic settings.
Key Points:
- We will use Pulumi to define and deploy the infrastructure.
- The storage bucket will be created in a specified location.
- We will configure versioning and other optional settings for the bucket.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
// Create a Google Cloud Storage bucket
const bucket = new gcp.storage.Bucket("my-bucket", {
location: "US",
versioning: {
enabled: true,
},
lifecycleRules: [{
action: {
type: "Delete",
},
condition: {
age: 365,
},
}],
website: {
mainPageSuffix: "index.html",
notFoundPage: "404.html",
},
});
// Export the bucket name
export const bucketName = bucket.name;
Summary:
In this guide, we created a Google Cloud Storage bucket using Pulumi in TypeScript. We specified the bucket’s location, enabled versioning, and added a lifecycle rule to delete objects older than one year. We also configured the bucket to serve a static website with custom main and 404 pages. Finally, we exported the bucket name for reference.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank 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.