Home / Market / google cicd terraform

google cicd terraform

Architect, provision, and troubleshoot infrastructure on Google Cloud using Terraform. This skill ensures best practices like GCS backend usage and least-privilege IAM are followed. Enforces Google's Cloud Foundation Fabric patterns and rigorous validation protocols to ensure secure, idempotent, and scalable deployments across environments. Activate when the user requests infrastructure changes, pipeline design involving Terraform, or debugging Terraform issues. DO NOT use when deploying applica

skill★ 255660 dlgithubApache-2.0Install in CosmosUpstream Source

Documentation & Preview

--- name: google-cicd-terraform metadata: version: "1.0.0" category: DevOps description: >- Architect, provision, and troubleshoot infrastructure on Google Cloud using Terraform. This skill ensures best practices like GCS backend usage and least-privilege IAM are followed. Enforces Google's Cloud Foundation Fabric patterns and rigorous validation protocols to ensure secure, idempotent, and scalable deployments across environments. Activate when the user requests infrastructure changes, pipeline design involving Terraform, or debugging Terraform issues. DO NOT use when deploying application code or container images directly via gcloud or kubectl without Terraform (use google-cicd-deploy), designing high-level CI/CD architecture before choosing an IaC tool (use google-cicd-pipeline-design), or managing Cloud Deploy releases and rollouts via clouddeploy.yaml (use google-cicd-release-orchestration).

---

Terraform GCP Skill

Usage Attribution

MUST READ: Before executing any gcloud, REST API, or MCP command, you MUST read and follow the instructions in Usage Attribution.

This skill provides expert-level guidance for architecting, deploying, and managing GCP infrastructure using Terraform.

Prerequisites

Ensure the following prerequisites are satisfied before executing live commands:

Google Cloud SDK (gcloud), and attach an active billing account to the target project.

gcloud auth application-default login (or set GOOGLE_APPLICATION_CREDENTIALS for CI service accounts), then set the project and region (e.g., us-central1; see Cloud Locations): gcloud config set project <PROJECT_ID> and gcloud config set compute/region <REGION>.

gcloud services enable cloudresourcemanager.googleapis.com serviceusage.googleapis.com iam.googleapis.com storage.googleapis.com cloudbuild.googleapis.com developerconnect.googleapis.com artifactregistry.googleapis.com run.googleapis.com container.googleapis.com, and follow least-privilege IAM roles per iam-and-security.md.

🎯 When to Use This Skill

troubleshooting-gcp.md).

🏗️ Core Architecture: GCS Backend & State

Always use a GCS backend for state. Local state is strictly for local prototyping and must never be committed. If local state directory is used, add it to .gitignore.

Standard Backend Configuration

terraform {
  backend "gcs" {
    # Variables (var.*) are not allowed in backend blocks; set literal values
    # or pass via: terraform init -backend-config="bucket=tf-state-<PROJECT_ID>"
    bucket = "tf-state-<PROJECT_ID>"
    prefix = "terraform/state/<ENVIRONMENT>"
  }
}

Note: The GCS bucket must have Object Versioning enabled to allow recovery from accidental state corruption or overlapping writes.

Required Provider Version

Use the Google Cloud Terraform provider version 7.20.0 or higher. This skill utilizes features (e.g., Developer Connect) introduced in Google Provider v7.20.0.

terraform {
  required_version = ">= 1.6.0"

  required_providers {
    google = {
      source  = "hashicorp/google"
      version = ">= 7.20.0"
    }
  }
}

To retrieve the latest version of the Google provider, use the following command:

curl -s https://registry.terraform.io/v1/providers/hashicorp/google | jq -r .version

🛠️ Execution Protocol (Safety First)

The Agent must follow this lifecycle for every infrastructure change to ensure idempotency and prevent production outages:

  1. Initialize (terraform init):

.terraform.lock.hcl.

  1. Validate (terraform validate & tflint):

fields or non-optimal configurations.

  1. Plan (terraform plan -out=tfplan):

specifically highlighting any Destroy actions.

  1. Apply (terraform apply tfplan):

explicit manual confirmation.

🔍 Live Provider Documentation Lookup

To prevent hallucinations regarding new fields or deprecated attributes, the Agent must verify the grounded truth of the provider schema.

