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 user project override support for data.google_kms_secret_ciphertext #2746

Merged
merged 2 commits into from
Nov 25, 2019
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
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (

"encoding/base64"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func dataSourceGoogleKmsSecretCiphertext() *schema.Resource {
Expand Down Expand Up @@ -46,7 +47,11 @@ func dataSourceGoogleKmsSecretCiphertextRead(d *schema.ResourceData, meta interf
Plaintext: plaintext,
}

encryptResponse, err := config.clientKms.Projects.Locations.KeyRings.CryptoKeys.Encrypt(cryptoKeyId.cryptoKeyId(), kmsEncryptRequest).Do()
encryptCall := config.clientKms.Projects.Locations.KeyRings.CryptoKeys.Encrypt(cryptoKeyId.cryptoKeyId(), kmsEncryptRequest)
if config.UserProjectOverride {
encryptCall.Header().Set("X-Goog-User-Project", cryptoKeyId.KeyRingId.Project)
}
encryptResponse, err := encryptCall.Do()

if err != nil {
return fmt.Errorf("Error encrypting plaintext: %s", err)
Expand Down
12 changes: 12 additions & 0 deletions third_party/terraform/utils/provider_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ resource "google_project_iam_member" "project-2-kms" {
member = "serviceAccount:${google_service_account.project-1.email}"
}

resource "google_project_iam_member" "project-2-kms-encrypt" {
project = google_project.project-2.project_id
role = "roles/cloudkms.cryptoKeyEncrypter"
member = "serviceAccount:${google_service_account.project-1.email}"
}

data "google_client_openid_userinfo" "me" {}

// Enable the test runner to get an access token on behalf of
Expand Down Expand Up @@ -479,6 +485,12 @@ resource "google_kms_crypto_key" "project-2-key" {
name = "%s"
key_ring = google_kms_key_ring.project-2-keyring.self_link
}

data "google_kms_secret_ciphertext" "project-2-ciphertext" {
provider = google.project-1-token
crypto_key = google_kms_crypto_key.project-2-key.self_link
plaintext = "my-secret"
}
`, testAccProviderIndirectUserProjectOverride_step3(pid, name, org, billing, sa, override), pid, pid)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ The following arguments are supported:
The following attribute is exported:

* `ciphertext` - Contains the result of encrypting the provided plaintext, encoded in base64.

## User Project Overrides

This data source supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).