The module creates an object storage bucket in Google Cloud Storage.

Allows configuring essential parameters:

  • toggle versioning
  • toggle access mode
  • attach externally defined IAM policies
  • configure storage class

Storage Bucket in GCP Cloud Storage

Storage Bucket management in GCP Cloud Storage
$300
BUY
311
Log in to Corewide IaC registry

Once you have a Corewide Solutions Portal account, this one-time action will use your browser session to retrieve credentials:

 shellterraform login solutions.corewide.com
Provision instructions

Initialize mandatory providers:

Copy and paste into your Terraform configuration and insert the variables:

 hclmodule "tf_gcp_storage_bucket" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-storage-bucket/google"
  version = "~> 1.0.0"

  # specify module inputs here or try one of the examples below
  ...
}

Initialize the setup:

 shellterraform init
Define update strategy

Corewide DevOps team strictly follows Semantic Versioning Specification to provide our clients with products that have predictable upgrades between versions. We recommend pinning patch versions of our modules using pessimistic constraint operator (~>) to prevent breaking changes during upgrades.

To get new features during the upgrades (without breaking compatibility), use ~> 1.0 and run terraform init -upgrade

For the safest setup, use strict pinning with version = "1.0.0"

v1.0.0 released 6 months, 3 weeks ago

Setup with custom configuration, versioning enabled, access_mode is private, policy assigned and a storage_class is multi_regional:

 hcldata "google_iam_policy" "policy1" {
  binding {
    role = "roles/storage.objectAdmin"

    members = [
      "user:[email protected]",
    ]
  }
}

data "google_iam_policy" "policy2" {
  binding {
    role = "roles/storage.objectViewer"

    members = [
      "user:[email protected]",
    ]
  }
}

module "bucket" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-storage-bucket/google"
  version = "~> 1.0"

  name          = "foo"
  region        = "us-central1"
  access_mode   = "private"
  storage_class = "multi_regional"

  bucket_policies = {
    policy1 = data.google_iam_policy.policy1.policy_data
    policy2 = data.google_iam_policy.policy2.policy_data
  }
}

Minimal setup with default parameters:

 hclmodule "bucket" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-storage-bucket/google"
  version = "~> 1.0"

  region = "us-central1"
  name   = "foo"
}

Simple configuration with publicly accessible storage:

 hclmodule "bucket" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-storage-bucket/google"
  version = "~> 1.0"

  name        = "foo"
  region      = "us-central1"
  access_mode = "public-read"
}
Variable Description Type Default Required Sensitive
name Storage bucket name. Maximum length is 63 characters (56 characters when add_random_suffix is enabled) string yes no
region GCP region to create resources in string yes no
access_mode Storage bucket access mode. Allowed values are 'public-read' or 'private' string private no no
add_random_suffix Append a random suffix to the bucket name to ensure uniqueness. Note: modifying this variable will trigger the re-creation of the bucket bool false no no
bucket_policies Valid IAM policy data to apply to the storage bucket in key-value format. Each key defines the policy name, and the value references an IAM policy document that specifies the roles and members for access control map(string) {} no no
storage_class The storage class for the bucket. Valid values are STANDARD, MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, and ARCHIVE string STANDARD no no
versioning Toggle bucket versioning bool true no no
Output Description Type Sensitive
bucket Contains all the Storage bucket attributes resource no
Dependency Version Kind
terraform >= 1.3 CLI
hashicorp/google ~> 6.3 provider
hashicorp/random ~> 3.3 provider

Not sure where to start?
Let's find your perfect match.