Terraform GCP Cloud Storage Config Builder

Generate Terraform HCL for a GCP Cloud Storage bucket

Build Terraform configuration for a Google Cloud Storage bucket — location, storage class, versioning, lifecycle rules, uniform access, public-access prevention, and an optional IAM member binding.

What is uniform bucket-level access?

Uniform bucket-level access disables per-object ACLs and uses only IAM for permissions. Google recommends it because it makes access control consistent and auditable. The builder enables it by default for safer permissions.

Provision a GCS bucket the Terraform way

Hand-writing google_storage_bucket HCL means remembering the right nested blocks for versioning, lifecycle, and access control. This builder assembles a correct, opinionated resource — secure defaults on, plus an optional IAM binding — that you can drop straight into your Terraform configuration.

How it works

The generated google_storage_bucket resource declares the bucket name, project, location, and storage_class. It sets uniform_bucket_level_access = true so permissions are governed entirely by IAM rather than legacy per-object ACLs, and enforces public_access_prevention to block accidental public exposure.

A versioning block keeps prior object generations, and an optional lifecycle_rule applies an action once objects reach a given age. Choosing Delete removes old objects, while choosing a storage class (Nearline, Coldline, Archive) emits a SetStorageClass action that tiers data down to cheaper storage. If you enable the IAM binding, a separate google_storage_bucket_iam_member grants a role to a member without overwriting other bindings.

Tips and notes

  • force_destroy is set to false so Terraform will refuse to delete a non-empty bucket — flip it to true only for disposable buckets.
  • Use google_storage_bucket_iam_member (additive) rather than ..._iam_policy (authoritative) unless you intend to manage the entire policy in Terraform.
  • Combine versioning with a lifecycle rule on noncurrent versions to control cost.
  • Bucket names are global; prefix them with your org or project to avoid 409 conflict errors on apply.