Skip to content

Commit df5817e

Browse files
authored
chore(KMS): cleanup isolated and redundant KMS resources (#1271)
1 parent ceeead2 commit df5817e

File tree

25 files changed

+26
-116
lines changed

25 files changed

+26
-116
lines changed

0-bootstrap/sa.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ locals {
6262
"roles/accesscontextmanager.policyAdmin",
6363
"roles/resourcemanager.organizationAdmin",
6464
"roles/serviceusage.serviceUsageConsumer",
65+
"roles/cloudkms.admin",
6566
], local.common_roles)),
6667
}
6768

1-org/envs/shared/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
| Name | Description | Type | Default | Required |
55
|------|-------------|------|---------|:--------:|
66
| billing\_export\_dataset\_location | The location of the dataset for billing data export. | `string` | `null` | no |
7-
| cai\_monitoring\_kms\_force\_destroy | If set to true, delete KMS keyring and keys when destroying the module; otherwise, destroying the module will fail if KMS keys are present. | `bool` | `false` | no |
87
| create\_access\_context\_manager\_access\_policy | Whether to create access context manager access policy. | `bool` | `true` | no |
98
| create\_unique\_tag\_key | Creates unique organization-wide tag keys by adding a random suffix to each key. | `bool` | `false` | no |
109
| 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 |
@@ -18,7 +17,7 @@
1817
| log\_export\_storage\_location | The location of the storage bucket used to export logs. | `string` | `null` | no |
1918
| log\_export\_storage\_retention\_policy | Configuration of the bucket's data retention policy for how long objects in the bucket should be retained. | <pre>object({<br> is_locked = bool<br> retention_period_days = number<br> })</pre> | `null` | no |
2019
| log\_export\_storage\_versioning | (Optional) Toggles bucket versioning, ability to retain a non-current object version when the live object version gets replaced or deleted. | `bool` | `false` | no |
21-
| project\_budget | Budget configuration for projects.<br> budget\_amount: The amount to use as the budget.<br> alert\_spent\_percents: A list of percentages of the budget to alert on when threshold is exceeded.<br> 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}`.<br> alert\_spend\_basis: The type of basis used to determine if spend has passed the threshold. Possible choices are `CURRENT_SPEND` or `FORECASTED_SPEND` (default). | <pre>object({<br> dns_hub_budget_amount = optional(number, 1000)<br> dns_hub_alert_spent_percents = optional(list(number), [1.2])<br> dns_hub_alert_pubsub_topic = optional(string, null)<br> dns_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> base_net_hub_budget_amount = optional(number, 1000)<br> base_net_hub_alert_spent_percents = optional(list(number), [1.2])<br> base_net_hub_alert_pubsub_topic = optional(string, null)<br> base_net_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> base_network_budget_amount = optional(number, 1000)<br> base_network_alert_spent_percents = optional(list(number), [1.2])<br> base_network_alert_pubsub_topic = optional(string, null)<br> base_network_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> restricted_net_hub_budget_amount = optional(number, 1000)<br> restricted_net_hub_alert_spent_percents = optional(list(number), [1.2])<br> restricted_net_hub_alert_pubsub_topic = optional(string, null)<br> restricted_net_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> restricted_network_budget_amount = optional(number, 1000)<br> restricted_network_alert_spent_percents = optional(list(number), [1.2])<br> restricted_network_alert_pubsub_topic = optional(string, null)<br> restricted_network_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> interconnect_budget_amount = optional(number, 1000)<br> interconnect_alert_spent_percents = optional(list(number), [1.2])<br> interconnect_alert_pubsub_topic = optional(string, null)<br> interconnect_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_secrets_budget_amount = optional(number, 1000)<br> org_secrets_alert_spent_percents = optional(list(number), [1.2])<br> org_secrets_alert_pubsub_topic = optional(string, null)<br> org_secrets_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_billing_export_budget_amount = optional(number, 1000)<br> org_billing_export_alert_spent_percents = optional(list(number), [1.2])<br> org_billing_export_alert_pubsub_topic = optional(string, null)<br> org_billing_export_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_audit_logs_budget_amount = optional(number, 1000)<br> org_audit_logs_alert_spent_percents = optional(list(number), [1.2])<br> org_audit_logs_alert_pubsub_topic = optional(string, null)<br> org_audit_logs_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_kms_budget_amount = optional(number, 1000)<br> org_kms_alert_spent_percents = optional(list(number), [1.2])<br> org_kms_alert_pubsub_topic = optional(string, null)<br> org_kms_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> scc_notifications_budget_amount = optional(number, 1000)<br> scc_notifications_alert_spent_percents = optional(list(number), [1.2])<br> scc_notifications_alert_pubsub_topic = optional(string, null)<br> scc_notifications_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> })</pre> | `{}` | no |
20+
| project\_budget | Budget configuration for projects.<br> budget\_amount: The amount to use as the budget.<br> alert\_spent\_percents: A list of percentages of the budget to alert on when threshold is exceeded.<br> 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}`.<br> alert\_spend\_basis: The type of basis used to determine if spend has passed the threshold. Possible choices are `CURRENT_SPEND` or `FORECASTED_SPEND` (default). | <pre>object({<br> dns_hub_budget_amount = optional(number, 1000)<br> dns_hub_alert_spent_percents = optional(list(number), [1.2])<br> dns_hub_alert_pubsub_topic = optional(string, null)<br> dns_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> base_net_hub_budget_amount = optional(number, 1000)<br> base_net_hub_alert_spent_percents = optional(list(number), [1.2])<br> base_net_hub_alert_pubsub_topic = optional(string, null)<br> base_net_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> base_network_budget_amount = optional(number, 1000)<br> base_network_alert_spent_percents = optional(list(number), [1.2])<br> base_network_alert_pubsub_topic = optional(string, null)<br> base_network_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> restricted_net_hub_budget_amount = optional(number, 1000)<br> restricted_net_hub_alert_spent_percents = optional(list(number), [1.2])<br> restricted_net_hub_alert_pubsub_topic = optional(string, null)<br> restricted_net_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> restricted_network_budget_amount = optional(number, 1000)<br> restricted_network_alert_spent_percents = optional(list(number), [1.2])<br> restricted_network_alert_pubsub_topic = optional(string, null)<br> restricted_network_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> interconnect_budget_amount = optional(number, 1000)<br> interconnect_alert_spent_percents = optional(list(number), [1.2])<br> interconnect_alert_pubsub_topic = optional(string, null)<br> interconnect_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_secrets_budget_amount = optional(number, 1000)<br> org_secrets_alert_spent_percents = optional(list(number), [1.2])<br> org_secrets_alert_pubsub_topic = optional(string, null)<br> org_secrets_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_billing_export_budget_amount = optional(number, 1000)<br> org_billing_export_alert_spent_percents = optional(list(number), [1.2])<br> org_billing_export_alert_pubsub_topic = optional(string, null)<br> org_billing_export_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_audit_logs_budget_amount = optional(number, 1000)<br> org_audit_logs_alert_spent_percents = optional(list(number), [1.2])<br> org_audit_logs_alert_pubsub_topic = optional(string, null)<br> org_audit_logs_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> common_kms_budget_amount = optional(number, 1000)<br> common_kms_alert_spent_percents = optional(list(number), [1.2])<br> common_kms_alert_pubsub_topic = optional(string, null)<br> common_kms_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> scc_notifications_budget_amount = optional(number, 1000)<br> scc_notifications_alert_spent_percents = optional(list(number), [1.2])<br> scc_notifications_alert_pubsub_topic = optional(string, null)<br> scc_notifications_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> })</pre> | `{}` | no |
2221
| remote\_state\_bucket | Backend bucket to load Terraform Remote State Data from previous steps. | `string` | n/a | yes |
2322
| 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 |
2423
| 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 |
@@ -35,6 +34,7 @@
3534
| cai\_monitoring\_bucket | CAI Monitoring Cloud Function Source Bucket name. |
3635
| cai\_monitoring\_topic | CAI Monitoring Cloud Function Pub/Sub Topic name. |
3736
| common\_folder\_name | The common folder name |
37+
| common\_kms\_project\_id | The org Cloud Key Management Service (KMS) project ID |
3838
| dns\_hub\_project\_id | The DNS hub project ID |
3939
| domains\_to\_allow | The list of domains to allow users from in IAM. |
4040
| interconnect\_project\_id | The Dedicated Interconnect project ID |
@@ -47,7 +47,6 @@
4747
| org\_audit\_logs\_project\_id | The org audit logs project ID. |
4848
| org\_billing\_export\_project\_id | The org billing export project ID |
4949
| org\_id | The organization id |
50-
| org\_kms\_project\_id | The org Cloud Key Management Service (KMS) project ID |
5150
| org\_secrets\_project\_id | The org secrets project ID |
5251
| parent\_resource\_id | The parent resource id |
5352
| parent\_resource\_type | The parent resource type |