Schema Inspection via CLI

The primary command for retrieving the machine-readable schema of the currently initialized providers is:

$ terraform providers schema -json

🛡️ GCP-Specific Standards

  1. Resource Naming & "Main" Pattern: To maintain a clean module interface,

use the main identifier for singleton resources (the primary resource the module is named after). Use underscores for identifiers and hyphens for names (see naming-conventions.md).

    resource "google_compute_network" "main" {
      name                    = "${var.prefix}-vpc"
      auto_create_subnetworks = false
    }
  1. IAM Management (see

iam-and-security.md and gcp-networking-patterns.md):

and replaces the entire IAM policy for the project. It is the #1 cause of accidental lockouts.

a single member.

It's useful for managing all members of a role, but be aware it overwrites existing members for that role.

lives) and Service projects (where resources consume the network).

private_ip_google_access = true.

Account JSON keys.

  1. Cloud Build Triggers with Developer Connect: When using Developer

Connect git repository links, use developer_connect_event_config — NOT repository_event_config. The repository_event_config block is for Cloud Build v2 repository connections and will not work with Developer Connect resources. An example block to create a Cloud Build trigger with Developer Connect git repository link is as follows:

    resource "google_cloudbuild_trigger" "main" {
      developer_connect_event_config {
        git_repository_link = google_developer_connect_git_repository_link.main.id
        push {
          branch = var.trigger_branch
        }
      }
    }
  1. Developer Connect Connection (GitHub, GitLab, Bitbucket): When

configuring google_developer_connect_connection, configure the block matching the user's source control provider (github_config, github_enterprise_config, gitlab_config, gitlab_enterprise_config, bitbucket_cloud_config, or bitbucket_data_center_config). If using github_config, always set github_app to "DEVELOPER_CONNECT" (using "FIREBASE" is incorrect and will cause triggers to fail).

    resource "google_developer_connect_connection" "main" {
      location      = var.region
      connection_id = var.connection_id
      project       = var.project_id

      # Example for GitHub (use gitlab_config / bitbucket_cloud_config for GitLab / Bitbucket):
      github_config {
        github_app = "DEVELOPER_CONNECT" # CORRECT
        authorizer_credential {
          oauth_token_secret_version = "" # Populated after manual authorization
        }
      }

      depends_on = [google_project_service.main["developerconnect.googleapis.com"]]

      lifecycle {
        ignore_changes = [github_config[0].authorizer_credential]
      }
    }
  1. Developer Connect Git Repository Link: When configuring

google_developer_connect_git_repository_link, use parent_connection and git_repository_link_id as required arguments.

    resource "google_developer_connect_git_repository_link" "main" {
      location                = var.region
      parent_connection       = google_developer_connect_connection.main.connection_id
      git_repository_link_id  = "my-repo-link"
      clone_uri               = var.git_repo_uri
    }

📂 Directory Structure

Follow this standard (see style-and-structure.md) to ensure compatibility with Antigravity (AGY) discovery and Google best practices:

.
└── terraform/
    ├── main.tf              # Entry point / Resource definitions
    ├── variables.tf         # Typed variables with units and descriptions
    ├── outputs.tf           # Resource ID outputs (no direct input pass-through)
    ├── versions.tf          # Provider version pinning
    ├── network.tf           # (Optional) Grouped networking resources
    ├── examples/            # Example usage for modules
    ├── files/               # Static files (startup scripts, etc.)
    ├── templates/           # .tftpl templates
    ├── scripts/             # Scripts called by Terraform
    └── helpers/             # Scripts NOT called by Terraform

⚠️ Anti-Patterns (Do NOT do these)

google_cloudbuild_trigger. Always use developer_connect_event_config.

data "google_project" source.

Identity Federation or the default metadata server.

IAM roles instead.

type = string not type = STRING).

🧪 Testing Strategy

mocked plan validation and terraform test patterns.

configurations (e.g., public GCS buckets).

and network tags are correctly applied to resources before full deployment.

📚 Reference Guides

identifier and GCP naming rules.

formatting, and variable typing standards.

Workload Identity, and Secret Manager integration.

VPCs, Shared VPC, and Private Service Connect patterns.