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

[TEST ONLY] Request reviewer #14

Closed
wants to merge 4 commits into from
Closed
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 products/pubsub/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ objects:
required: true
description: 'Name of the topic.'
input: true
- !ruby/object:Api::Type::String
name: 'kmsKeyName'
description: |
The resource name of the Cloud KMS CryptoKey to be used to protect access
to messsages published on this topic. Your project's PubSub service account
(`service-{{PROJECT_NUMBER}}@gcp-sa-pubsub.iam.gserviceaccount.com`) must have
`roles/cloudkms.cryptoKeyEncrypterDecrypter` to use this feature.

The expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`
input: true
- !ruby/object:Api::Type::KeyValuePairs
name: 'labels'
description: |
Expand Down
8 changes: 8 additions & 0 deletions products/pubsub/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ overrides: !ruby/object:Overrides::ResourceOverrides
primary_resource_id: "example"
vars:
topic_name: "example-topic"
- !ruby/object:Provider::Terraform::Examples
name: "pubsub_topic_cmek"
primary_resource_id: "example"
skip_test: true
vars:
topic_name: "example-topic"
key_name: "example-key"
keyring_name: "example-keyring"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'compareSelfLinkOrResourceName'
Expand Down
14 changes: 14 additions & 0 deletions templates/terraform/examples/pubsub_topic_cmek.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "google_pubsub_topic" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['topic_name'] %>"
kms_key_name = "${google_kms_crypto_key.crypto_key.self_link}"
}

resource "google_kms_crypto_key" "crypto_key" {
name = "<%= ctx[:vars]['key_name'] %>"
key_ring = "${google_kms_key_ring.key_ring.self_link}"
}

resource "google_kms_key_ring" "key_ring" {
name = "<%= ctx[:vars]['keyring_name'] %>"
location = "global"
}
43 changes: 43 additions & 0 deletions third_party/terraform/tests/resource_pubsub_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ func TestAccPubsubTopic_update(t *testing.T) {
})
}

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

kms := BootstrapKMSKey(t)
pid := getTestProjectFromEnv()
topicName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccPubsubTopic_cmek(pid, topicName, kms.CryptoKey.Name),
},
{
ResourceName: "google_pubsub_topic.topic",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccPubsubTopic_update(topic, key, value string) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
Expand All @@ -50,3 +73,23 @@ resource "google_pubsub_topic" "foo" {
}
`, topic, key, value)
}

func testAccPubsubTopic_cmek(pid, topicName, kmsKey string) string {
return fmt.Sprintf(`
data "google_project" "project" {
project_id = "%s"
}

resource "google_project_iam_member" "kms-project-binding" {
project = "${data.google_project.project.project_id}"
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com"
}

resource "google_pubsub_topic" "topic" {
name = "%s"
project = "${google_project_iam_member.kms-project-binding.project}"
kms_key_name = "%s"
}
`, pid, topicName, kmsKey)
}