Skip to content

Commit d2cdfb6

Browse files
authored
feat: replace scc gcloud provisioner with native resource (#514)
* replace scc configure gcloud to Terraform resource * fix the format * format * add readme
1 parent 27a31a6 commit d2cdfb6

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

1-org/envs/shared/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
| restricted\_net\_hub\_project\_alert\_pubsub\_topic | The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}` for the restricted net hub project. | `string` | `null` | no |
5353
| restricted\_net\_hub\_project\_alert\_spent\_percents | A list of percentages of the budget to alert on when threshold is exceeded for the restricted net hub project. | `list(number)` | <pre>[<br> 0.5,<br> 0.75,<br> 0.9,<br> 0.95<br>]</pre> | no |
5454
| restricted\_net\_hub\_project\_budget\_amount | The amount to use as the budget for the restricted net hub project. | `number` | `1000` | no |
55-
| scc\_notification\_filter | Filter used to create the Security Command Center Notification, you can see more details on how to create filters in https://cloud.google.com/security-command-center/docs/how-to-api-filter-notifications#create-filter | `string` | `"state=\\\"ACTIVE\\\""` | no |
55+
| scc\_notification\_filter | Filter used to create the Security Command Center Notification, you can see more details on how to create filters in https://cloud.google.com/security-command-center/docs/how-to-api-filter-notifications#create-filter | `string` | `"state = \"ACTIVE\""` | no |
5656
| scc\_notification\_name | Name of the Security Command Center Notification. It must be unique in the organization. Run `gcloud scc notifications describe <scc_notification_name> --organization=org_id` to check if it already exists. | `string` | n/a | yes |
5757
| scc\_notifications\_project\_alert\_pubsub\_topic | The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}` for the SCC notifications project. | `string` | `null` | no |
5858
| scc\_notifications\_project\_alert\_spent\_percents | A list of percentages of the budget to alert on when threshold is exceeded for the SCC notifications project. | `list(number)` | <pre>[<br> 0.5,<br> 0.75,<br> 0.9,<br> 0.95<br>]</pre> | no |

1-org/envs/shared/scc_notification.tf

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,13 @@ resource "google_pubsub_subscription" "scc_notification_subscription" {
2929
project = module.scc_notifications.project_id
3030
}
3131

32-
module "scc_notification" {
33-
source = "terraform-google-modules/gcloud/google"
34-
version = "~> 1.1.0"
32+
resource "google_scc_notification_config" "scc_notification_config" {
33+
config_id = var.scc_notification_name
34+
organization = var.org_id
35+
description = "SCC Notification for all active findings"
36+
pubsub_topic = google_pubsub_topic.scc_notification_topic.id
3537

36-
additional_components = var.skip_gcloud_download ? [] : ["alpha"]
37-
38-
create_cmd_entrypoint = "gcloud"
39-
create_cmd_body = <<-EOF
40-
scc notifications create ${var.scc_notification_name} --organization ${var.org_id} \
41-
--description "SCC Notification for all active findings" \
42-
--pubsub-topic projects/${module.scc_notifications.project_id}/topics/${google_pubsub_topic.scc_notification_topic.name} \
43-
--filter "${var.scc_notification_filter}" \
44-
--project "${module.scc_notifications.project_id}" \
45-
--impersonate-service-account=${var.terraform_service_account}
46-
EOF
47-
48-
destroy_cmd_entrypoint = "gcloud"
49-
destroy_cmd_body = <<-EOF
50-
scc notifications delete organizations/${var.org_id}/notificationConfigs/${var.scc_notification_name} \
51-
--impersonate-service-account ${var.terraform_service_account} \
52-
--project "${module.scc_notifications.project_id}" \
53-
--quiet
54-
EOF
55-
skip_download = var.skip_gcloud_download
38+
streaming_config {
39+
filter = var.scc_notification_filter
40+
}
5641
}

1-org/envs/shared/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ variable "skip_gcloud_download" {
8181
variable "scc_notification_filter" {
8282
description = "Filter used to create the Security Command Center Notification, you can see more details on how to create filters in https://cloud.google.com/security-command-center/docs/how-to-api-filter-notifications#create-filter"
8383
type = string
84-
default = "state=\\\"ACTIVE\\\""
84+
default = "state = \"ACTIVE\""
8585
}
8686

8787
variable "parent_folder" {

1-org/envs/shared/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ terraform {
1919
required_providers {
2020
google = {
2121
source = "hashicorp/google"
22-
version = ">= 3.50"
22+
version = ">= 3.77"
2323
}
2424
google-beta = {
2525
source = "hashicorp/google-beta"
26-
version = ">= 3.50"
26+
version = ">= 3.77"
2727
}
2828
}
2929

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
## Inputs
3+
4+
| Name | Description | Type | Default | Required |
5+
|------|-------------|------|---------|:--------:|
6+
| associations | Resources to associate the policy to | `list(string)` | n/a | yes |
7+
| name | Hierarchical policy name | `string` | n/a | yes |
8+
| parent | Where the firewall policy will be created (can be organizations/{organization\_id} or folders/{folder\_id}) | `string` | n/a | yes |
9+
| rules | Firewall rules to add to the policy | <pre>map(object({<br> description = string<br> direction = string<br> action = string<br> priority = number<br> ranges = list(string)<br> ports = map(list(string))<br> target_service_accounts = list(string)<br> target_resources = list(string)<br> logging = bool<br> }))</pre> | `{}` | no |
10+
11+
## Outputs
12+
13+
| Name | Description |
14+
|------|-------------|
15+
| id | n/a |
16+
17+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

0 commit comments

Comments
 (0)