Skip to content

Commit

Permalink
Merge pull request #11 from kopachevsky/fix/9/topic-labels
Browse files Browse the repository at this point in the history
Label support #9
  • Loading branch information
aaron-lane authored Sep 11, 2019
2 parents ca57032 + 9967fd4 commit bc54048
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to

## [Unreleased]

- Added node_labels variable to define map of key/value label pairs to assign to Pub/Sub topic. [#11]

## [1.0.0] - 2019-07-26

### Changed
Expand All @@ -34,3 +36,4 @@ and this project adheres to

[#7]: https://github.com/terraform-google-modules/terraform-google-pubsub/pull/7
[#2]: https://github.com/terraform-google-modules/terraform-google-pubsub/pull/2
[#11]: https://github.com/terraform-google-modules/terraform-google-pubsub/pull/11
96 changes: 91 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

# Docker build config variables
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
DOCKER_ORG := gcr.io/cloud-foundation-cicd
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 2.3.0
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}

# All is the first target in the file so it will get picked up when you just run 'make' on its own
all: check_shell check_python check_golang check_terraform check_docker check_base_files check_trailing_whitespace generate_docs
all: check_shell check_python check_golang check_terraform check_base_files check_trailing_whitespace generate_docs

# The .PHONY directive tells make that this isn't a real target and so
# the presence of a file named 'check_shell' won't cause this target to stop
Expand All @@ -37,10 +43,6 @@ check_golang:
check_terraform:
@source test/make.sh && check_terraform

.PHONY: check_docker
check_docker:
@source test/make.sh && docker

.PHONY: check_base_files
check_base_files:
@source test/make.sh && basefiles
Expand Down Expand Up @@ -68,3 +70,87 @@ generate_docs:
.PHONY: test_integration
test_integration:
@source test/test.sh

# Run docker
.PHONY: docker_run
docker_run:
docker run --rm -it \
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
-e PROJECT_ID \
-e REGION \
-e ZONES \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v "$(CURDIR)":/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "source test/ci_integration.sh && setup_environment && exec /bin/bash"

.PHONY: docker_create
docker_create: docker_build_kitchen_terraform
docker run --rm -it \
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
-e PROJECT_ID \
-e REGION \
-e ZONES \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v "$(CURDIR)":/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen create"

.PHONY: docker_converge
docker_converge:
docker run --rm -it \
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
-e PROJECT_ID \
-e REGION \
-e ZONES \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v "$(CURDIR)":/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen converge && kitchen converge"

.PHONY: docker_verify
docker_verify:
docker run --rm -it \
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
-e PROJECT_ID \
-e REGION \
-e ZONES \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v "$(CURDIR)":/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen verify"

.PHONY: docker_destroy
docker_destroy:
docker run --rm -it \
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
-e PROJECT_ID \
-e REGION \
-e ZONES \
-e SERVICE_ACCOUNT_JSON \
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v "$(CURDIR)":/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen destroy"

.PHONY: test_integration_docker
test_integration_docker:
docker run --rm -it \
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
-e PROJECT_ID \
-e REGION \
-e ZONES \
-e SERVICE_ACCOUNT_JSON \
-v "$(CURDIR)":/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
/bin/bash -c "test/ci_integration.sh"

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module "pubsub" {
| pull\_subscriptions | The list of the pull subscriptions | list(map(string)) | `<list>` | no |
| push\_subscriptions | The list of the push subscriptions | list(map(string)) | `<list>` | no |
| topic | The Pub/Sub topic name | string | n/a | yes |
| topic\_labels | A map of labels to assign to the Pub/Sub topic | map(string) | `<map>` | no |

## Outputs

Expand All @@ -53,6 +54,7 @@ module "pubsub" {
| subscription\_names | The name list of Pub/Sub subscriptions |
| subscription\_paths | The path list of Pub/Sub subscriptions |
| topic | The name of the Pub/Sub topic |
| topic\_labels | Labels assigned to the Pub/Sub topic |
| uri | The URI of the Pub/Sub topic |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand Down
2 changes: 2 additions & 0 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ This example illustrates how to use the `pubsub` module.
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| 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 -->
Expand Down
9 changes: 5 additions & 4 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ provider "google" {
}

module "pubsub" {
source = "../../"
project_id = "${var.project_id}"
topic = "${var.topic_name}"
source = "../../"
project_id = var.project_id
topic = var.topic_name
topic_labels = var.topic_labels

pull_subscriptions = [
{
name = "pull"
ack_deadline_seconds = 20
ack_deadline_seconds = 10
},
]

Expand Down
6 changes: 5 additions & 1 deletion examples/simple/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ output "project_id" {
}

output "topic_name" {
value = var.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"
}
7 changes: 7 additions & 0 deletions examples/simple/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ 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 = {}
}

3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ locals {
}

resource "google_pubsub_topic" "topic" {
name = var.topic
project = var.project_id
name = var.topic
labels = var.topic_labels
}

resource "google_pubsub_subscription" "push_subscriptions" {
Expand Down
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ output "topic" {
description = "The name of the Pub/Sub topic"
}

output "topic_labels" {
value = google_pubsub_topic.topic.labels
description = "Labels assigned to the Pub/Sub topic"
}

output "id" {
value = google_pubsub_topic.topic.id
description = "The ID of the Pub/Sub topic"
Expand Down
26 changes: 8 additions & 18 deletions test/fixtures/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,13 @@
* limitations under the License.
*/

module "pubsub" {
source = "../../"
module "example" {
source = "../../examples/simple"
project_id = var.project_id
topic = var.topic_name

push_subscriptions = [
{
name = "push"
push_endpoint = "https://${var.project_id}.appspot.com/"
x-goog-version = "v1beta1"
ack_deadline_seconds = 20
},
]

pull_subscriptions = [
{
name = "pull"
},
]
topic_name = var.topic_name
topic_labels = {
foo_label = "foo_value"
bar_label = "bar_value"
}
}

11 changes: 9 additions & 2 deletions test/fixtures/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
*/

output "project_id" {
value = var.project_id
value = var.project_id
description = "The project ID"
}

output "topic_name" {
value = var.topic_name
value = module.example.topic_name
description = "The name of the Pub/Sub topic created"
}

output "topic_labels" {
value = module.example.topic_labels
description = "The labels of the Pub/Sub topic created"
}
2 changes: 2 additions & 0 deletions test/fixtures/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/

variable "project_id" {
type = string
description = "The project to run tests against"
}

variable "topic_name" {
type = string
description = "The project to run tests against"
}
1 change: 1 addition & 0 deletions test/integration/default/controls/pubsub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
describe command("gcloud --project='#{project_id}' pubsub topics describe #{topic}") do
its(:exit_status) { should be_zero }
it { expect(subject.stdout).to match(%r{name: projects/#{project_id}/topics/#{topic}}) }
it { expect(subject.stdout).to match(%r{labels:\n bar_label: bar_value\n foo_label: foo_value\nname}) }
end

describe command("gcloud --project='#{project_id}' pubsub subscriptions describe pull --format=json") do
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ variable "topic" {
description = "The Pub/Sub topic name"
}

variable "topic_labels" {
type = map(string)
description = "A map of labels to assign to the Pub/Sub topic"
default = {}
}

variable "push_subscriptions" {
type = list(map(string))
description = "The list of the push subscriptions"
Expand Down

0 comments on commit bc54048

Please sign in to comment.