Export your carbon footprint
You can export your Carbon Footprint data to BigQuery in order to perform data analysis, or to create custom dashboards and reports.
The Carbon Footprint export captures gross greenhouse gas emissions from electricity associated with the usage of covered Google Cloud services for the selected billing account.
After configuring an export, you are charged for the used BigQuery resources.
Before you begin
To create a Carbon Footprint export, we recommend having the following IAM roles:
- Project Owner or Project Editor on the Google Cloud project to export to.
- Carbon Footprint Viewer or Billing Account Viewer on the billing account to export the carbon for
More precisely, you must have the following IAM permissions on the Google Cloud project:
resourcemanager.projects.update
serviceusage.services.enable
bigquery.transfers.update
And the following IAM permission on the billing account:
billing.accounts.getCarbonInformation
If using VPC Service Controls
If your organization is using VPC Service Controls, an ingress rule needs to be defined for the BigQuery API and BigQuery Data Transfer Service API.
For your Ingress policy rule,
- set the source in the 'From' section to 'All sources allow'
- grant permission to the identity,
els-da-carbon@gcp-carbon-footprint-exports.iam.gserviceaccount.com
Configuring a Carbon Footprint export to BigQuery
Carbon Footprint data is exported via the BigQuery Data Transfer Service. The data will be exported to the BigQuery table of your choice on the schedule you specify. Each export will overwrite the entire table with the most recent data available, which includes historical data and data for the new month. Each month's data is added to the export on the 15th day of the following month.
Console
Initiating the export:
- Go to Carbon Footprint
- Select the Cloud Billing account you want to export from the Billing account menu.
- Click Export to enable the BigQuery Data Transfer Service and open the BigQuery Data Transfer Service page.
- On the BigQuery Data Transfer Service page:
- Ensure that Source is set to "Google Cloud Carbon Footprint Exports".
- In Transfer config name, enter a display name.
- In Schedule options, select Start now to trigger the export as soon as possible.
- In Destination settings, click the Dataset ID field and then select Create new dataset if you want to create a new BigQuery dataset to host the exported table; alternatively select an existing BigQuery dataset.
- In Data source details, confirm the Cloud Billing account ID to
export. Optionally, add additional account IDs as a comma separated
list. All billing account IDs should be in the format
XXXXXX-XXXXXX-XXXXXX
.
- Click Save.
- In the access request window, select the two options.
- Click Continue
If you selected Start now in the schedule options, your data transfer will
be scheduled for the current day.
The data transfer creates a single table in the selected BigQuery
dataset called carbon_footprint_export
, which is overwritten with the complete
data export every time the transfer runs.
The initial transfer run will likely complete on the following day.
bq
Use the bq mk
command to
initiate the export:
bq mk \ --transfer_config \ --target_dataset=DATASET \ --display_name=NAME \ --params='{"billing_accounts":"BILLING_ACCOUNT_IDS"}' \ --data_source=61cede5a-0000-2440-ad42-883d24f8f7b8
Where:
- DATASET is the target dataset for the transfer configuration.
- NAME is the display name for the transfer configuration. For example: "Company Carbon Report".
- BILLING_ACCOUNT_IDS is your billing account ID or a
comma-separated list of billing account IDs. For example:
XXXXXX-XXXXXX-XXXXXX,XXXXXX-XXXXXX-XXXXXX
Terraform
Use the bigquery_data_transfer_config
Terraform resource to create an export:
resource "google_bigquery_data_transfer_config" "RESOURCE_NAME" { display_name = "NAME" data_source_id = "61cede5a-0000-2440-ad42-883d24f8f7b8" destination_dataset_id = google_bigquery_dataset.DATASET.dataset_id params = { billing_accounts = "BILLING_ACCOUNT_IDS" } }
Where:
- RESOURCE_NAME is the name of the Terraform resource.
For example:
carbon_export
. - NAME is the display name for the transfer configuration. For example: "Company Carbon Report".
DATASET is the name of the
google_bigquery_dataset
Terraform resource to use as the target dataset for the export.BILLING_ACCOUNT_IDS is your billing account ID or a comma-separated list of billing account IDs. For example:
XXXXXX-XXXXXX-XXXXXX,XXXXXX-XXXXXX-XXXXXX
Once completed, you can use BigQuery to view and query the data. Read more about the data schema.
You can share the exported data to others in your organization by granting them the BigQuery User IAM role on the project selected earlier or the BigQuery table.
Managing Carbon Footprint exports
You can manage your Carbon Footprint exports through the BigQuery Data Transfer Service. Learn more about Working with transfers.
Exporting to Sheets or CSV
After you've configured your carbon footprint export to BigQuery and the scheduled export has completed, you can export that data from BigQuery to Sheets or CSV.
- Go to BigQuery
- In the Explorer panel, expand your project and dataset, then select the table that contains the exported carbon footprint data.
- Click Query.
- Enter a query to return the data you want to export. See below for an example.
- After the query has run, under Query results, click Save results.
- Select the desired format and click Save.
The following query lets you save the entire content of the exported table:
SELECT
usage_month,
billing_account_id,
project.number AS project_number,
project.id AS project_id,
service.id AS service_id,
service.description AS service_description,
location.location AS location,
location.region AS region,
carbon_footprint_kgCO2e,
carbon_model_version
FROM
`PROJECT.DATASET.TABLE`
ORDER BY
usage_month DESC,
carbon_footprint_kgCO2 DESC
What's next?
- Read about the data schema used in the export.
- Explore your gross carbon footprint in the Google Cloud console
- Create custom dashboards with the exported data.
- Understand the methodology behind Carbon Footprint