Updated Nov 27, 20265 min read

Create a Google Cloud Storage Bucket Without Terraform

What a production Cloud Storage bucket needs beyond the create call, from uniform access and public access prevention to versioning and access for your app, how the console, gcloud and Terraform compare, and how to get a bucket in your own Google Cloud project from code.

Illustration for Create a Google Cloud Storage Bucket Without Terraform

Creating a Cloud Storage bucket is one command, which is why people reach for the console or gcloud first, and what takes longer is everything around it: a globally unique name, the location, uniform access, public access prevention, versioning, and a service account that may write to the bucket and sign URLs for it.

This guide lists what a bucket needs, shows the gcloud and Terraform versions for comparison, and then creates a bucket from application code, with the signed URLs a browser uses to upload and download.

What does a Cloud Storage bucket need?

PieceWhat to decide
Name and locationNames are global across Google Cloud, and the location can be a region, dual-region or multi-region
Access modelUniform bucket-level access, so IAM alone decides who can read and write
Public accessPublic access prevention on, unless the bucket serves a website
VersioningKeeps old versions of overwritten or deleted objects, at the cost of storage
Access for the appA service account with an object role on this bucket, not the whole project
Browser accessSigned URLs, or CORS rules if the browser calls Cloud Storage directly
LifecycleDelete old versions so storage does not grow without bound

The bucket naming rules apply across every project, which is why teams add a project or environment suffix. Google documents uniform bucket-level access and public access prevention as settings you choose per bucket, and signed URLs as the way to hand out time-limited access.

What are the options besides Terraform?

The console creates a bucket from a form with the same choices, and gcloud does it in two commands:

~
$ gcloud storage buckets create gs://acme-uploads-prod --location=europe-west1 \ --uniform-bucket-level-access --public-access-prevention$ gcloud storage buckets update gs://acme-uploads-prod --versioning

That leaves the application side undone: an IAM binding for the service account, signing code and a second bucket for staging with the same settings. The console and CLI are fine for one bucket, and they leave no record of what was changed, which is the gap Terraform fills.

What does the Terraform look like?

One resource carries the settings, and the IAM binding sits next to it:

resource "google_storage_bucket" "uploads" { name = "acme-uploads-prod" location = "EUROPE-WEST1" uniform_bucket_level_access = true public_access_prevention = "enforced" versioning { enabled = true } lifecycle_rule { condition { days_since_noncurrent_time = 30 } action { type = "Delete" } } } variable "app_service_account" { type = string } resource "google_storage_bucket_iam_member" "app" { bucket = google_storage_bucket.uploads.name role = "roles/storage.objectUser" member = "serviceAccount:${var.app_service_account}" }

The service account itself, the environment variable that tells the app the bucket name, the permission to sign URLs and a second copy of all this for staging come on top.

How does Encore create a bucket from code?

Encore brings infrastructure from code, so the bucket is declared next to the endpoints that use it and created in your own Google Cloud project on deploy, as the GCP infrastructure docs list under Cloud Storage. On AWS the same declaration becomes an S3 bucket, and the application code does not change.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create files --example=ts/hello-world$ cd files && mkdir -p reports

The reports folder also needs an encore.service.ts that exports new Service("reports"). The service hands out a signed upload URL, lists what has been uploaded and returns a signed download URL, and the bucket keeps old versions of overwritten files:

// reports/reports.ts import { api, APIError } from "encore.dev/api"; import { Bucket } from "encore.dev/storage/objects"; // A Cloud Storage bucket on GCP, an S3 bucket on AWS, local disk under `encore run`. const reports = new Bucket("reports", { versioned: true }); const SAFE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/; export const startUpload = api( { expose: true, method: "POST", path: "/reports/:name/upload-url" }, async ({ name }: { name: string }): Promise<{ url: string }> => { if (!SAFE_NAME.test(name)) throw APIError.invalidArgument("invalid file name"); const { url } = await reports.signedUploadUrl(name, { ttl: 900 }); return { url }; }, ); export const list = api( { expose: true, method: "GET", path: "/reports" }, async (): Promise<{ names: string[] }> => { const names: string[] = []; for await (const entry of reports.list({ limit: 100 })) { names.push(entry.name); } return { names }; }, ); export const getDownloadUrl = api( { expose: true, method: "GET", path: "/reports/:name/download-url" }, async ({ name }: { name: string }): Promise<{ url: string; size: number }> => { if (!SAFE_NAME.test(name)) throw APIError.invalidArgument("invalid file name"); if (!(await reports.exists(name))) throw APIError.notFound("report not found"); const attrs = await reports.attrs(name); const { url } = await reports.signedDownloadUrl(name, { ttl: 300 }); return { url, size: attrs.size }; }, );

encore run keeps bucket objects on local disk, so the whole flow works on a laptop with no Google Cloud project: request an upload URL, PUT a file to it with curl, then list and fetch the file back. The object storage docs cover public buckets, listing and deleting objects. Deploying goes through Connect your cloud account and a push, and the bucket appears in your project with the service allowed to use it. Teams bring their own agents, and Encore provides the environments, the system context and the controls, so an agent that adds a second bucket declares it in the same change and the deploy creates it.

Best fit: Teams that want Cloud Storage buckets and signed upload and download URLs in their own Google Cloud project, with the same code running locally.

Frequently asked questions

How do I create a Cloud Storage bucket without Terraform?

Run gcloud storage buckets create gs://BUCKET_NAME with --location, and add --uniform-bucket-level-access and --public-access-prevention to keep it private. Turn on versioning afterwards with gcloud storage buckets update --versioning, and grant your service account an object role on the bucket.

What are uniform bucket-level access and public access prevention?

Uniform bucket-level access turns off per-object ACLs so that IAM alone controls access to the bucket, and public access prevention blocks the bucket from being made public through IAM or ACLs. Both can be set when the bucket is created and are the usual defaults for application buckets.

How do users upload files to Cloud Storage without exposing credentials?

The backend generates a signed URL that allows a single PUT to one object for a short time, and the browser uploads straight to the bucket with it. The signing happens on the server with the service account, whose credentials never reach the browser.

How do I get a Cloud Storage bucket in my own Google Cloud project from application code?

With Encore you declare a bucket in the service code and use its signed URL methods, and deploying to your Google Cloud project creates the bucket for you. encore run keeps objects on local disk, so uploads and downloads can be tried on a laptop first.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders