-
Notifications
You must be signed in to change notification settings - Fork 286
docs: Add CMEK for Eventarc #827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| # [START eventarc_terraform_cmek_apis] | ||
| # Enable Cloud KMS API | ||
| resource "google_project_service" "cloudkms" { | ||
| service = "cloudkms.googleapis.com" | ||
| disable_on_destroy = false | ||
| } | ||
|
|
||
| # Enable Eventarc API | ||
| resource "google_project_service" "eventarc" { | ||
| service = "eventarc.googleapis.com" | ||
| disable_on_destroy = false | ||
| } | ||
| # [END eventarc_terraform_cmek_apis] | ||
|
|
||
| # Used to retrieve project information later | ||
| data "google_project" "default" { | ||
| } | ||
|
|
||
| # [START eventarc_terraform_cmek_key] | ||
| resource "random_id" "default" { | ||
| byte_length = 8 | ||
| } | ||
|
|
||
| # Create a Cloud KMS key ring | ||
| resource "google_kms_key_ring" "default" { | ||
| name = "${random_id.default.hex}-example-keyring" | ||
| location = "us-central1" | ||
| } | ||
|
|
||
| # Create a Cloud KMS key | ||
| resource "google_kms_crypto_key" "default" { | ||
| name = "example-key" | ||
| key_ring = google_kms_key_ring.default.id | ||
| rotation_period = "7776000s" | ||
| } | ||
| # [END eventarc_terraform_cmek_key] | ||
|
|
||
| # [START eventarc_terraform_cmek_service_agent] | ||
| # Grant service account access to Cloud KMS key | ||
| resource "google_kms_crypto_key_iam_member" "default" { | ||
| crypto_key_id = google_kms_crypto_key.default.id | ||
| role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
| member = "serviceAccount:service-${data.google_project.default.number}@gcp-sa-eventarc.iam.gserviceaccount.com" | ||
| } | ||
| # [END eventarc_terraform_cmek_service_agent] | ||
|
|
||
| # [START eventarc_terraform_cmek_google_channel] | ||
| # Specify a CMEK key for the `GoogleChannelConfig` resource | ||
| resource "google_eventarc_google_channel_config" "default" { | ||
| location = "us-central1" | ||
| name = "googleChannelConfig" | ||
| crypto_key_name = google_kms_crypto_key.default.id | ||
| depends_on = [google_kms_crypto_key_iam_member.default] | ||
| } | ||
| # [END eventarc_terraform_cmek_google_channel] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing due to this service account not existing. IIRC this might be due to the eventual setup of eventarc, and since we're using a brand new project for tests, this is something that may not affect docs consumers.
Other eventarc samples due a dedicated service account rather than the product service account. It doesn't look like other samples on the intended page use the product service account, so I suggest adapting the setup from https://github.com/terraform-google-modules/terraform-docs-samples/blob/main/eventarc/basic/main.tf that uses
google_service_accountto create the service account, then reference it here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Katie! I've added using
google_project_service_identityto generate the Eventarc SA....hopefully, that passes muster.