Create a public Cloud Storage bucket

Use IAM and Cloud Storage Terraform resources to create a public Cloud Storage bucket.

Code sample

Terraform

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands. For more information, see the Terraform provider reference documentation.

resource "random_id" "bucket_prefix" {
  byte_length = 8
}

resource "google_storage_bucket" "default" {
  provider                    = google
  name                        = "${random_id.bucket_prefix.hex}-example-bucket-name"
  location                    = "US"
  uniform_bucket_level_access = true
}

# Make bucket public
resource "google_storage_bucket_iam_member" "member" {
  provider = google
  bucket   = google_storage_bucket.default.name
  role     = "roles/storage.objectViewer"
  member   = "allUsers"
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.