-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from deseretdigital/feature-create-terraform-mo…
…dule-for-pub-sub-topics-sc-308777 Bump Documentation
- Loading branch information
Showing
12 changed files
with
270 additions
and
18 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,34 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc |
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,94 @@ | ||
# Google PubSub Subscription with BigQuery Output | ||
|
||
This module create a Google PubSub Subscription that will automagically write to a BigQuery table. | ||
|
||
## Usage | ||
|
||
### Basic Configuration: | ||
|
||
```hcl | ||
module "pubsub_subscription_module" { | ||
source = "deseretdigital/ddm-pubsub-subscription/google//modules/big-query" | ||
version = "~> 2.0.0" | ||
# Required | ||
bigquery_table = {TABLE_NAME} | ||
pubsub_service_account = "service-{NUMBERS}@gcp-sa-pubsub.iam.gserviceaccount.com" | ||
subscription_name = {YOUR_SUBSCRIPTION_NAME} | ||
topic_id = {PARENT_TOPIC_ID} | ||
# Optional | ||
labels = { | ||
env = "prod" | ||
region = {REGION} | ||
# etc... | ||
} | ||
use_topic_schema = false | ||
} | ||
``` | ||
|
||
#### Example Usage | ||
|
||
This example assumes you are not using the topic schema and instead are using the table schema. You'll need to know this before you go in which schema you will use as your source of truth. | ||
|
||
```hcl | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "~> 6.0" | ||
} | ||
} | ||
} | ||
provider "google" { | ||
# Configuration options | ||
} | ||
resource "google_pubsub_topic" "example" { | ||
name = "Example_TopicName" | ||
} | ||
resource "google_bigquery_dataset" "test" { | ||
dataset_id = "example_dataset" | ||
} | ||
resource "google_bigquery_table" "test" { | ||
deletion_protection = false | ||
table_id = "example_table" | ||
dataset_id = google_bigquery_dataset.test.dataset_id | ||
schema = <<EOF | ||
[ | ||
{ | ||
"name": "data", | ||
"type": "STRING", | ||
"mode": "NULLABLE", | ||
"description": "The data" | ||
} | ||
] | ||
EOF | ||
} | ||
module "pubsub_subscription_module" { | ||
source = "deseretdigital/ddm-pubsub-subscription/google//modules/big-query" | ||
version = "~> 2.0.0" | ||
# Required | ||
bigquery_table = "${google_bigquery_table.test.project}.${google_bigquery_table.test.dataset_id}.${google_bigquery_table.test.table_id}" | ||
pubsub_service_account = "service-{NUMBERS}@gcp-sa-pubsub.iam.gserviceaccount.com" | ||
subscription_name = "Example_SubscriptionName" | ||
topic_id = google_pubsub_topic.example.id | ||
# Optional | ||
labels = { | ||
env = "prod" | ||
region = {REGION} | ||
# etc... | ||
} | ||
use_topic_schema = false # Since we're using the scheme of 'google_bigquery_table.test' | ||
} | ||
``` |
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,2 @@ | ||
data "google_project" "project" { | ||
} |
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,8 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "~> 6.0" | ||
} | ||
} | ||
} |
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,9 @@ | ||
output "subscription_id" { | ||
value = google_pubsub_subscription.subscription.id | ||
description = "The ID of the created subscription." | ||
} | ||
|
||
output "subscription_name" { | ||
value = google_pubsub_subscription.subscription.name | ||
description = "The name of the created subscription." | ||
} |
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,24 @@ | ||
resource "google_pubsub_subscription" "subscription" { | ||
name = var.subscription_name | ||
topic = var.topic_id | ||
labels = var.labels | ||
|
||
bigquery_config { | ||
use_topic_schema = var.use_topic_schema | ||
table = var.bigquery_table | ||
} | ||
|
||
depends_on = [google_project_iam_member.viewer, google_project_iam_member.editor] | ||
} | ||
|
||
resource "google_project_iam_member" "viewer" { | ||
project = data.google_project.project.project_id | ||
role = "roles/bigquery.metadataViewer" | ||
member = "serviceAccount:${var.pubsub_service_account}" | ||
} | ||
|
||
resource "google_project_iam_member" "editor" { | ||
project = data.google_project.project.project_id | ||
role = "roles/bigquery.dataEditor" | ||
member = "serviceAccount:${var.pubsub_service_account}" | ||
} |
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,42 @@ | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_google"></a> [google](#requirement\_google) | ~> 6.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_google"></a> [google](#provider\_google) | ~> 6.0 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [google_project_iam_member.editor](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_member) | resource | | ||
| [google_project_iam_member.viewer](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_member) | resource | | ||
| [google_pubsub_subscription.subscription](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_subscription) | resource | | ||
| [google_project.project](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/project) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_bigquery_table"></a> [bigquery\_table](#input\_bigquery\_table) | The name of the table to which to write data, of the form {projectId}.{datasetId}.{tableId} | `string` | n/a | yes | | ||
| <a name="input_labels"></a> [labels](#input\_labels) | A set of key/value label pairs to assign to this Topic. | `map(string)` | `{}` | no | | ||
| <a name="input_pubsub_service_account"></a> [pubsub\_service\_account](#input\_pubsub\_service\_account) | The service account to be used by the Pub/Sub system. Looks like 'service-<project-number>@gcp-sa-pubsub.iam.gserviceaccount.com'. | `string` | n/a | yes | | ||
| <a name="input_subscription_name"></a> [subscription\_name](#input\_subscription\_name) | The name of the subscription. | `string` | n/a | yes | | ||
| <a name="input_topic_id"></a> [topic\_id](#input\_topic\_id) | A reference to a Topic resource, of the form projects/{project}/topics/{{name}} (as in the id property of a google\_pubsub\_topic), or just a topic name if the topic is in the same project as the subscription. | `string` | n/a | yes | | ||
| <a name="input_use_topic_schema"></a> [use\_topic\_schema](#input\_use\_topic\_schema) | When true, use the topic's schema as the columns to write to in BigQuery, if it exists. | `bool` | `false` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_subscription_id"></a> [subscription\_id](#output\_subscription\_id) | The ID of the created subscription. | | ||
| <a name="output_subscription_name"></a> [subscription\_name](#output\_subscription\_name) | The name of the created subscription. | |
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,45 @@ | ||
variable "bigquery_table" { | ||
description = "The name of the table to which to write data, of the form {projectId}.{datasetId}.{tableId}" | ||
type = string | ||
|
||
validation { | ||
condition = can(regex("^[^\\.]+\\.[^\\.]+\\.[^\\.]+$", var.bigquery_table)) | ||
error_message = "Value must be a valid BigQuery table name." | ||
} | ||
} | ||
|
||
variable "labels" { | ||
description = "A set of key/value label pairs to assign to this Topic." | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "pubsub_service_account" { | ||
description = "The service account to be used by the Pub/Sub system. Looks like 'service-<project-number>@gcp-sa-pubsub.iam.gserviceaccount.com'." | ||
type = string | ||
validation { | ||
condition = can(regex("^service-\\d+@gcp-sa-pubsub\\.iam\\.gserviceaccount\\.com$", var.pubsub_service_account)) | ||
error_message = "value must be a valid service account email address." | ||
} | ||
} | ||
|
||
variable "subscription_name" { | ||
description = "The name of the subscription." | ||
type = string | ||
} | ||
|
||
variable "topic_id" { | ||
description = " A reference to a Topic resource, of the form projects/{project}/topics/{{name}} (as in the id property of a google_pubsub_topic), or just a topic name if the topic is in the same project as the subscription." | ||
type = string | ||
|
||
validation { | ||
condition = can(regex("projects/[^/]+/topics/[^/]+", var.topic_id)) | ||
error_message = "value must be a reference to a Topic resource, of the form projects/{project}/topics/{{name}}." | ||
} | ||
} | ||
|
||
variable "use_topic_schema" { | ||
description = "When true, use the topic's schema as the columns to write to in BigQuery, if it exists." | ||
type = bool | ||
default = false | ||
} |
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
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