The Google Cloud Platform (GCP) Provider enables you to manage resources in Google Cloud using Terraform. Whether you’re deploying Compute Engine instances, configuring storage buckets, or managing Kubernetes clusters, this provider offers robust capabilities to automate and scale your infrastructure.
Key Features:
Example Use Case: Creating a Compute Engine Instance
Compute Engine instances are virtual machines running in GCP. Here’s how to create one using the Google Provider:
provider "google" {
project = "my-gcp-project"
region = "us-central1"
}
resource "google_compute_instance" "example" {
name = "example-instance"
machine_type = "e2-medium"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = "debian-cloud/debian-10"
}
}
network_interface {
network = "default"
access_config {}
}
tags = ["web", "dev"]
}
What’s Happening Here?
provider
block configures Terraform to use the GCP project my-gcp-project
in the us-central1
region.google_compute_instance
resource creates a virtual machine named example-instance
with the e2-medium
machine type.web
and dev
are added for organization and firewall rules.Advanced Tip:
Use instance templates for consistent and scalable deployments:
resource "google_compute_instance_template" "example_template" {
name = "example-template"
machine_type = "e2-medium"
disk {
source_image = "debian-cloud/debian-10"
auto_delete = true
boot = true
}
network_interface {
network = "default"
access_config {}
}
tags = ["web", "dev"]
}
This template can be reused for managed instance groups, enabling automatic scaling of your virtual machines.