1-org/envs/shared/cai_monitoring.tf

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
module "kms" {
18-
source = "terraform-google-modules/kms/google"
19-
version = "~> 2.1"
20-
21-
project_id = module.scc_notifications.project_id
22-
keyring = "krg-cai-monitoring"
23-
location = local.default_region
24-
keys = ["key-cai-monitoring"]
25-
prevent_destroy = !var.cai_monitoring_kms_force_destroy
26-
}
27-
2817
module "cai_monitoring" {
2918
source = "../../modules/cai-monitoring"
3019

3120
org_id = local.org_id
3221
billing_account = local.billing_account
3322
project_id = module.scc_notifications.project_id
3423
location = local.default_region
35-
enable_cmek = true
36-
encryption_key = module.kms.keys["key-cai-monitoring"]
3724
}

1-org/envs/shared/iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ resource "google_project_iam_member" "global_secrets_admin" {
184184

185185
resource "google_project_iam_member" "kms_admin" {
186186
count = var.gcp_groups.kms_admin != null ? 1 : 0
187-
project = module.org_kms.project_id
187+
project = module.common_kms.project_id
188188
role = "roles/cloudkms.viewer"
189189
member = "group:${var.gcp_groups.kms_admin}"
190190
}

1-org/envs/shared/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ output "org_secrets_project_id" {
5959
description = "The org secrets project ID"
6060
}
6161

62-
output "org_kms_project_id" {
63-
value = module.org_kms.project_id
62+
output "common_kms_project_id" {
63+
value = module.common_kms.project_id
6464
description = "The org Cloud Key Management Service (KMS) project ID"
6565
}
6666

1-org/envs/shared/projects.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ module "org_billing_export" {
9595
}
9696

9797
/******************************************
98-
Project for Org-wide KMS
98+
Project for Common-folder KMS
9999
*****************************************/
100100

101-
module "org_kms" {
101+
module "common_kms" {
102102
source = "terraform-google-modules/project-factory/google"
103103
version = "~> 15.0"
104104

@@ -122,10 +122,10 @@ module "org_kms" {
122122
vpc = "none"
123123
}
124124

125-
budget_alert_pubsub_topic = var.project_budget.org_kms_alert_pubsub_topic
126-
budget_alert_spent_percents = var.project_budget.org_kms_alert_spent_percents
127-
budget_amount = var.project_budget.org_kms_budget_amount
128-
budget_alert_spend_basis = var.project_budget.org_kms_budget_alert_spend_basis
125+
budget_alert_pubsub_topic = var.project_budget.common_kms_alert_pubsub_topic
126+
budget_alert_spent_percents = var.project_budget.common_kms_alert_spent_percents
127+
budget_amount = var.project_budget.common_kms_budget_amount
128+
budget_alert_spend_basis = var.project_budget.common_kms_budget_alert_spend_basis
129129
}
130130

131131
/******************************************

1-org/envs/shared/variables.tf

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ variable "project_budget" {
133133
org_audit_logs_alert_spent_percents = optional(list(number), [1.2])
134134
org_audit_logs_alert_pubsub_topic = optional(string, null)
135135
org_audit_logs_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
136-
org_kms_budget_amount = optional(number, 1000)
137-
org_kms_alert_spent_percents = optional(list(number), [1.2])
138-
org_kms_alert_pubsub_topic = optional(string, null)
139-
org_kms_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
136+
common_kms_budget_amount = optional(number, 1000)
137+
common_kms_alert_spent_percents = optional(list(number), [1.2])
138+
common_kms_alert_pubsub_topic = optional(string, null)
139+
common_kms_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
140140
scc_notifications_budget_amount = optional(number, 1000)
141141
scc_notifications_alert_spent_percents = optional(list(number), [1.2])
142142
scc_notifications_alert_pubsub_topic = optional(string, null)
@@ -187,11 +187,6 @@ variable "create_unique_tag_key" {
187187
type = bool
188188
default = false
189189
}
190-
variable "cai_monitoring_kms_force_destroy" {
191-
description = "If set to true, delete KMS keyring and keys when destroying the module; otherwise, destroying the module will fail if KMS keys are present."
192-
type = bool
193-
default = false
194-
}
195190

196191
variable "tfc_org_name" {
197192
description = "Name of the TFC organization"

1-org/modules/cai-monitoring/iam.tf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ data "google_storage_project_service_account" "gcs_sa" {
4646
project = var.project_id
4747
}
4848

49-
// Encrypter/Decrypter role
50-
resource "google_kms_crypto_key_iam_member" "encrypter_decrypter" {
51-
for_each = var.enable_cmek ? local.identities : {}
52-
53-
crypto_key_id = var.encryption_key
54-
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
55-
member = each.value
56-
}
57-
5849
// Cloud Function SA
5950
resource "google_service_account" "cloudfunction" {
6051
account_id = "cai-monitoring"
@@ -80,7 +71,6 @@ resource "google_project_iam_member" "cloudfunction_iam" {
8071
resource "time_sleep" "wait_kms_iam" {
8172
create_duration = "60s"
8273
depends_on = [
83-
google_kms_crypto_key_iam_member.encrypter_decrypter,
8474
google_organization_iam_member.cloudfunction_findings_editor,
8575
google_project_iam_member.cloudfunction_iam
8676
]

4-projects/business_unit_1/development/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
| base\_subnets\_self\_links | The self-links of subnets from base environment. |
2222
| bucket | The created storage bucket. |
2323
| default\_region | The default region for the project. |
24-
| env\_kms\_project | Project sample for KMS usage project ID. |
2524
| floating\_project | Project sample floating project. |
2625
| iap\_firewall\_tags | The security tags created for IAP (SSH and RDP) firewall rules and to be used on the VM created on step 5-app-infra on the peering network project. |
2726
| keyring | The name of the keyring. |

4-projects/business_unit_1/development/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ output "peering_complete" {
7979
value = module.env.peering_complete
8080
}
8181

82-
output "env_kms_project" {
83-
description = "Project sample for KMS usage project ID."
84-
value = module.env.env_kms_project
85-
}
86-
8782
output "keyring" {
8883
description = "The name of the keyring."
8984
value = module.env.keyring

0 commit comments

Comments
 (0)