-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add custom KMS key support (#25)
Co-authored-by: Calvin Behling <[email protected]>
- Loading branch information
1 parent
0343db7
commit 9516ff1
Showing
7 changed files
with
195 additions
and
4 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
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,39 @@ | ||
# KMS Example | ||
|
||
This example illustrates how to use the `pubsub` module with a custom `kms` key. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| kms\_key\_name | Name of KMS key to use for pubsub topic | string | n/a | yes | | ||
| kms\_keyring\_name | Name of KMS key ring to use for pubsub topic | string | n/a | yes | | ||
| project\_id | The project ID to manage the Pub/Sub resources | string | n/a | yes | | ||
| topic\_labels | A map of labels to assign to the Pub/Sub topic | map(string) | `<map>` | no | | ||
| topic\_name | The name for the Pub/Sub topic | string | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| project\_id | The project ID | | ||
| topic\_labels | The labels of the Pub/Sub topic created | | ||
| topic\_name | The name of the Pub/Sub topic created | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
## Requirements | ||
|
||
The following sections describe the requirements which must be met in | ||
order to invoke this example. The requirements of the | ||
[root module][root-module-requirements] must be met. | ||
|
||
## Usage | ||
|
||
To provision this example, populate `terraform.tfvars` with the [required variables](#inputs) and run the following commands within | ||
this directory: | ||
- `terraform init` to get the plugins | ||
- `terraform plan` to see the infrastructure plan | ||
- `terraform apply` to apply the infrastructure build | ||
- `terraform destroy` to destroy the built infrastructure |
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,73 @@ | ||
/** | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
provider "google" { | ||
version = "~> 2.13" | ||
region = "us-central1" | ||
} | ||
|
||
data "google_project" "project" { | ||
project_id = var.project_id | ||
} | ||
|
||
locals { | ||
pubsub_svc_account_email = "service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com" | ||
} | ||
|
||
data "google_iam_role" "kms_encrypt_decrypt" { | ||
name = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
} | ||
|
||
resource "google_kms_key_ring" "my_key_ring" { | ||
name = "my-key-ring-crqif" | ||
location = "us-central1" | ||
project = var.project_id | ||
} | ||
|
||
resource "google_kms_crypto_key" "my_crypto_key" { | ||
name = "my-crypto-key-ra5jb" | ||
key_ring = google_kms_key_ring.my_key_ring.id | ||
} | ||
|
||
resource "google_project_iam_member" "project" { | ||
project = var.project_id | ||
role = data.google_iam_role.kms_encrypt_decrypt.name | ||
member = "serviceAccount:${local.pubsub_svc_account_email}" | ||
} | ||
|
||
module "pubsub" { | ||
source = "../../" | ||
project_id = var.project_id | ||
topic = var.topic_name | ||
topic_labels = var.topic_labels | ||
topic_kms_key_name = google_kms_crypto_key.my_crypto_key.id | ||
|
||
pull_subscriptions = [ | ||
{ | ||
name = "pull" | ||
ack_deadline_seconds = 10 | ||
}, | ||
] | ||
|
||
push_subscriptions = [ | ||
{ | ||
name = "push" | ||
push_endpoint = "https://${var.project_id}.appspot.com/" | ||
x-goog-version = "v1beta1" | ||
ack_deadline_seconds = 20 | ||
}, | ||
] | ||
} |
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,30 @@ | ||
/** | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
output "project_id" { | ||
value = var.project_id | ||
description = "The project ID" | ||
} | ||
|
||
output "topic_name" { | ||
value = module.pubsub.topic | ||
description = "The name of the Pub/Sub topic created" | ||
} | ||
|
||
output "topic_labels" { | ||
value = module.pubsub.topic_labels | ||
description = "The labels of the Pub/Sub topic created" | ||
} |
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,41 @@ | ||
/** | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
variable "project_id" { | ||
type = string | ||
description = "The project ID to manage the Pub/Sub resources" | ||
} | ||
|
||
variable "topic_name" { | ||
type = string | ||
description = "The name for the Pub/Sub topic" | ||
} | ||
|
||
variable "topic_labels" { | ||
type = map(string) | ||
description = "A map of labels to assign to the Pub/Sub topic" | ||
default = {} | ||
} | ||
|
||
variable "kms_key_name" { | ||
type = string | ||
description = "Name of KMS key to use for pubsub topic" | ||
} | ||
|
||
variable "kms_keyring_name" { | ||
type = string | ||
description = "Name of KMS key ring to use for pubsub topic" | ||
} |
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
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