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
Login and activate the Google Cloud command line console.
Create a directory named ‘ terraform’ and enter in.
Create a file named ‘main.tf’ and enter the editor mode.
Write the configuration file.
Check and apply the file( in terminal ).
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"
}