Skip to content

Commit 376df06

Browse files
j0g3scmeshkodiak[bot]
authored andcommitted
adds carbon footprint data export module
1 parent 17c8157 commit 376df06

File tree

6 files changed

+85
-1
lines changed

6 files changed

+85
-1
lines changed

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ module "replicator_sa" {
2020

2121
billing_account_id = var.billing_account_id
2222
}
23+
24+
module "carbon_export" {
25+
source = "./modules/meshcloud-carbon-export/"
26+
27+
carbon_data_export_dataset_id = var.carbon_footprint_dataset_id
28+
carbon_data_export_project_id = var.cloud_billing_export_project_id # using the same project as for billing
29+
carbon_dataset_region = var.carbon_footprint_dataset_location
30+
31+
billing_account_id = var.billing_account_id
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
resource "google_project_service" "bigquery_api" {
2+
project = var.carbon_data_export_project_id
3+
service = "bigquery.googleapis.com"
4+
disable_on_destroy = false
5+
}
6+
7+
resource "google_project_service" "bigquerydatatransfer_api" {
8+
project = var.carbon_data_export_project_id
9+
service = "bigquerydatatransfer.googleapis.com"
10+
disable_on_destroy = false
11+
}
12+
13+
resource "google_bigquery_dataset" "carbon_data_export_dataset" {
14+
dataset_id = var.carbon_data_export_dataset_id
15+
friendly_name = "carbon_data_export_tf"
16+
description = "This dataset holds the carbon footprint data."
17+
location = var.carbon_dataset_region
18+
project = var.carbon_data_export_project_id
19+
}
20+
21+
resource "google_bigquery_data_transfer_config" "carbon_footprint_transfer_config" {
22+
display_name = "carbon-footprint-export-tf"
23+
location = var.carbon_dataset_region
24+
data_source_id = "61cede5a-0000-2440-ad42-883d24f8f7b8"
25+
schedule = "every day 00:00"
26+
destination_dataset_id = google_bigquery_dataset.carbon_data_export_dataset.dataset_id
27+
project = var.carbon_data_export_project_id
28+
params = {
29+
billing_accounts = var.billing_account_id
30+
}
31+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "carbon_footprint_export_table_name" {
2+
description = "The BigQuery table name containing the GCP Carbon Footprint BigQuery export."
3+
value = "${var.carbon_data_export_project_id}.${var.carbon_data_export_dataset_id}.${var.carbon_data_export_dataset_id}"
4+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
variable "carbon_dataset_region" {
2+
type = string
3+
description = "The location of the BigQuery dataset for carbon data exports."
4+
}
5+
6+
variable "billing_account_id" {
7+
type = string
8+
description = "The GCP Billing Account in your organization."
9+
}
10+
11+
variable "carbon_data_export_project_id" {
12+
type = string
13+
description = "GCP Project where the BiqQuery table resides that holds the Carbon Footprint export to BigQuery. See https://cloud.google.com/billing/docs/how-to/export-data-bigquery"
14+
}
15+
16+
variable "carbon_data_export_dataset_id" {
17+
type = string
18+
description = "GCP BigQuery dataset containing the Carbon Footprint BigQuery export. This variable is only required to form the output for meshPlatform configuration. No resources are created or attached."
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "hashicorp/google"
5+
version = "4.11.0"
6+
}
7+
}
8+
}

variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ variable "landing_zone_folder_ids" {
2525

2626
variable "cloud_billing_export_project_id" {
2727
type = string
28-
description = "GCP Project where the BiqQery table resides that holds the Cloud Billing export to BigQuery. See https://cloud.google.com/billing/docs/how-to/export-data-bigquery"
28+
description = "GCP Project where the BiqQuery table resides that holds the Cloud Billing export to BigQuery. See https://cloud.google.com/billing/docs/how-to/export-data-bigquery"
2929
}
3030

3131
variable "cloud_billing_export_dataset_id" {
@@ -54,3 +54,15 @@ variable "kraken_sa_name" {
5454
description = "Name of the service account to create for Kraken."
5555
default = "mesh-kraken-service-tf"
5656
}
57+
58+
variable "carbon_footprint_dataset_location" {
59+
type = string
60+
description = "Location of BigQuery dataset for carbon footprint."
61+
default = "us-west1"
62+
}
63+
64+
variable "carbon_footprint_dataset_id" {
65+
type = string
66+
description = "Id of BigQuery dataset for carbon footprint."
67+
default = "carbon_footprint_data"
68+
}

0 commit comments

Comments
 (0)