From cf9fa396382a99ebe16a7d65d438e66270129c38 Mon Sep 17 00:00:00 2001 From: Ian Knighton Date: Fri, 11 Oct 2024 08:39:17 -0600 Subject: [PATCH 1/4] chore: update release tagging --- .github/workflows/release-tagging.yml | 52 ++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-tagging.yml b/.github/workflows/release-tagging.yml index b1f84bc..a7d58db 100644 --- a/.github/workflows/release-tagging.yml +++ b/.github/workflows/release-tagging.yml @@ -34,4 +34,54 @@ jobs: with: tag: ${{ needs.release-tag.outputs.RELEASE_TAG }} name: Release ${{ needs.release-tag.outputs.RELEASE_TAG }} - body: ${{ needs.release-tag.outputs.RELEASE_TAG }} \ No newline at end of file + body: ${{ needs.release-tag.outputs.RELEASE_TAG }} + + release-notifier: + runs-on: ubuntu-latest + needs: ['release-tag', 'create-release'] + name: 'Release Notifier' + steps: + - name: Send Notification + uses: slackapi/slack-github-action@v1.27.0 + env: + SLACK_BOT_TOKEN: ${{ secrets.RELEASE_SLACKBOT_TOKEN }} + with: + channel-id: release + payload: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": ":terraform: ${{github.event.repository.name}} release", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*${{github.event.repository.name}}* release." + }, + "accessory": { + "type": "button", + "text": { + "type": "plain_text", + "text": "${{needs.release-tag.outputs.RELEASE_TAG}}", + "emoji": true + }, + "url": "https://github.com/deseretdigital/${{github.event.repository.name}}/releases/tag/${{needs.release-tag.outputs.RELEASE_TAG}}" + } + }, + { + "type": "context", + "elements": [ + { + "type": "mrkdwn", + "text": "_This is an automated message. It does not indicate the deploy was successful, and it will not post here if it has failed. Please check the action run for more details._" + } + ] + } + ] + } \ No newline at end of file From e2100b078c8536d67feae2700b84d3621bf822f7 Mon Sep 17 00:00:00 2001 From: Ian Knighton Date: Fri, 11 Oct 2024 08:49:27 -0600 Subject: [PATCH 2/4] docs: update documentation --- .github/workflows/release-tagging.yml | 2 +- README.md | 94 ++++++++++++++++----------- terraform-docs.md | 36 ++++++++++ variables.tf | 1 + 4 files changed, 93 insertions(+), 40 deletions(-) create mode 100644 terraform-docs.md diff --git a/.github/workflows/release-tagging.yml b/.github/workflows/release-tagging.yml index a7d58db..17635f4 100644 --- a/.github/workflows/release-tagging.yml +++ b/.github/workflows/release-tagging.yml @@ -34,7 +34,7 @@ jobs: with: tag: ${{ needs.release-tag.outputs.RELEASE_TAG }} name: Release ${{ needs.release-tag.outputs.RELEASE_TAG }} - body: ${{ needs.release-tag.outputs.RELEASE_TAG }} + generateReleaseNotes: true release-notifier: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 5f63aed..9944465 100644 --- a/README.md +++ b/README.md @@ -4,42 +4,58 @@ This module creates a Google PubSub Topic. The primary point is to make the creation of these resources repeatable. -# Terraform-Docs - -## Requirements - -| Name | Version | -|------|---------| -| [google](#requirement\_google) | 6.5.0 | - -## Providers - -| Name | Version | -|------|---------| -| [google](#provider\_google) | 6.5.0 | - -## Modules - -No modules. - -## Resources - -| Name | Type | -|------|------| -| [google_pubsub_topic.topic](https://registry.terraform.io/providers/hashicorp/google/6.5.0/docs/resources/pubsub_topic) | resource | - -## Inputs - -| Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| -| [labels](#input\_labels) | A set of key/value label pairs to assign to this Topic. | `map(string)` | n/a | yes | -| [message\_retention\_duration](#input\_message\_retention\_duration) | Indicates the minimum duration to retain a message after it is published to the topic. If this field is set, messages published to the topic in the last messageRetentionDuration are always available to subscribers. For instance, it allows any attached subscription to seek to a timestamp that is up to messageRetentionDuration in the past. If this field is not set, message retention is controlled by settings on individual subscriptions. | `string` | `null` | no | -| [schema](#input\_schema) | The name of the schema that messages published should be validated against. | `string` | n/a | yes | -| [schema\_encoding](#input\_schema\_encoding) | The encoding of messages validated against schema. Default value is ENCODING\_UNSPECIFIED. Possible values are: ENCODING\_UNSPECIFIED, JSON, BINARY. | `string` | n/a | yes | -| [topic\_name](#input\_topic\_name) | Name of the topic. | `string` | n/a | yes | - -## Outputs - -| Name | Description | -|------|-------------| -| [topic\_id](#output\_topic\_id) | The ID of the created Pub/Sub Topic. | \ No newline at end of file +## Usage + +### Basic Configuration: + +```hcl +module "pubsub_topic_module" { + source = "deseretdigital/ddm-pubsub-topic/google" + version = "~> 1.0.0" + + # Required + topic_name = {YOUR_TOPIC_NAME} + + # Optional + labels = { + env = "prod" + region = {REGION} + # etc... + } + + message_retention_duration = {DEFAULT_2678400s} +} +``` + +This module creates a Google PubSub Topic. + +#### Example Usage + +```hcl +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 6.0" + } + } +} + +provider "google" { + # Configuration options +} + +module "pubsub_topic_module" { + source = "deseretdigital/ddm-pubsub-topic/google" + version = "~> 1.0.0" + topic_name = "Example_TopicName" + + labels = { + date = "2024-10-11" + region = "us-west3" + env = "prod" + } + + message_retention_duration = "84000s" +} +``` \ No newline at end of file diff --git a/terraform-docs.md b/terraform-docs.md new file mode 100644 index 0000000..f893a91 --- /dev/null +++ b/terraform-docs.md @@ -0,0 +1,36 @@ +## Requirements + +| Name | Version | +|------|---------| +| [google](#requirement\_google) | 6.5.0 | + +## Providers + +| Name | Version | +|------|---------| +| [google](#provider\_google) | 6.5.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [google_pubsub_topic.topic](https://registry.terraform.io/providers/hashicorp/google/6.5.0/docs/resources/pubsub_topic) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [labels](#input\_labels) | A set of key/value label pairs to assign to this Topic. | `map(string)` | `{}` | no | +| [message\_retention\_duration](#input\_message\_retention\_duration) | Indicates the minimum duration to retain a message after it is published to the topic. If this field is set, messages published to the topic in the last messageRetentionDuration are always available to subscribers. For instance, it allows any attached subscription to seek to a timestamp that is up to messageRetentionDuration in the past. If this field is not set, message retention is controlled by settings on individual subscriptions. | `string` | `"2678400s"` | no | +| [topic\_name](#input\_topic\_name) | Name of the topic. | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [topic\_id](#output\_topic\_id) | The ID of the created Pub/Sub Topic. | +| [topic\_name](#output\_topic\_name) | The name of the created Pub/Sub Topic. | \ No newline at end of file diff --git a/variables.tf b/variables.tf index 27a3d66..74e9bcb 100644 --- a/variables.tf +++ b/variables.tf @@ -1,6 +1,7 @@ variable "labels" { description = "A set of key/value label pairs to assign to this Topic." type = map(string) + default = {} } variable "message_retention_duration" { From 0ecf634fa900979e175ee2d5db794073f8528d3b Mon Sep 17 00:00:00 2001 From: Ian Knighton Date: Fri, 11 Oct 2024 08:50:51 -0600 Subject: [PATCH 3/4] docs: fix formatting --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9944465..f351e94 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ This module creates a Google PubSub Topic. terraform { required_providers { google = { - source = "hashicorp/google" + source = "hashicorp/google" version = "~> 6.0" } } @@ -46,8 +46,8 @@ provider "google" { } module "pubsub_topic_module" { - source = "deseretdigital/ddm-pubsub-topic/google" - version = "~> 1.0.0" + source = "deseretdigital/ddm-pubsub-topic/google" + version = "~> 1.0.0" topic_name = "Example_TopicName" labels = { From 5fe74f4f5f3726d6bb992dabb7d46cd1ba544656 Mon Sep 17 00:00:00 2001 From: Ian Knighton Date: Fri, 11 Oct 2024 09:03:59 -0600 Subject: [PATCH 4/4] feat: adds schema submodule BREAKING CHANGE: this introduces some new file structure and a need to mark as a breaking change --- modules/topic-schema/README.md | 71 ++++++++++++++++++++++++++ modules/topic-schema/data.tf | 0 modules/topic-schema/main.tf | 8 +++ modules/topic-schema/outputs.tf | 9 ++++ modules/topic-schema/resources.tf | 6 +++ modules/topic-schema/terraform-docs.md | 38 ++++++++++++++ modules/topic-schema/variables.tf | 42 +++++++++++++++ 7 files changed, 174 insertions(+) create mode 100644 modules/topic-schema/README.md create mode 100644 modules/topic-schema/data.tf create mode 100644 modules/topic-schema/main.tf create mode 100644 modules/topic-schema/outputs.tf create mode 100644 modules/topic-schema/resources.tf create mode 100644 modules/topic-schema/terraform-docs.md create mode 100644 modules/topic-schema/variables.tf diff --git a/modules/topic-schema/README.md b/modules/topic-schema/README.md new file mode 100644 index 0000000..7c96e2f --- /dev/null +++ b/modules/topic-schema/README.md @@ -0,0 +1,71 @@ +# Google PubSub Topic with Schema + +This module creates a Google PubSub Topic with a provided schema. + +## Usage + +### Basic Configuration: + +```hcl +module "pubsub_topic_module" { + source = "deseretdigital/ddm-pubsub-topic/google" + version = "~> 1.0.0" + + # Required + topic_name = {YOUR_TOPIC_NAME} + schema = {YOUR_SCHEMA} + schema_encoding = {SCHEMA_ENCODING} + + # Optional + labels = { + env = "prod" + region = {REGION} + # etc... + } + + message_retention_duration = {DEFAULT_2678400s} +} +``` + +This module creates a Google PubSub Topic. + +#### Example Usage + +```hcl +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 6.0" + } + } +} + +provider "google" { + # Configuration options +} + +resource "google_pubsub_schema" "example" { + name = "example" + type = "AVRO" + definition = "{\n \"type\" : \"record\",\n \"name\" : \"Avro\",\n \"fields\" : [\n {\n \"name\" : \"StringField\",\n \"type\" : \"string\"\n },\n {\n \"name\" : \"IntField\",\n \"type\" : \"int\"\n }\n ]\n}\n" +} + +module "pubsub_topic_module" { + source = "deseretdigital/ddm-pubsub-topic/google" + version = "~> 1.0.0" + topic_name = "Example_TopicName" + schema = "projects/{PROJECT_NAME}/schemas/example" + schema_encoding = "JSON" + + labels = { + date = "2024-10-11" + region = "us-west3" + env = "prod" + } + + message_retention_duration = "84000s" + + depends_on = [google_pubsub_schema.example] +} +``` \ No newline at end of file diff --git a/modules/topic-schema/data.tf b/modules/topic-schema/data.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/topic-schema/main.tf b/modules/topic-schema/main.tf new file mode 100644 index 0000000..f07bf16 --- /dev/null +++ b/modules/topic-schema/main.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "6.5.0" + } + } +} \ No newline at end of file diff --git a/modules/topic-schema/outputs.tf b/modules/topic-schema/outputs.tf new file mode 100644 index 0000000..4fac8f2 --- /dev/null +++ b/modules/topic-schema/outputs.tf @@ -0,0 +1,9 @@ +output "topic_id" { + description = "The ID of the created Pub/Sub Topic." + value = google_pubsub_topic.topic.id +} + +output "topic_name" { + description = "The name of the created Pub/Sub Topic." + value = google_pubsub_topic.topic.name +} \ No newline at end of file diff --git a/modules/topic-schema/resources.tf b/modules/topic-schema/resources.tf new file mode 100644 index 0000000..a1c0665 --- /dev/null +++ b/modules/topic-schema/resources.tf @@ -0,0 +1,6 @@ +resource "google_pubsub_topic" "topic" { + name = var.topic_name + labels = var.labels + + message_retention_duration = var.message_retention_duration +} \ No newline at end of file diff --git a/modules/topic-schema/terraform-docs.md b/modules/topic-schema/terraform-docs.md new file mode 100644 index 0000000..e78405c --- /dev/null +++ b/modules/topic-schema/terraform-docs.md @@ -0,0 +1,38 @@ +## Requirements + +| Name | Version | +|------|---------| +| [google](#requirement\_google) | 6.5.0 | + +## Providers + +| Name | Version | +|------|---------| +| [google](#provider\_google) | 6.5.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [google_pubsub_topic.topic](https://registry.terraform.io/providers/hashicorp/google/6.5.0/docs/resources/pubsub_topic) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [labels](#input\_labels) | A set of key/value label pairs to assign to this Topic. | `map(string)` | `{}` | no | +| [message\_retention\_duration](#input\_message\_retention\_duration) | Indicates the minimum duration to retain a message after it is published to the topic. If this field is set, messages published to the topic in the last messageRetentionDuration are always available to subscribers. For instance, it allows any attached subscription to seek to a timestamp that is up to messageRetentionDuration in the past. If this field is not set, message retention is controlled by settings on individual subscriptions. | `string` | `"2678400s"` | no | +| [schema](#input\_schema) | The name of the schema that messages published should be validated against. Format is projects/{project}/schemas/{schema}. The value of this field will be deleted-schema if the schema has been deleted. | `string` | n/a | yes | +| [schema\_encoding](#input\_schema\_encoding) | The encoding of the messages validated against schema. Only JSON is supported. If this is not set, the encoding will be defaulted to JSON. | `string` | `"ENCODING_UNSPECIFIED"` | no | +| [topic\_name](#input\_topic\_name) | Name of the topic. | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [topic\_id](#output\_topic\_id) | The ID of the created Pub/Sub Topic. | +| [topic\_name](#output\_topic\_name) | The name of the created Pub/Sub Topic. | \ No newline at end of file diff --git a/modules/topic-schema/variables.tf b/modules/topic-schema/variables.tf new file mode 100644 index 0000000..9dc47a3 --- /dev/null +++ b/modules/topic-schema/variables.tf @@ -0,0 +1,42 @@ +variable "labels" { + description = "A set of key/value label pairs to assign to this Topic." + type = map(string) + default = {} +} + +variable "message_retention_duration" { + default = "2678400s" + description = "Indicates the minimum duration to retain a message after it is published to the topic. If this field is set, messages published to the topic in the last messageRetentionDuration are always available to subscribers. For instance, it allows any attached subscription to seek to a timestamp that is up to messageRetentionDuration in the past. If this field is not set, message retention is controlled by settings on individual subscriptions." + type = string + + validation { + condition = can(regex("^\\d+s$", var.message_retention_duration)) + error_message = "Value must be a duration represented in seconds. Example: 86400s" + } +} + +variable "schema" { + description = "The name of the schema that messages published should be validated against. Format is projects/{project}/schemas/{schema}. The value of this field will be deleted-schema if the schema has been deleted." + type = string + + validation { + condition = can(regex("^projects/[^/]+/schemas/[^/]+$", var.schema)) + error_message = "Value must be in the format projects/{project}/schemas/{schema}." + } +} + +variable "schema_encoding" { + description = "The encoding of the messages validated against schema. Only JSON is supported. If this is not set, the encoding will be defaulted to JSON." + type = string + default = "ENCODING_UNSPECIFIED" + + validation { + condition = contains(["BINARY", "JSON", "ENCODING_UNSPECIFIED"], var.schema_encoding) + error_message = "Value must be one of: BINARY, JSON, ENCODING_UNSPECIFIED" + } +} + +variable "topic_name" { + description = "Name of the topic." + type = string +}