1.3.2 - Terraform Basics
Last updated Jan 25, 2025
Youtube Video | ~29 min
✍️ This video we set up a service account in our Google Cloud. We will then create a Main.tf file to configure our Google Cloud Infrastructure.
📜 Main.tf
Terraform provider for Google Cloud - The Google Cloud provider is used to configure your Google Cloud infrastructure.
To install this provider, copy and paste this code into your Terraform configuration. Then, run terraform init
.
Terraform 0.13+
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "6.17.0"
}
}
}
provider "google" {
# Configuration options
provider "google" {
project = "my-project-id"
region = "us-central1"
}
}
Where my-project-id
comes from your GCP Dashboard.
◼️ Terminal you can now run terraform init
+ Add a new bucket in Google cloud storage service (GCS) - in the same script append
resource "google_storage_bucket" "auto-expire" {
name = "auto-expiring-bucket"
location = "US"
force_destroy = true
lifecycle_rule {
condition {
age = 3
}
action {
type = "Delete"
}
}
lifecycle_rule {
condition {
age = 1
}
action {
type = "AbortIncompleteMultipartUpload"
}
}
}
Where auto-expire & name
need to be changed to a unique value, where name needs to be globally unique
◼️ Terminal you can now run terraform plan
and then terraform apply
👀 We can also generate the proposed changes and auto-executing the plan by using terraform apply -auto-approve
You should now see this bucket created on your GCP
◼️ Terminal you can now run terraform destroy
once you are done
Last updated