-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add CMEK support for Firestore database in Beta provider (#10044)
* Modify database.yaml to add cmek related fields * Add two examples for firestore CMEK databases for testing * Resolve trailing space * Update documentation for kmsKeyName field * Resolve trailing space * Make field immutable * Update field documentation * Update field description
- Loading branch information
1 parent
ffd2cf3
commit 787da35
Showing
3 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
50 changes: 50 additions & 0 deletions
50
mmv1/templates/terraform/examples/firestore_cmek_database.tf.erb
This file contains 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,50 @@ | ||
data "google_project" "project" { | ||
provider = google-beta | ||
} | ||
|
||
resource "google_firestore_database" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
|
||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
name = "<%= ctx[:vars]['database_id']%>" | ||
location_id = "nam5" | ||
type = "FIRESTORE_NATIVE" | ||
concurrency_mode = "OPTIMISTIC" | ||
app_engine_integration_mode = "DISABLED" | ||
point_in_time_recovery_enablement = "POINT_IN_TIME_RECOVERY_ENABLED" | ||
delete_protection_state = "<%= ctx[:vars]['delete_protection_state'] %>" | ||
deletion_policy = "DELETE" | ||
cmek_config { | ||
kms_key_name = google_kms_crypto_key.crypto_key.id | ||
} | ||
|
||
depends_on = [ | ||
google_kms_crypto_key_iam_binding.firestore_cmek_keyuser | ||
] | ||
} | ||
|
||
resource "google_kms_crypto_key" "crypto_key" { | ||
provider = google-beta | ||
|
||
name = "<%= ctx[:vars]['kms_key_name'] %>" | ||
key_ring = google_kms_key_ring.key_ring.id | ||
purpose = "ENCRYPT_DECRYPT" | ||
} | ||
|
||
resource "google_kms_key_ring" "key_ring" { | ||
provider = google-beta | ||
|
||
name = "<%= ctx[:vars]['kms_key_ring_name'] %>" | ||
location = "us" | ||
} | ||
|
||
resource "google_kms_crypto_key_iam_binding" "firestore_cmek_keyuser" { | ||
provider = google-beta | ||
|
||
crypto_key_id = google_kms_crypto_key.crypto_key.id | ||
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
|
||
members = [ | ||
"serviceAccount:service-${data.google_project.project.number}@gcp-sa-firestore.iam.gserviceaccount.com", | ||
] | ||
} |
50 changes: 50 additions & 0 deletions
50
mmv1/templates/terraform/examples/firestore_cmek_database_in_datastore_mode.tf.erb
This file contains 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,50 @@ | ||
data "google_project" "project" { | ||
provider = google-beta | ||
} | ||
|
||
resource "google_firestore_database" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
|
||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
name = "<%= ctx[:vars]['database_id']%>" | ||
location_id = "nam5" | ||
type = "DATASTORE_MODE" | ||
concurrency_mode = "OPTIMISTIC" | ||
app_engine_integration_mode = "DISABLED" | ||
point_in_time_recovery_enablement = "POINT_IN_TIME_RECOVERY_ENABLED" | ||
delete_protection_state = "<%= ctx[:vars]['delete_protection_state'] %>" | ||
deletion_policy = "DELETE" | ||
cmek_config { | ||
kms_key_name = google_kms_crypto_key.crypto_key.id | ||
} | ||
|
||
depends_on = [ | ||
google_kms_crypto_key_iam_binding.firestore_cmek_keyuser | ||
] | ||
} | ||
|
||
resource "google_kms_crypto_key" "crypto_key" { | ||
provider = google-beta | ||
|
||
name = "<%= ctx[:vars]['kms_key_name'] %>" | ||
key_ring = google_kms_key_ring.key_ring.id | ||
purpose = "ENCRYPT_DECRYPT" | ||
} | ||
|
||
resource "google_kms_key_ring" "key_ring" { | ||
provider = google-beta | ||
|
||
name = "<%= ctx[:vars]['kms_key_ring_name'] %>" | ||
location = "us" | ||
} | ||
|
||
resource "google_kms_crypto_key_iam_binding" "firestore_cmek_keyuser" { | ||
provider = google-beta | ||
|
||
crypto_key_id = google_kms_crypto_key.crypto_key.id | ||
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
|
||
members = [ | ||
"serviceAccount:service-${data.google_project.project.number}@gcp-sa-firestore.iam.gserviceaccount.com", | ||
] | ||
} |