Skip to main content

GCP Terraform Module Reference

The nOps GCP Integration Terraform Module automates the GCP-side configuration — all IAM role grants and API enablement — in a single terraform apply.

Before Using Terraform

You must complete these manual steps first:

  1. Prerequisites — Configure billing exports in GCP
  2. Link GCP Billing Data to nOps — Create the integration in nOps to get the service account email

The Terraform module handles Step 2 (Grant Permissions) and Step 3 (Enable APIs) from the integration guide.


GitHub Repository

GitHub Repository

Repository: github.com/nops-io/terraform-gcp-nops-integration


What the Module Does

With a single module invocation, you can configure:

CategoryWhat Gets Configured
Organization IAMCloud Asset Viewer, Browser, Recommender Viewer, Logs Viewer, Compute Viewer, Container Viewer, Cloud SQL Viewer, Cloud Run Viewer
Billing Account IAMBilling Account Viewer
Project IAMService Usage Consumer
Dataset IAMBigQuery Data Viewer (on all 3 billing export datasets)
APIsCloud Asset, Cloud Billing, Recommender (+ optional BigQuery Reservation)

Quick Start

1. Create Configuration

Create a main.tf file:

terraform {
required_version = ">= 1.0"

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

provider "google" {
# Uses Application Default Credentials
# Run: gcloud auth application-default login
}

module "nops_gcp_integration" {
source = "github.com/nops-io/terraform-gcp-nops-integration"

# Required: Your GCP identifiers
organization_id = "123456789012"
billing_account_id = "XXXXXX-XXXXXX-XXXXXX"
billing_export_project_id = "your-billing-export-project"

# Required: nOps service account email (from nOps integration setup)
nops_service_account_email = "your-nops-sa@project.iam.gserviceaccount.com"

# Required: BigQuery dataset IDs for billing exports
bigquery_detailed_usage_cost_dataset_id = "project-id:dataset_name"
bigquery_pricing_dataset_id = "project-id:dataset_name"
bigquery_committed_use_discounts_dataset_id = "project-id:dataset_name"
}

2. Apply

# Authenticate
gcloud auth application-default login

# Initialize and apply
terraform init
terraform plan
terraform apply

Input Variables

VariableDescriptionRequired
organization_idGCP Organization IDYes
billing_account_idGCP Billing Account IDYes
billing_export_project_idProject ID where billing exports are configured (where APIs are enabled)Yes
nops_service_account_emailnOps service account emailYes
bigquery_detailed_usage_cost_dataset_idDataset ID for Detailed Usage Cost exportYes
bigquery_pricing_dataset_idDataset ID for Pricing exportYes
bigquery_committed_use_discounts_dataset_idDataset ID for CUD exportYes
enable_bigquery_reservation_apiEnable BigQuery Reservation API (for flat-rate pricing)No (default: false)
grant_nops_iam_rolesGrant organization-level IAM rolesNo (default: true)
grant_nops_billing_iam_rolesGrant billing account IAM rolesNo (default: true)
grant_nops_project_iam_rolesGrant project-level IAM rolesNo (default: true)
grant_nops_bigquery_dataset_iam_rolesGrant BigQuery dataset IAM rolesNo (default: true)
enable_domain_restricted_sharingConfigure domain restricted sharing to nOpsno
nops_customer_idThe nOps Google Workspace Customer IDno

Finding Your IDs

gcloud organizations list

Use the ID column value.


Authentication

Recommended for local development:

gcloud auth application-default login

Required Permissions

The user or service account running Terraform needs:

LevelPermissions
Organizationresourcemanager.organizations.get, resourcemanager.projects.list, resourcemanager.organizationIamPolicies.set
Billing Accountbilling.accounts.getIamPolicy, billing.accounts.setIamPolicy
Projectserviceusage.services.enable, resourcemanager.projects.setIamPolicy
BigQuerybigquery.datasets.setIamPolicy

These can be granted via roles like roles/owner, roles/resourcemanager.organizationAdmin, or roles/billing.admin.


Troubleshooting

ErrorSolution
Permission deniedVerify your credentials have the required permissions listed above
Project not foundCheck that organization_id and billing_account_id are correct
APIs not enablingEnsure billing is enabled on the project; wait a few minutes for propagation
Domain restricted sharing errorAdd the nOps Customer ID to your organization's allowed domains (see Prerequisites)

OpenTofu Compatibility

This module works with both Terraform and OpenTofu. Simply replace terraform with tofu:

tofu init
tofu plan
tofu apply