Skip to content
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

add secret manager cmek #4752

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mmv1/products/secretmanager/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ objects:
required: true
description: |
The canonical IDs of the location to replicate data. For example: "us-east1".
- !ruby/object:Api::Type::NestedObject
name: customerManagedEncryption
description: |
Customer Managed Encryption for the secret.
properties:
- !ruby/object:Api::Type::String
name: kmsKeyName
required: true
description: |
Describes the Cloud KMS encryption key that will be used to protect destination secret.
- !ruby/object:Api::Resource
name: SecretVersion
base_url: '{{name}}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ func TestAccSecretManagerSecret_import(t *testing.T) {
})
}

func TestAccSecretManagerSecret_cmek(t *testing.T) {
t.Parallel()

kmscentral := BootstrapKMSKeyInLocation(t, "us-central1")
kmseast := BootstrapKMSKeyInLocation(t, "us-east1")
context1 := map[string]interface{}{
"pid": getTestProjectFromEnv(),
"random_suffix": randString(t, 10),
"kms_key_name_central": kmscentral.CryptoKey.Name,
"kms_key_name_east": kmseast.CryptoKey.Name,
}
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSecretManagerSecretDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccSecretMangerSecret_cmek(context1),
},
{
ResourceName: "google_secret_manager_secret.secret-basic",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccSecretManagerSecret_basic(context map[string]interface{}) string {
return Nprintf(`
resource "google_secret_manager_secret" "secret-basic" {
Expand All @@ -56,3 +84,41 @@ resource "google_secret_manager_secret" "secret-basic" {
}
`, context)
}

func testAccSecretMangerSecret_cmek(context map[string]interface{}) string {
return Nprintf(`
data "google_project" "project" {
project_id = "%{pid}"
}
resource "google_project_iam_member" "kms-secret-binding" {
project = data.google_project.project.project_id
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-secretmanager.iam.gserviceaccount.com"
}
resource "google_secret_manager_secret" "secret-basic" {
secret_id = "tf-test-secret-%{random_suffix}"

labels = {
label = "my-label"
}
replication {
user_managed {
replicas {
location = "us-central1"
customer_managed_encryption {
kms_key_name = "%{kms_key_name_central}"
}
}
replicas {
location = "us-east1"
customer_managed_encryption {
kms_key_name = "%{kms_key_name_east}"
}
}

}
}
project = google_project_iam_member.kms-secret-binding.project
}
`, context)
}