Skip to content

Create Cloud Storage with Terraform on Google Cloud

Objectives:

  • Understand the terraform{} block
  • Understand the provider{} block
  • Understand the resource{} block
  • Know how to activate Cloud Shell
  • Know how to create directory and file
  • Know to create a cloud storage bucket with Terraform on GCP

Prerequisite

  • Google Cloud Account

Tasks

  1. Login and activate the Google Cloud command line console.
  2. Create a directory named ‘ terraform’ and enter in.
  3. Create a file named ‘main.tf’ and enter the editor mode.
  4. Write the configuration file.
  5. Check and apply the file( in terminal ).
  6. Check the result in (user interface).

Code

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

provider "google" {

  project = "PROJECT ID"  #replace to your project id
  region  = "REGION"      #replae to your region
  zone    = "ZONE"        #replace to your zone
}

resource "google_storage_bucket" "static" {
 name          = "BUCKET_NAME"  # give your unique bucket name
 location      = "US"
 storage_class = "STANDARD"

}