Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 1.32 KB

readme.md

File metadata and controls

40 lines (34 loc) · 1.32 KB

Terraform-BigQuery Proxy

The purpose of this module is to execute queries in BigQuery using Terraform.

This can be useful for running stored procedures during the apply phase, or to dynamically generate the BigQuery schema basing on values from some tables.

Usage example:

# setup appropriate credentials 
data "google_service_account" "impersonatee" {
  account_id = "[email protected]"
}
resource "google_service_account_iam_member" "impersonatee-iam" {
  service_account_id = data.google_service_account.impersonatee.id
  role               = "roles/iam.serviceAccountTokenCreator"

  member = "[email protected]"
}
# obtain access token with appropriate scopes
data "google_service_account_access_token" "impersonatee" {
  target_service_account = data.google_service_account.impersonatee.id
  scopes                 = [
    "https://www.googleapis.com/auth/cloud-platform",
    "https://www.googleapis.com/auth/drive",
  ]
}
# perform query
module "bq_users" {
  source       = "git::https://github.com/GFN-CIS/tf-bq-proxy.git//tf-module"
  project_id   = var.project_id
  location     = var.location
  access_token = data.google_service_account_access_token.impersonatee.access_token
  query        = "SELECT users from datasets.users"

}

output "debug" {
  value = module.bq_proxy.result
}