Skip to content

Commit bc096e9

Browse files
authored
docs: Create main.tf
Per b/404495162
1 parent 9c92e68 commit bc096e9

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

eventarc/use_cmek/main.tf

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright 2025 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+
# [START eventarc_terraform_cmek_apis]
18+
# Enable Cloud KMS API
19+
resource "google_project_service" "cloudkms" {
20+
service = "cloudkms.googleapis.com"
21+
disable_on_destroy = false
22+
}
23+
24+
# Enable Eventarc API
25+
resource "google_project_service" "eventarc" {
26+
service = "eventarc.googleapis.com"
27+
disable_on_destroy = false
28+
}
29+
# [END eventarc_terraform_cmek_apis]
30+
31+
# Used to retrieve project information later
32+
data "google_project" "default" {
33+
}
34+
35+
# [START eventarc_terraform_cmek_key]
36+
resource "random_id" "default" {
37+
byte_length = 8
38+
}
39+
40+
# Create a Cloud KMS key ring
41+
resource "google_kms_key_ring" "default" {
42+
name = "${random_id.default.hex}-example-keyring"
43+
location = "us-central1"
44+
}
45+
46+
# Create a Cloud KMS key
47+
resource "google_kms_crypto_key" "default" {
48+
name = "example-key"
49+
key_ring = google_kms_key_ring.default.id
50+
rotation_period = "7776000s"
51+
}
52+
# [END eventarc_terraform_cmek_key]
53+
54+
# [START eventarc_terraform_cmek_service_agent]
55+
# Grant service account access to Cloud KMS key
56+
resource "google_kms_crypto_key_iam_member" "default" {
57+
crypto_key_id = google_kms_crypto_key.default.id
58+
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
59+
member = "serviceAccount:service-${data.google_project.default.number}@gcp-sa-eventarc.iam.gserviceaccount.com"
60+
}
61+
# [END eventarc_terraform_cmek_service_agent]
62+
63+
# [START eventarc_terraform_cmek_google_channel]
64+
# Specify a CMEK key for the `GoogleChannelConfig` resource
65+
resource "google_eventarc_google_channel_config" "default" {
66+
location = "us-central1"
67+
name = "googleChannelConfig"
68+
crypto_key_name = google_kms_crypto_key.default.id
69+
depends_on = [google_kms_crypto_key_iam_member.default]
70+
}
71+
# [END eventarc_terraform_cmek_google_channel]

0 commit comments

Comments
 (0)