Skip to content

Commit 783b3b7

Browse files
JohannesRudolphmeshkodiak[bot]
authored andcommitted
feat: remove carbon footprint export setup
see #10 for justification
1 parent 29a0783 commit 783b3b7

File tree

12 files changed

+83
-75
lines changed

12 files changed

+83
-75
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ To run this module, you need the following:
3232
# Only required when you need your landing zone to invoke a cloud function
3333
"cloudfunctions.functions.getIamPolicy",
3434
"cloudfunctions.functions.setIamPolicy",
35+
3536
# Only required for the optional submodule for exporting carbon data
3637
"resourcemanager.projects.update",
3738
"serviceusage.services.enable",
38-
"bigquery.transfers.update"
39-
39+
"bigquery.datasets.get",
40+
"bigquery.datasets.update"
4041
```
4142
4243
Organization-level:
@@ -118,6 +119,12 @@ resource "google_project" "meshstack_root" {
118119
The replicator service account needs the "Groups Admin" role from the Admin Console (Workspace) to manage permissions for managed GCP projects.
119120
To authorize the Service Account **via the Google Admin Console** navigate to `@Account` in the sidebar and then `Admin Roles -> Groups Admin` and click `Assign Service Accounts`. In the prompt that appears, enter the service account email, which looks like `user@project.iam.gserviceaccount.com`.
120121

122+
6. Optional: Enable GCP Cloud Carbon Footprint Export Transfer
123+
124+
When configuring the module with `carbon_export_module_enabled = true`, you need to manually set up the GCP
125+
data transfer config.
126+
127+
121128
## Example Usages
122129

123130
Check [examples](./examples/) for different use cases. As a quick start we recommend using [basic-gcp-integration](./examples/basic-gcp-integration) example.
@@ -162,11 +169,11 @@ No resources.
162169
| <a name="input_billing_account_id"></a> [billing\_account\_id](#input\_billing\_account\_id) | The GCP billing account in your organization. | `string` | n/a | yes |
163170
| <a name="input_billing_org_id"></a> [billing\_org\_id](#input\_billing\_org\_id) | GCP organization ID that holds billing account. | `string` | n/a | yes |
164171
| <a name="input_carbon_export_module_enabled"></a> [carbon\_export\_module\_enabled](#input\_carbon\_export\_module\_enabled) | Determines whether or not to include the resources of the carbon footprint export module. | `bool` | `false` | no |
165-
| <a name="input_carbon_footprint_dataset_id"></a> [carbon\_footprint\_dataset\_id](#input\_carbon\_footprint\_dataset\_id) | Id of BigQuery dataset for carbon footprint. | `string` | `"carbon_footprint_data"` | no |
166-
| <a name="input_carbon_footprint_dataset_location"></a> [carbon\_footprint\_dataset\_location](#input\_carbon\_footprint\_dataset\_location) | Location of BigQuery dataset for carbon footprint. | `string` | `"us-west1"` | no |
167-
| <a name="input_cloud_billing_export_dataset_id"></a> [cloud\_billing\_export\_dataset\_id](#input\_cloud\_billing\_export\_dataset\_id) | GCP BigQuery dataset containing the Cloud Billing BigQuery export. This variable is only required to form the output for meshPlatform configuration. No resources are created or attached. | `string` | n/a | yes |
172+
| <a name="input_cloud_billing_export_dataset_id"></a> [cloud\_billing\_export\_dataset\_id](#input\_cloud\_billing\_export\_dataset\_id) | GCP BigQuery dataset containing the Cloud Billing BigQuery export. | `string` | n/a | yes |
168173
| <a name="input_cloud_billing_export_project_id"></a> [cloud\_billing\_export\_project\_id](#input\_cloud\_billing\_export\_project\_id) | 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 | `string` | n/a | yes |
169174
| <a name="input_cloud_billing_export_table_id"></a> [cloud\_billing\_export\_table\_id](#input\_cloud\_billing\_export\_table\_id) | GCP BigQuery table containing the Cloud Billing BigQuery export. This variable is only required to form the output for meshPlatform configuration. No resources are created or attached. | `string` | n/a | yes |
175+
| <a name="input_cloud_carbon_export_dataset_id"></a> [cloud\_carbon\_export\_dataset\_id](#input\_cloud\_carbon\_export\_dataset\_id) | GCP BigQuery dataset containing the Cloud Carbon Footprint BigQuery export. | `string` | n/a | yes |
176+
| <a name="input_cloud_carbon_export_project_id"></a> [cloud\_carbon\_export\_project\_id](#input\_cloud\_carbon\_export\_project\_id) | GCP Project where the BiqQuery table resides that holds the Cloud Carbon Footprint export to BigQuery. | `string` | n/a | yes |
170177
| <a name="input_kraken_sa_name"></a> [kraken\_sa\_name](#input\_kraken\_sa\_name) | Name of the service account to create for Kraken. | `string` | `"mesh-kraken-service-tf"` | no |
171178
| <a name="input_landing_zone_folder_ids"></a> [landing\_zone\_folder\_ids](#input\_landing\_zone\_folder\_ids) | GCP Folders that make up the Landing Zone. The service account will only receive permissions on these folders. | `list(string)` | n/a | yes |
172179
| <a name="input_org_id"></a> [org\_id](#input\_org\_id) | GCP Organization ID that holds the projects that generate billing data that the service account should import. | `string` | n/a | yes |
@@ -177,7 +184,9 @@ No resources.
177184

178185
| Name | Description |
179186
|------|-------------|
187+
| <a name="output_carbon_footprint_export_manual_setup"></a> [carbon\_footprint\_export\_manual\_setup](#output\_carbon\_footprint\_export\_manual\_setup) | GCP Cloud Carbon Footprint BigQuery export manual setup information. |
180188
| <a name="output_carbon_footprint_export_table_name"></a> [carbon\_footprint\_export\_table\_name](#output\_carbon\_footprint\_export\_table\_name) | The BigQuery table name containing the GCP Carbon Footprint BigQuery export. |
189+
| <a name="output_cloud_billing_export_manual_setup"></a> [cloud\_billing\_export\_manual\_setup](#output\_cloud\_billing\_export\_manual\_setup) | GCP Cloud Billing BigQuery export manual setup information. |
181190
| <a name="output_cloud_billing_export_table_name"></a> [cloud\_billing\_export\_table\_name](#output\_cloud\_billing\_export\_table\_name) | The BigQuery table name containing the GCP Cloud Billing BigQuery export. |
182191
| <a name="output_kraken_sa_email"></a> [kraken\_sa\_email](#output\_kraken\_sa\_email) | Kraken service account email. |
183192
| <a name="output_kraken_sa_key"></a> [kraken\_sa\_key](#output\_kraken\_sa\_key) | Kraken service account key. |

main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module "kraken_sa" {
22
source = "./modules/meshcloud-kraken-service-account/"
33

4-
sa_name = var.kraken_sa_name
5-
org_id = var.org_id
6-
meshstack_root_project_id = var.project_id
4+
sa_name = var.kraken_sa_name
5+
org_id = var.org_id
6+
meshstack_root_project_id = var.project_id
7+
landing_zone_folder_ids = var.landing_zone_folder_ids
8+
79
cloud_billing_export_project_id = var.cloud_billing_export_project_id
8-
landing_zone_folder_ids = var.landing_zone_folder_ids
10+
cloud_billing_export_dataset_id = var.cloud_billing_export_dataset_id
911
}
1012

1113
module "replicator_sa" {
@@ -25,9 +27,8 @@ module "carbon_export" {
2527
source = "./modules/meshcloud-carbon-export/"
2628
count = var.carbon_export_module_enabled ? 1 : 0
2729

28-
carbon_data_export_project_id = var.cloud_billing_export_project_id # using the same project as for billing
29-
carbon_data_export_dataset_id = var.carbon_footprint_dataset_id
30-
carbon_dataset_region = var.carbon_footprint_dataset_location
30+
kraken_sa_email = module.kraken_sa.sa_email
3131

32-
billing_account_id = var.billing_account_id
32+
cloud_carbon_export_project_id = var.cloud_carbon_export_project_id # using the same project as for billing
33+
cloud_carbon_export_dataset_id = var.cloud_carbon_export_dataset_id
3334
}

modules/meshcloud-carbon-export/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,20 @@ No modules.
1919

2020
| Name | Type |
2121
|------|------|
22-
| [google_bigquery_data_transfer_config.carbon_footprint_transfer_config](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/bigquery_data_transfer_config) | resource |
23-
| [google_bigquery_dataset.carbon_data_export_dataset](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/bigquery_dataset) | resource |
24-
| [google_project_service.bigquery_api](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/project_service) | resource |
25-
| [google_project_service.bigquerydatatransfer_api](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/project_service) | resource |
22+
| [google_bigquery_dataset_iam_member.read_carbon_export](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/bigquery_dataset_iam_member) | resource |
2623

2724
## Inputs
2825

2926
| Name | Description | Type | Default | Required |
3027
|------|-------------|------|---------|:--------:|
31-
| <a name="input_billing_account_id"></a> [billing\_account\_id](#input\_billing\_account\_id) | The GCP Billing Account in your organization. | `string` | n/a | yes |
32-
| <a name="input_carbon_data_export_dataset_id"></a> [carbon\_data\_export\_dataset\_id](#input\_carbon\_data\_export\_dataset\_id) | GCP BigQuery dataset containing the Carbon Footprint BigQuery export | `string` | n/a | yes |
33-
| <a name="input_carbon_data_export_project_id"></a> [carbon\_data\_export\_project\_id](#input\_carbon\_data\_export\_project\_id) | 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 | `string` | n/a | yes |
34-
| <a name="input_carbon_dataset_region"></a> [carbon\_dataset\_region](#input\_carbon\_dataset\_region) | The location of the BigQuery dataset for carbon data exports. | `string` | n/a | yes |
28+
| <a name="input_cloud_carbon_export_dataset_id"></a> [cloud\_carbon\_export\_dataset\_id](#input\_cloud\_carbon\_export\_dataset\_id) | GCP BigQuery dataset containing the Carbon Footprint BigQuery export | `string` | n/a | yes |
29+
| <a name="input_cloud_carbon_export_project_id"></a> [cloud\_carbon\_export\_project\_id](#input\_cloud\_carbon\_export\_project\_id) | 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 | `string` | n/a | yes |
30+
| <a name="input_kraken_sa_email"></a> [kraken\_sa\_email](#input\_kraken\_sa\_email) | Kraken Service account email address. | `string` | n/a | yes |
3531

3632
## Outputs
3733

3834
| Name | Description |
3935
|------|-------------|
36+
| <a name="output_carbon_footprint_export_manual_setup"></a> [carbon\_footprint\_export\_manual\_setup](#output\_carbon\_footprint\_export\_manual\_setup) | GCP Cloud Carbon Footprint BigQuery export manual setup information. |
4037
| <a name="output_carbon_footprint_export_table_name"></a> [carbon\_footprint\_export\_table\_name](#output\_carbon\_footprint\_export\_table\_name) | The BigQuery table name containing the GCP Carbon Footprint BigQuery export. |
4138
<!-- END_TF_DOCS -->
Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
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-
}
1+
# similar to the cost export, we expect that the dataset already exists and was setup externally
2+
# this is a bit of a bummer as we can _almost_ automate it, see https://github.com/meshcloud/terraform-gcp-meshplatform/issues/10
63

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-
}
4+
resource "google_bigquery_dataset_iam_member" "read_carbon_export" {
5+
project = var.cloud_carbon_export_project_id
6+
dataset_id = var.cloud_carbon_export_dataset_id
127

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-
}
8+
member = "serviceAccount:${var.kraken_sa_email}"
9+
role = "roles/bigquery.dataViewer"
3110
}

modules/meshcloud-carbon-export/outputs.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ output "carbon_footprint_export_table_name" {
33

44
# note carbon_footprint is the default table name that google's data transfer config creates
55
# we can't control this via terraform right now
6-
value = "${var.carbon_data_export_project_id}.${var.carbon_data_export_dataset_id}.carbon_footprint"
7-
}
6+
value = "${var.cloud_carbon_export_project_id}.${var.cloud_carbon_export_dataset_id}.carbon_footprint"
7+
}
8+
9+
output "carbon_footprint_export_manual_setup" {
10+
description = "GCP Cloud Carbon Footprint BigQuery export manual setup information."
11+
value = "Attention. You need to manually configure the carbon footprint export transfer config before exceuting this module. See https://docs.meshcloud.io/docs/meshstack.how-to.integrate-meshplatform-gcp-manually.html#optional-enable-gcp-cloud-carbon-footprint-export for instructions."
12+
}
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
variable "carbon_dataset_region" {
1+
variable "cloud_carbon_export_project_id" {
22
type = string
3-
description = "The location of the BigQuery dataset for carbon data exports."
3+
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"
44
}
55

6-
variable "billing_account_id" {
6+
variable "cloud_carbon_export_dataset_id" {
77
type = string
8-
description = "The GCP Billing Account in your organization."
8+
description = "GCP BigQuery dataset containing the Carbon Footprint BigQuery export"
99
}
1010

11-
variable "carbon_data_export_project_id" {
11+
variable "kraken_sa_email" {
1212
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-
}
13+
description = "Kraken Service account email address."
1514

16-
variable "carbon_data_export_dataset_id" {
17-
type = string
18-
description = "GCP BigQuery dataset containing the Carbon Footprint BigQuery export"
1915
}

modules/meshcloud-kraken-service-account/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ No modules.
1919

2020
| Name | Type |
2121
|------|------|
22-
| [google_folder_iam_member.replicator_service](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/folder_iam_member) | resource |
22+
| [google_bigquery_dataset_iam_member.read_billing_export](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/bigquery_dataset_iam_member) | resource |
23+
| [google_folder_iam_member.kraken_service](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/folder_iam_member) | resource |
2324
| [google_organization_iam_custom_role.meshcloud_kraken_sa](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/organization_iam_custom_role) | resource |
2425
| [google_project_iam_member.bigquery_jobuser](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/project_iam_member) | resource |
25-
| [google_project_iam_member.biquery_dataViewer](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/project_iam_member) | resource |
2626
| [google_project_service.bigquery_api](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/project_service) | resource |
2727
| [google_service_account.meshcloud_kraken_sa](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/service_account) | resource |
2828
| [google_service_account_key.sa_key](https://registry.terraform.io/providers/hashicorp/google/4.11.0/docs/resources/service_account_key) | resource |
@@ -31,6 +31,7 @@ No modules.
3131

3232
| Name | Description | Type | Default | Required |
3333
|------|-------------|------|---------|:--------:|
34+
| <a name="input_cloud_billing_export_dataset_id"></a> [cloud\_billing\_export\_dataset\_id](#input\_cloud\_billing\_export\_dataset\_id) | GCP BigQuery dataset containing the Cloud Billing BigQuery export. | `string` | n/a | yes |
3435
| <a name="input_cloud_billing_export_project_id"></a> [cloud\_billing\_export\_project\_id](#input\_cloud\_billing\_export\_project\_id) | GCP Project where the BigQuery table resides that holds the Cloud Billing export to BigQuery. | `string` | n/a | yes |
3536
| <a name="input_landing_zone_folder_ids"></a> [landing\_zone\_folder\_ids](#input\_landing\_zone\_folder\_ids) | GCP Folders that make up the Landing Zone. The service account will only receive permissions on these folders. | `set(string)` | n/a | yes |
3637
| <a name="input_meshstack_root_project_id"></a> [meshstack\_root\_project\_id](#input\_meshstack\_root\_project\_id) | GCP Project ID where to create the service account. This is typically a 'meshstack-root' project. | `string` | n/a | yes |
@@ -41,6 +42,7 @@ No modules.
4142

4243
| Name | Description |
4344
|------|-------------|
45+
| <a name="output_billing_export_manual_setup"></a> [billing\_export\_manual\_setup](#output\_billing\_export\_manual\_setup) | GCP Cloud Billing BigQuery export manual setup information. |
4446
| <a name="output_sa_email"></a> [sa\_email](#output\_sa\_email) | Service account email. |
4547
| <a name="output_sa_key"></a> [sa\_key](#output\_sa\_key) | Service account key (base64 encoded credential.json). |
4648
<!-- END_TF_DOCS -->

modules/meshcloud-kraken-service-account/module.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ resource "google_project_iam_member" "bigquery_jobuser" {
1818
member = "serviceAccount:${google_service_account.meshcloud_kraken_sa.email}"
1919
}
2020

21-
resource "google_project_iam_member" "biquery_dataViewer" {
22-
project = var.cloud_billing_export_project_id
23-
role = "roles/bigquery.dataViewer"
21+
resource "google_bigquery_dataset_iam_member" "read_billing_export" {
22+
project = var.cloud_billing_export_project_id
23+
dataset_id = var.cloud_billing_export_dataset_id
2424

2525
member = "serviceAccount:${google_service_account.meshcloud_kraken_sa.email}"
26+
role = "roles/bigquery.dataViewer"
2627
}
2728

2829
resource "google_organization_iam_custom_role" "meshcloud_kraken_sa" {
@@ -39,9 +40,9 @@ resource "google_organization_iam_custom_role" "meshcloud_kraken_sa" {
3940
}
4041

4142
# We apply a hardened security configuration, i.e. we assign permissions only on LZ folders instead of the organization
42-
# root
43+
# root - this allows kraken to read projects
4344

44-
resource "google_folder_iam_member" "replicator_service" {
45+
resource "google_folder_iam_member" "kraken_service" {
4546
for_each = var.landing_zone_folder_ids
4647

4748
folder = each.value

modules/meshcloud-kraken-service-account/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ output "sa_email" {
88
value = google_service_account.meshcloud_kraken_sa.email
99
description = "Service account email."
1010
}
11+
12+
output "billing_export_manual_setup" {
13+
description = "GCP Cloud Billing BigQuery export manual setup information."
14+
value = "Attention. You need to manually configure the billing account big query export before exceuting this module. See https://docs.meshcloud.io/docs/meshstack.how-to.integrate-meshplatform-gcp-manually.html#set-up-gcp-billing-data-export for instructions."
15+
}

modules/meshcloud-kraken-service-account/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ variable "cloud_billing_export_project_id" {
1818
description = "GCP Project where the BigQuery table resides that holds the Cloud Billing export to BigQuery."
1919
}
2020

21+
variable "cloud_billing_export_dataset_id" {
22+
type = string
23+
description = "GCP BigQuery dataset containing the Cloud Billing BigQuery export."
24+
}
25+
2126
variable "landing_zone_folder_ids" {
2227
type = set(string)
2328
description = "GCP Folders that make up the Landing Zone. The service account will only receive permissions on these folders."

0 commit comments

Comments
 (0)