|
| 1 | +# terraform-google-pubsub |
| 2 | + |
| 3 | +This module makes it easy to create Google Cloud Pub/Sub topic and subscriptions associated with the topic. |
| 4 | + |
| 5 | +## Compatibility |
| 6 | +This module is meant for use with Terraform 0.13+ and tested using Terraform 1.0+. If you find incompatibilities using Terraform >=0.13, please open an issue. |
| 7 | + If you haven't |
| 8 | +[upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform |
| 9 | +0.12.x-compatible version of this module, the last released version |
| 10 | +intended for Terraform 0.12.x is [v1.9.0](https://registry.terraform.io/modules/terraform-google-modules/-pubsub/google/v1.9.0). |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +This is a simple usage of the module. Please see also a simple setup provided in the example directory. |
| 15 | + |
| 16 | +```hcl |
| 17 | +module "pubsub" { |
| 18 | + source = "terraform-google-modules/pubsub/google" |
| 19 | + version = "~> 7.0" |
| 20 | +
|
| 21 | + topic = "tf-topic" |
| 22 | + project_id = "my-pubsub-project" |
| 23 | + push_subscriptions = [ |
| 24 | + { |
| 25 | + name = "push" // required |
| 26 | + ack_deadline_seconds = 20 // optional |
| 27 | + push_endpoint = "https://example.com" // required |
| 28 | + x-goog-version = "v1beta1" // optional |
| 29 | + oidc_service_account_email = "[email protected]" // optional |
| 30 | + audience = "example" // optional |
| 31 | + expiration_policy = "1209600s" // optional |
| 32 | + dead_letter_topic = "projects/my-pubsub-project/topics/example-dl-topic" // optional |
| 33 | + max_delivery_attempts = 5 // optional |
| 34 | + maximum_backoff = "600s" // optional |
| 35 | + minimum_backoff = "300s" // optional |
| 36 | + filter = "attributes.domain = \"com\"" // optional |
| 37 | + enable_message_ordering = true // optional |
| 38 | + } |
| 39 | + ] |
| 40 | + pull_subscriptions = [ |
| 41 | + { |
| 42 | + name = "pull" // required |
| 43 | + ack_deadline_seconds = 20 // optional |
| 44 | + dead_letter_topic = "projects/my-pubsub-project/topics/example-dl-topic" // optional |
| 45 | + max_delivery_attempts = 5 // optional |
| 46 | + maximum_backoff = "600s" // optional |
| 47 | + minimum_backoff = "300s" // optional |
| 48 | + filter = "attributes.domain = \"com\"" // optional |
| 49 | + enable_message_ordering = true // optional |
| 50 | + service_account = "[email protected]" // optional |
| 51 | + enable_exactly_once_delivery = true // optional |
| 52 | + } |
| 53 | + ] |
| 54 | + bigquery_subscriptions = [ |
| 55 | + { |
| 56 | + name = "bigquery" // required |
| 57 | + table = "project.dataset.table" // required |
| 58 | + use_topic_schema = true // optional |
| 59 | + use_table_schema = false // optional |
| 60 | + write_metadata = false // optional |
| 61 | + drop_unknown_fields = false // optional |
| 62 | + } |
| 63 | + ] |
| 64 | + cloud_storage_subscriptions = [ |
| 65 | + { |
| 66 | + name = "cloud-storage" // required |
| 67 | + bucket = "example-bucket" // required |
| 68 | + filename_prefix = "log_events_" // optional |
| 69 | + filename_suffix = ".avro" // optional |
| 70 | + filename_datetime_format = "YYYY-MM-DD/hh_mm_ssZ" // optional |
| 71 | + max_duration = "60s" // optional |
| 72 | + max_bytes = "10000000" // optional |
| 73 | + max_messages = "10000" // optional |
| 74 | + output_format = "avro" // optional |
| 75 | + write_metadata = false // optional |
| 76 | + use_topic_schema = false // optional |
| 77 | + } |
| 78 | + ] |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
| 83 | +## Inputs |
| 84 | + |
| 85 | +| Name | Description | Type | Default | Required | |
| 86 | +|------|-------------|------|---------|:--------:| |
| 87 | +| create\_topic | Specify true if you want to create a topic. | `bool` | `true` | no | |
| 88 | +| message\_storage\_policy | A map of storage policies. Default - inherit from organization's Resource Location Restriction policy. | `map(any)` | `{}` | no | |
| 89 | +| project\_id | The project ID to manage the Pub/Sub resources. | `string` | n/a | yes | |
| 90 | +| schema | Schema for the topic. | <pre>object({<br> name = string<br> type = string<br> definition = string<br> encoding = string<br> })</pre> | `null` | no | |
| 91 | +| topic | The Pub/Sub topic name. | `string` | n/a | yes | |
| 92 | +| topic\_kms\_key\_name | The resource name of the Cloud KMS CryptoKey to be used to protect access to messages published on this topic. | `string` | `null` | no | |
| 93 | +| topic\_labels | A map of labels to assign to the Pub/Sub topic. | `map(string)` | `{}` | no | |
| 94 | +| topic\_message\_retention\_duration | The minimum duration in seconds to retain a message after it is published to the topic. | `string` | `null` | no | |
| 95 | + |
| 96 | +## Outputs |
| 97 | + |
| 98 | +| Name | Description | |
| 99 | +|------|-------------| |
| 100 | +| id | The ID of the Pub/Sub topic | |
| 101 | +| topic | The name of the Pub/Sub topic | |
| 102 | +| topic\_labels | Labels assigned to the Pub/Sub topic | |
| 103 | +| uri | The URI of the Pub/Sub topic | |
| 104 | + |
| 105 | +<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
| 106 | + |
| 107 | +## Requirements |
| 108 | + |
| 109 | +### Installation Dependencies |
| 110 | + |
| 111 | +- [Terraform](https://www.terraform.io/downloads.html) >= 0.13.0 |
| 112 | +- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin >= v2.13 |
| 113 | + |
| 114 | +### Configure a Service Account |
| 115 | + |
| 116 | +In order to execute this module you must have a Service Account with the following: |
| 117 | + |
| 118 | +#### Roles |
| 119 | + |
| 120 | +- `roles/pubsub.admin` |
| 121 | + |
| 122 | +### Enable APIs |
| 123 | + |
| 124 | +In order to operate with the Service Account you must activate the following APIs on the project where the Service Account was created: |
| 125 | + |
| 126 | +- Cloud Pub/Sub API |
| 127 | + |
| 128 | +#### Service Account Credentials |
| 129 | + |
| 130 | +You can pass the service account credentials into this module by setting the following environment variables: |
| 131 | + |
| 132 | +* `GOOGLE_CREDENTIALS` |
| 133 | +* `GOOGLE_CLOUD_KEYFILE_JSON` |
| 134 | +* `GCLOUD_KEYFILE_JSON` |
| 135 | + |
| 136 | +See more [details](https://www.terraform.io/docs/providers/google/provider_reference.html#configuration-reference). |
| 137 | + |
| 138 | +[v0.2.0]: https://registry.terraform.io/modules/terraform-google-modules/pubsub/google/0.2.0 |
| 139 | +[terraform-0.12-upgrade]: https://www.terraform.io/upgrade-guides/0-12.html |
0 commit comments