Skip to content

Commit 320e9d5

Browse files
authored
chore: disabling SCC notifications for now (#1304)
1 parent 0a3e977 commit 320e9d5

File tree

8 files changed

+62
-50
lines changed

8 files changed

+62
-50
lines changed

1-org/envs/shared/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| data\_access\_logs\_enabled | Enable Data Access logs of types DATA\_READ, DATA\_WRITE for all GCP services. Enabling Data Access logs might result in your organization being charged for the additional logs usage. See https://cloud.google.com/logging/docs/audit#data-access The ADMIN\_READ logs are enabled by default. | `bool` | `false` | no |
1010
| domains\_to\_allow | The list of domains to allow users from in IAM. Used by Domain Restricted Sharing Organization Policy. Must include the domain of the organization you are deploying the foundation. To add other domains you must also grant access to these domains to the Terraform Service Account used in the deploy. | `list(string)` | n/a | yes |
1111
| enable\_hub\_and\_spoke | Enable Hub-and-Spoke architecture. | `bool` | `false` | no |
12+
| enable\_scc\_resources\_in\_terraform | Create Security Command Center resources in Terraform. If your organization has newly enabled any preview features for SCC and get an error related to the v2 API, you must set this variable to false because the v2 API does not yet support Terraform resources. See [issue 1189](https://github.com/terraform-google-modules/terraform-example-foundation/issues/1189) for context. | `bool` | `false` | no |
1213
| enforce\_allowed\_worker\_pools | Whether to enforce the organization policy restriction on allowed worker pools for Cloud Build. | `bool` | `false` | no |
1314
| essential\_contacts\_domains\_to\_allow | The list of domains that email addresses added to Essential Contacts can have. | `list(string)` | n/a | yes |
1415
| essential\_contacts\_language | Essential Contacts preferred language for notifications, as a ISO 639-1 language code. See [Supported languages](https://cloud.google.com/resource-manager/docs/managing-notification-contacts#supported-languages) for a list of supported languages. | `string` | `"en"` | no |

1-org/envs/shared/cai_monitoring.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616

1717
module "cai_monitoring" {
18-
source = "../../modules/cai-monitoring"
19-
18+
source = "../../modules/cai-monitoring"
19+
count = var.enable_scc_resources_in_terraform ? 1 : 0
2020
org_id = local.org_id
2121
billing_account = local.billing_account
2222
project_id = module.scc_notifications.project_id
2323
location = local.default_region
24-
build_service_account = "projects/${module.scc_notifications.project_id}/serviceAccounts/${google_service_account.cai_monitoring_builder.email}"
24+
build_service_account = "projects/${module.scc_notifications.project_id}/serviceAccounts/${google_service_account.cai_monitoring_builder[0].email}"
2525
}

1-org/envs/shared/iam.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ resource "google_organization_iam_member" "org_scc_admin" {
169169
}
170170

171171
resource "google_project_iam_member" "project_scc_admin" {
172-
count = var.gcp_groups.scc_admin != null ? 1 : 0
172+
count = var.gcp_groups.scc_admin != null && var.enable_scc_resources_in_terraform ? 1 : 0
173173
project = module.scc_notifications.project_id
174174
role = "roles/securitycenter.adminEditor"
175175
member = "group:${var.gcp_groups.scc_admin}"
@@ -191,11 +191,12 @@ resource "google_project_iam_member" "kms_admin" {
191191

192192
resource "google_project_iam_member" "cai_monitoring_builder" {
193193
project = module.scc_notifications.project_id
194-
for_each = toset([
195-
"roles/logging.logWriter",
196-
"roles/storage.objectViewer",
197-
"roles/artifactregistry.writer",
198-
])
194+
for_each = toset(var.enable_scc_resources_in_terraform ?
195+
[
196+
"roles/logging.logWriter",
197+
"roles/storage.objectViewer",
198+
"roles/artifactregistry.writer",
199+
] : [])
199200
role = each.key
200-
member = "serviceAccount:${google_service_account.cai_monitoring_builder.email}"
201+
member = "serviceAccount:${google_service_account.cai_monitoring_builder[0].email}"
201202
}

1-org/envs/shared/outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ output "interconnect_project_number" {
7575
}
7676

7777
output "scc_notifications_project_id" {
78-
value = module.scc_notifications.project_id
78+
value = try(module.scc_notifications.project_id, null)
7979
description = "The SCC notifications project ID"
8080
}
8181

@@ -140,21 +140,21 @@ output "shared_vpc_projects" {
140140
}
141141

142142
output "cai_monitoring_artifact_registry" {
143-
value = module.cai_monitoring.artifact_registry_name
143+
value = try(module.cai_monitoring[0].artifact_registry_name, null)
144144
description = "CAI Monitoring Cloud Function Artifact Registry name."
145145
}
146146

147147
output "cai_monitoring_asset_feed" {
148-
value = module.cai_monitoring.asset_feed_name
148+
value = try(module.cai_monitoring[0].asset_feed_name, null)
149149
description = "CAI Monitoring Cloud Function Organization Asset Feed name."
150150
}
151151

152152
output "cai_monitoring_bucket" {
153-
value = module.cai_monitoring.bucket_name
153+
value = try(module.cai_monitoring[0].bucket_name, null)
154154
description = "CAI Monitoring Cloud Function Source Bucket name."
155155
}
156156

157157
output "cai_monitoring_topic" {
158-
value = module.cai_monitoring.topic_name
158+
value = try(module.cai_monitoring[0].topic_name, null)
159159
description = "CAI Monitoring Cloud Function Pub/Sub Topic name."
160160
}

1-org/envs/shared/sa.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
resource "google_service_account" "cai_monitoring_builder" {
1818
project = module.scc_notifications.project_id
19+
count = var.enable_scc_resources_in_terraform ? 1 : 0
1920
account_id = "cai-monitoring-builder"
2021
description = "Cloud Functions has an underlying dependency on Cloud Build and other services. This service account allows Cloud Build to provision the necessary resources for Cloud Functions."
2122
create_ignore_already_exists = true

1-org/envs/shared/scc_notification.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,24 @@
1919
*****************************************/
2020

2121
resource "google_pubsub_topic" "scc_notification_topic" {
22+
count = var.enable_scc_resources_in_terraform ? 1 : 0
2223
name = "top-scc-notification"
2324
project = module.scc_notifications.project_id
2425
}
2526

2627
resource "google_pubsub_subscription" "scc_notification_subscription" {
28+
count = var.enable_scc_resources_in_terraform ? 1 : 0
2729
name = "sub-scc-notification"
28-
topic = google_pubsub_topic.scc_notification_topic.name
30+
topic = google_pubsub_topic.scc_notification_topic[0].name
2931
project = module.scc_notifications.project_id
3032
}
3133

3234
resource "google_scc_notification_config" "scc_notification_config" {
35+
count = var.enable_scc_resources_in_terraform ? 1 : 0
3336
config_id = var.scc_notification_name
3437
organization = local.org_id
3538
description = "SCC Notification for all active findings"
36-
pubsub_topic = google_pubsub_topic.scc_notification_topic.id
39+
pubsub_topic = google_pubsub_topic.scc_notification_topic[0].id
3740

3841
streaming_config {
3942
filter = var.scc_notification_filter

1-org/envs/shared/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ variable "enable_hub_and_spoke" {
2020
default = false
2121
}
2222

23+
variable "enable_scc_resources_in_terraform" {
24+
description = "Create Security Command Center resources in Terraform. If your organization has newly enabled any preview features for SCC and get an error related to the v2 API, you must set this variable to false because the v2 API does not yet support Terraform resources. See [issue 1189](https://github.com/terraform-google-modules/terraform-example-foundation/issues/1189) for context."
25+
type = bool
26+
default = false
27+
}
28+
2329
variable "domains_to_allow" {
2430
description = "The list of domains to allow users from in IAM. Used by Domain Restricted Sharing Organization Policy. Must include the domain of the organization you are deploying the foundation. To add other domains you must also grant access to these domains to the Terraform Service Account used in the deploy."
2531
type = list(string)

test/integration/org/org_test.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,22 @@ func TestOrg(t *testing.T) {
182182
requireOsLogin := gcloud.Runf(t, "resource-manager org-policies describe %s --folder %s", "constraints/compute.requireOsLogin", parentFolder)
183183
assert.Equal("constraints/compute.requireOsLogin", requireOsLogin.Get("constraint").String(), "org policy should require OS Login")
184184

185-
// security command center
186-
sccProjectID := org.GetStringOutput("scc_notifications_project_id")
187-
topicName := "top-scc-notification"
188-
topicFullName := fmt.Sprintf("projects/%s/topics/%s", sccProjectID, topicName)
189-
topic := gcloud.Runf(t, "pubsub topics describe %s --project %s", topicName, sccProjectID)
190-
assert.Equal(topicFullName, topic.Get("name").String(), fmt.Sprintf("topic %s should have been created", topicName))
191-
192-
subscriptionName := "sub-scc-notification"
193-
subscriptionFullName := fmt.Sprintf("projects/%s/subscriptions/%s", sccProjectID, subscriptionName)
194-
subscription := gcloud.Runf(t, "pubsub subscriptions describe %s --project %s", subscriptionName, sccProjectID)
195-
assert.Equal(subscriptionFullName, subscription.Get("name").String(), fmt.Sprintf("subscription %s should have been created", subscriptionName))
196-
197-
orgID := bootstrap.GetTFSetupStringOutput("org_id")
198-
notificationName := org.GetStringOutput("scc_notification_name")
199-
notification := gcloud.Runf(t, "scc notifications describe %s --organization %s", notificationName, orgID)
200-
assert.Equal(topicFullName, notification.Get("pubsubTopic").String(), fmt.Sprintf("notification %s should use topic %s", notificationName, topicName))
185+
// security command center (commented out with issue #1189)
186+
// sccProjectID := org.GetStringOutput("scc_notifications_project_id")
187+
// topicName := "top-scc-notification"
188+
// topicFullName := fmt.Sprintf("projects/%s/topics/%s", sccProjectID, topicName)
189+
// topic := gcloud.Runf(t, "pubsub topics describe %s --project %s", topicName, sccProjectID)
190+
// assert.Equal(topicFullName, topic.Get("name").String(), fmt.Sprintf("topic %s should have been created", topicName))
191+
192+
// subscriptionName := "sub-scc-notification"
193+
// subscriptionFullName := fmt.Sprintf("projects/%s/subscriptions/%s", sccProjectID, subscriptionName)
194+
// subscription := gcloud.Runf(t, "pubsub subscriptions describe %s --project %s", subscriptionName, sccProjectID)
195+
// assert.Equal(subscriptionFullName, subscription.Get("name").String(), fmt.Sprintf("subscription %s should have been created", subscriptionName))
196+
197+
// orgID := bootstrap.GetTFSetupStringOutput("org_id")
198+
// notificationName := org.GetStringOutput("scc_notification_name")
199+
// notification := gcloud.Runf(t, "scc notifications describe %s --organization %s", notificationName, orgID)
200+
// assert.Equal(topicFullName, notification.Get("pubsubTopic").String(), fmt.Sprintf("notification %s should use topic %s", notificationName, topicName))
201201

202202
//essential contacts
203203
//test case considers that just the Org Admin group exists and will subscribe for all categories
@@ -293,33 +293,33 @@ func TestOrg(t *testing.T) {
293293
}
294294
}
295295

296-
// CAI Monitoring
296+
// CAI Monitoring (commented out with issue #1189)
297297
// Variables
298-
caiAr := org.GetStringOutput("cai_monitoring_artifact_registry")
299-
caiBucket := org.GetStringOutput("cai_monitoring_bucket")
300-
caiTopic := org.GetStringOutput("cai_monitoring_topic")
298+
// caiAr := org.GetStringOutput("cai_monitoring_artifact_registry")
299+
// caiBucket := org.GetStringOutput("cai_monitoring_bucket")
300+
// caiTopic := org.GetStringOutput("cai_monitoring_topic")
301301

302-
caiSaEmail := fmt.Sprintf("cai-monitoring@%s.iam.gserviceaccount.com", sccProjectID)
303-
caiTopicFullName := fmt.Sprintf("projects/%s/topics/%s", sccProjectID, caiTopic)
302+
// caiSaEmail := fmt.Sprintf("cai-monitoring@%s.iam.gserviceaccount.com", sccProjectID)
303+
// caiTopicFullName := fmt.Sprintf("projects/%s/topics/%s", sccProjectID, caiTopic)
304304

305305
// Cloud Function
306-
opCf := gcloud.Runf(t, "functions describe caiMonitoring --project %s --gen2 --region %s", sccProjectID, defaultRegion)
307-
assert.Equal("ACTIVE", opCf.Get("state").String(), "Should be ACTIVE. Cloud Function is not successfully deployed.")
308-
assert.Equal(caiSaEmail, opCf.Get("serviceConfig.serviceAccountEmail").String(), fmt.Sprintf("Cloud Function should use the service account %s.", caiSaEmail))
309-
assert.Contains(opCf.Get("eventTrigger.eventType").String(), "google.cloud.pubsub.topic.v1.messagePublished", "Event Trigger is not based on Pub/Sub message. Check the EventType configuration.")
306+
// opCf := gcloud.Runf(t, "functions describe caiMonitoring --project %s --gen2 --region %s", sccProjectID, defaultRegion)
307+
// assert.Equal("ACTIVE", opCf.Get("state").String(), "Should be ACTIVE. Cloud Function is not successfully deployed.")
308+
// assert.Equal(caiSaEmail, opCf.Get("serviceConfig.serviceAccountEmail").String(), fmt.Sprintf("Cloud Function should use the service account %s.", caiSaEmail))
309+
// assert.Contains(opCf.Get("eventTrigger.eventType").String(), "google.cloud.pubsub.topic.v1.messagePublished", "Event Trigger is not based on Pub/Sub message. Check the EventType configuration.")
310310

311311
// Cloud Function Storage Bucket
312-
bktArgs := gcloud.WithCommonArgs([]string{"--project", sccProjectID, "--json"})
313-
opSrcBucket := gcloud.Run(t, fmt.Sprintf("alpha storage ls --buckets gs://%s", caiBucket), bktArgs).Array()
314-
assert.Equal("true", opSrcBucket[0].Get("metadata.iamConfiguration.bucketPolicyOnly.enabled").String(), "Should have Bucket Policy Only enabled.")
312+
// bktArgs := gcloud.WithCommonArgs([]string{"--project", sccProjectID, "--json"})
313+
// opSrcBucket := gcloud.Run(t, fmt.Sprintf("alpha storage ls --buckets gs://%s", caiBucket), bktArgs).Array()
314+
// assert.Equal("true", opSrcBucket[0].Get("metadata.iamConfiguration.bucketPolicyOnly.enabled").String(), "Should have Bucket Policy Only enabled.")
315315

316316
// Cloud Function Artifact Registry
317-
opAR := gcloud.Runf(t, "artifacts repositories describe %s --project %s --location %s", caiAr, sccProjectID, defaultRegion)
318-
assert.Equal("DOCKER", opAR.Get("format").String(), "Should have type: DOCKER")
317+
// opAR := gcloud.Runf(t, "artifacts repositories describe %s --project %s --location %s", caiAr, sccProjectID, defaultRegion)
318+
// assert.Equal("DOCKER", opAR.Get("format").String(), "Should have type: DOCKER")
319319

320320
// Cloud Function Pub/Sub
321-
opTopic := gcloud.Runf(t, "pubsub topics describe %s --project %s", caiTopic, sccProjectID)
322-
assert.Equal(caiTopicFullName, opTopic.Get("name").String(), fmt.Sprintf("Topic %s should have been created", caiTopicFullName))
321+
// opTopic := gcloud.Runf(t, "pubsub topics describe %s --project %s", caiTopic, sccProjectID)
322+
// assert.Equal(caiTopicFullName, opTopic.Get("name").String(), fmt.Sprintf("Topic %s should have been created", caiTopicFullName))
323323

324324
// Log Sink
325325
for _, sink := range []struct {

0 commit comments

Comments
 (0)