CSCv0.10rz
GitHub

Terraform for GCP Buckets

A simple Terraform configuration for creating a Google Cloud Storage bucket.

Provider Configuration

Ensure you have authenticated with GCP CLI (gcloud auth application-default login).

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "4.51.0"
    }
  }
}

provider "google" {
  project = "your-gcp-project-id"
  region  = "us-central1"
}
Creating a Storage Bucket

This example creates a standard, multi-regional bucket.

resource "google_storage_bucket" "example_bucket" {
  name          = "your-unique-bucket-name"
  location      = "US"
  force_destroy = true # Set to false for production
  
  storage_class = "STANDARD"

  uniform_bucket_level_access = true

  versioning {
    enabled = true
  }

  labels = {
    env = "dev"
  }
}
Basic Terraform Commands Initialize Terraform
terraform init
Plan Changes
terraform plan
Apply Changes
terraform apply