Skip to content

Commit da37d62

Browse files
committed
Review fixes.
1 parent 08124b0 commit da37d62

File tree

10 files changed

+22
-38
lines changed

10 files changed

+22
-38
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Then perform the following commands on the root folder:
5858
| message\_data | The data to send in the topic message. | string | `"dGVzdA=="` | no |
5959
| project\_id | The ID of the project where the resources will be created | string | n/a | yes |
6060
| region | The region in which resources will be applied. | string | n/a | yes |
61-
| scheduler\_job | The Cloud Scheduler job instance | any | `"null"` | no |
61+
| scheduler\_job | An existing Cloud Scheduler job instance | any | `"null"` | no |
6262
| time\_zone | The timezone to use in scheduler | string | `"Etc/UTC"` | no |
6363
| topic\_name | Name of pubsub topic connecting the scheduled job and the function | string | `"test-topic"` | no |
6464

@@ -67,6 +67,7 @@ Then perform the following commands on the root folder:
6767
| Name | Description |
6868
|------|-------------|
6969
| name | The name of the job created |
70+
| pubsub\_topic\_name | PubSub topic name |
7071
| scheduler\_job | The Cloud Scheduler job instance |
7172

7273
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/pubsub_scheduled_multiple/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Simple Project
1+
# Multiple Cloud Functions sharing the same Cloud Scheduler
22

33
This example module schedules a job to publish a message to a Pub/Sub topic every 5 minutes, which will trigger a CloudFunctions function.
44

@@ -19,6 +19,6 @@ More information is in the [root readme](../../README.md#app-engine).
1919
|------|-------------|
2020
| name | The name of the job created |
2121
| project\_id | The project ID |
22-
| scheduler\_job | The Cloud Scheduler job instance |
22+
| scheduler\_job | An existing Cloud Scheduler job instance |
2323

2424
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/pubsub_scheduled_multiple/function_source/package.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/pubsub_scheduled_multiple/function_source_2/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @param {!Object} event Event payload and metadata.
2222
* @param {!Function} callback Callback function to signal completion.
2323
*/
24-
exports.doSomething = (event) => {
24+
exports.doSomething2 = (event) => {
2525
console.log("Received event 2");
2626
console.log(event);
2727
};

examples/pubsub_scheduled_multiple/function_source_2/package.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/pubsub_scheduled_multiple/main.tf

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ provider "google-beta" {
2525
}
2626

2727
module "pubsub_scheduled_1" {
28-
providers = {
29-
google = google-beta
30-
}
31-
3228
source = "../../"
3329
project_id = var.project_id
3430
job_name = "pubsub-example"
@@ -41,16 +37,12 @@ module "pubsub_scheduled_1" {
4137
}
4238

4339
module "pubsub_scheduled_2" {
44-
providers = {
45-
google = google-beta
46-
}
47-
4840
source = "../../"
4941
project_id = var.project_id
50-
function_entry_point = "doSomething"
42+
function_entry_point = "doSomething2"
5143
function_source_directory = "${path.module}/function_source_2"
5244
function_name = "testfunction-2"
5345
region = var.region
54-
topic_name = "pubsub-1"
46+
topic_name = module.pubsub_scheduled_1.pubsub_topic_name
5547
scheduler_job = module.pubsub_scheduled_1.scheduler_job
5648
}

examples/pubsub_scheduled_multiple/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ output "project_id" {
2626

2727
output "scheduler_job" {
2828
value = module.pubsub_scheduled_1.scheduler_job
29-
description = "The Cloud Scheduler job instance"
29+
description = "An existing Cloud Scheduler job instance"
3030
}
3131

main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*****************************************/
2020

2121
resource "google_cloud_scheduler_job" "job" {
22-
count = var.scheduler_job == null ? 1 : 0
22+
count = var.scheduler_job == null ? 1 : 0
2323

2424
name = var.job_name
2525
project = var.project_id
@@ -39,11 +39,11 @@ resource "google_cloud_scheduler_job" "job" {
3939
*****************************************/
4040

4141
module "pubsub_topic" {
42-
source = "terraform-google-modules/pubsub/google"
43-
version = "~> 1.0"
44-
topic = var.topic_name
45-
project_id = var.project_id
46-
enable = var.scheduler_job == null ? true : false
42+
source = "terraform-google-modules/pubsub/google"
43+
version = "~> 1.0"
44+
topic = var.topic_name
45+
project_id = var.project_id
46+
create_topic = var.scheduler_job == null ? true : false
4747
}
4848

4949
/******************************************
@@ -57,7 +57,7 @@ module "main" {
5757
entry_point = var.function_entry_point
5858
event_trigger = {
5959
event_type = "google.pubsub.topic.publish"
60-
resource = module.pubsub_topic.topic
60+
resource = var.scheduler_job == null ? module.pubsub_topic.topic : var.topic_name
6161
}
6262
name = var.function_name
6363
project_id = var.project_id

outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
*/
1616

1717
output "name" {
18-
value = google_cloud_scheduler_job.job.*.name
18+
value = var.scheduler_job == null ? google_cloud_scheduler_job.job.0.name : var.scheduler_job.name
1919
description = "The name of the job created"
2020
}
2121

2222
output "scheduler_job" {
2323
value = var.scheduler_job == null ? google_cloud_scheduler_job.job : var.scheduler_job
2424
description = "The Cloud Scheduler job instance"
2525
}
26+
27+
output "pubsub_topic_name" {
28+
value = var.scheduler_job == null ? module.pubsub_topic.topic : var.topic_name
29+
description = "PubSub topic name"
30+
}

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,6 @@ variable "time_zone" {
143143

144144
variable "scheduler_job" {
145145
type = any
146-
description = "The Cloud Scheduler job instance"
146+
description = "An existing Cloud Scheduler job instance"
147147
default = null
148148
}

0 commit comments

Comments
 (0)