11locals {
2- stacklet_assumed_role = " arn:aws:sts::${ var . stacklet_aws_account_id } :assumed-role/${ var . stacklet_aws_role_name } "
2+ stacklet_assumed_role = " arn:aws:sts::${ var . stacklet_aws_account_id } :assumed-role/${ var . stacklet_aws_role_name } "
33
4- source_tables = [for key in var . billing_tables : {
5- " key" : key,
6- " project_id" : split (" ." , key)[0 ],
7- " dataset_id" : split (" ." , key)[1 ],
8- " table_id" : split (" ." , key)[2 ],
9- }]
4+ source_tables = [for key in var . billing_tables : {
5+ " key" : key,
6+ " project_id" : split (" ." , key)[0 ],
7+ " dataset_id" : split (" ." , key)[1 ],
8+ " table_id" : split (" ." , key)[2 ],
9+ }]
1010}
1111
1212
1313# A project for all the resources to live in, and the APIs it needs activated.
1414resource "google_project" "billing_export" {
15- name = " Stacklet billing export"
16- project_id = var. project_id
17- org_id = var. project_org_id
18- folder_id = var. project_folder_id
19- billing_account = var. project_billing_account_id
15+ name = " Stacklet billing export"
16+ project_id = var. project_id
17+ org_id = var. project_org_id
18+ folder_id = var. project_folder_id
19+ billing_account = var. project_billing_account_id
2020}
2121resource "google_project_service" "iamcredentials" {
22- project = google_project. billing_export . project_id
23- service = " iamcredentials.googleapis.com"
22+ project = google_project. billing_export . project_id
23+ service = " iamcredentials.googleapis.com"
2424}
2525resource "google_project_service" "bigquery" {
26- project = google_project. billing_export . project_id
27- service = " bigquery.googleapis.com"
26+ project = google_project. billing_export . project_id
27+ service = " bigquery.googleapis.com"
2828}
2929
3030
3131# Allow AWS roles from the Stacklet account to assume identities in GCP.
3232resource "google_iam_workload_identity_pool" "stacklet_access" {
33- project = google_project. billing_export . project_id
34- workload_identity_pool_id = " stacklet-access"
35- display_name = " Stacklet billing export"
33+ project = google_project. billing_export . project_id
34+ workload_identity_pool_id = " stacklet-access"
35+ display_name = " Stacklet billing export"
3636}
3737resource "google_iam_workload_identity_pool_provider" "stacklet_account" {
38- project = google_project. billing_export . project_id
39- workload_identity_pool_id = google_iam_workload_identity_pool. stacklet_access . workload_identity_pool_id
40- workload_identity_pool_provider_id = " stacklet-account"
41- display_name = " Stacklet FOCUS export"
42- disabled = false
38+ project = google_project. billing_export . project_id
39+ workload_identity_pool_id = google_iam_workload_identity_pool. stacklet_access . workload_identity_pool_id
40+ workload_identity_pool_provider_id = " stacklet-account"
41+ display_name = " Stacklet FOCUS export"
42+ disabled = false
4343
44- # The default attribute mapping for AWS sets `aws_role` attribute which matches the
45- # `local.stacklet_assumed_role` as used in the service account IAM policy.
46- aws {
47- account_id = var. stacklet_aws_account_id
48- }
44+ # The default attribute mapping for AWS sets `aws_role` attribute which matches the
45+ # `local.stacklet_assumed_role` as used in the service account IAM policy.
46+ aws {
47+ account_id = var. stacklet_aws_account_id
48+ }
4949}
5050
5151
5252# Service account, which can be impersonated by `local.stacklet_assumed_role`.
5353resource "google_service_account" "billing_access" {
54- project = google_project. billing_export . project_id
55- account_id = " stacklet-billing-access"
56- display_name = " Stacklet WIF billing access"
54+ project = google_project. billing_export . project_id
55+ account_id = " stacklet-billing-access"
56+ display_name = " Stacklet WIF billing access"
5757}
5858data "google_iam_policy" "stacklet_role_access" {
59- binding {
60- role = " roles/iam.serviceAccountTokenCreator"
61- members = [" principalSet://iam.googleapis.com/${ google_iam_workload_identity_pool . stacklet_access . name } /attribute.aws_role/${ local . stacklet_assumed_role } " ]
62- }
59+ binding {
60+ role = " roles/iam.serviceAccountTokenCreator"
61+ members = [" principalSet://iam.googleapis.com/${ google_iam_workload_identity_pool . stacklet_access . name } /attribute.aws_role/${ local . stacklet_assumed_role } " ]
62+ }
6363}
6464resource "google_service_account_iam_policy" "billing_access" {
6565 service_account_id = google_service_account. billing_access . name
@@ -74,20 +74,20 @@ resource "google_project_iam_member" "sa_bq_jobs" {
7474 member = google_service_account. billing_access . member
7575}
7676resource "google_bigquery_table_iam_member" "sa_bq_tables" {
77- for_each = { for table in local . source_tables : table . key => table }
77+ for_each = { for table in local . source_tables : table . key => table }
7878
79- project = each. value . project_id
80- dataset_id = each. value . dataset_id
81- table_id = each. value . table_id
82- role = " roles/bigquery.dataViewer"
83- member = google_service_account. billing_access . member
79+ project = each. value . project_id
80+ dataset_id = each. value . dataset_id
81+ table_id = each. value . table_id
82+ role = " roles/bigquery.dataViewer"
83+ member = google_service_account. billing_access . member
8484}
8585
8686
8787# Discover dataset locations for output.
8888data "google_bigquery_dataset" "table_datasets" {
89- for_each = { for table in local . source_tables : table . key => table }
89+ for_each = { for table in local . source_tables : table . key => table }
9090
91- project = each. value . project_id
92- dataset_id = each. value . dataset_id
91+ project = each. value . project_id
92+ dataset_id = each. value . dataset_id
9393}
0 commit comments