Skip to content

Commit 8c93cf1

Browse files
refactor: Separate out IAM resources in 1-org and add monitoring permissions for monitoring workspaces.
1 parent f5b2969 commit 8c93cf1

File tree

5 files changed

+71
-29
lines changed

5 files changed

+71
-29
lines changed

1-org/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The purpose of this step is to setup top level shared folders, monitoring & netw
4242
| data\_access\_table\_expiration\_ms | Period before tables expire for data access logs in milliseconds. Default is 30 days. | number | `"2592000000"` | no |
4343
| default\_region | Default region for BigQuery resources. | string | n/a | yes |
4444
| domains\_to\_allow | The list of domains to allow users from in IAM. | list(string) | n/a | yes |
45+
| monitoring\_workspace\_users | Gsuite or Cloud Identity group that have access to Monitoring Workspaces. | string | n/a | yes |
4546
| org\_id | The organization id for the associated services | string | n/a | yes |
4647
| system\_event\_table\_expiration\_ms | Period before tables expire for system event logs in milliseconds. Default is 400 days. | number | `"34560000000"` | no |
4748
| terraform\_service\_account | Service account email of the account to impersonate to run Terraform. | string | n/a | yes |

1-org/iam.tf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/******************************************
18+
Monitoring - IAM
19+
*****************************************/
20+
21+
resource "google_project_iam_member" "monitoring_prod_editor" {
22+
project = module.org_monitoring_prod.project_id
23+
role = "roles/monitoring.editor"
24+
member = "group:${var.monitoring_workspace_users}"
25+
}
26+
27+
resource "google_project_iam_member" "monitoring_nonprod_editor" {
28+
project = module.org_monitoring_nonprod.project_id
29+
role = "roles/monitoring.editor"
30+
member = "group:${var.monitoring_workspace_users}"
31+
}
32+
33+
/******************************************
34+
Audit Logs - IAM
35+
*****************************************/
36+
37+
resource "google_project_iam_member" "audit_log_bq_user" {
38+
project = module.org_audit_logs.project_id
39+
role = "roles/bigquery.user"
40+
member = "group:${var.audit_data_users}"
41+
}
42+
43+
resource "google_project_iam_member" "audit_log_bq_data_viewer" {
44+
project = module.org_audit_logs.project_id
45+
role = "roles/bigquery.dataViewer"
46+
member = "group:${var.audit_data_users}"
47+
}
48+
49+
/******************************************
50+
Billing BigQuery - IAM
51+
*****************************************/
52+
53+
resource "google_project_iam_member" "billing_bq_user" {
54+
project = module.org_billing_logs.project_id
55+
role = "roles/bigquery.user"
56+
member = "group:${var.billing_data_users}"
57+
}
58+
59+
resource "google_project_iam_member" "billing_bq_viewer" {
60+
project = module.org_billing_logs.project_id
61+
role = "roles/bigquery.dataViewer"
62+
member = "group:${var.billing_data_users}"
63+
}

1-org/log_sinks.tf

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,6 @@ module "bq_data_access_logs" {
8888
default_table_expiration_ms = var.data_access_table_expiration_ms
8989
}
9090

91-
/******************************************
92-
Audit Logs - IAM
93-
*****************************************/
94-
95-
resource "google_project_iam_member" "audit_log_bq_user" {
96-
project = module.org_audit_logs.project_id
97-
role = "roles/bigquery.user"
98-
member = "group:${var.audit_data_users}"
99-
}
100-
101-
resource "google_project_iam_member" "audit_log_bq_data_viewer" {
102-
project = module.org_audit_logs.project_id
103-
role = "roles/bigquery.dataViewer"
104-
member = "group:${var.audit_data_users}"
105-
}
106-
10791
/******************************************
10892
Billing logs (Export configured manually)
10993
*****************************************/
@@ -114,16 +98,3 @@ resource "google_bigquery_dataset" "billing_dataset" {
11498
friendly_name = "GCP Billing Data"
11599
location = var.default_region
116100
}
117-
118-
resource "google_project_iam_member" "billing_bq_user" {
119-
project = module.org_billing_logs.project_id
120-
role = "roles/bigquery.user"
121-
member = "group:${var.billing_data_users}"
122-
}
123-
124-
resource "google_project_iam_member" "billing_bq_viewer" {
125-
project = module.org_billing_logs.project_id
126-
role = "roles/bigquery.dataViewer"
127-
member = "group:${var.billing_data_users}"
128-
}
129-

1-org/terraform.example.tfvars

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ billing_data_users = "[email protected]"
2020

2121
audit_data_users = "[email protected]"
2222

23+
monitoring_workspace_users = "[email protected]"
24+
2325
org_id = "000000000000"
2426

2527
billing_account = "000000-000000-000000"

1-org/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ variable "audit_data_users" {
4444
type = string
4545
}
4646

47+
variable "monitoring_workspace_users" {
48+
description = "Gsuite or Cloud Identity group that have access to Monitoring Workspaces."
49+
type = string
50+
}
51+
4752
variable "domains_to_allow" {
4853
description = "The list of domains to allow users from in IAM."
4954
type = list(string)

0 commit comments

Comments
 (0)