-
Notifications
You must be signed in to change notification settings - Fork 48
/
main.tf
98 lines (85 loc) · 3.76 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/******************************************
Scheduled Function Definition
*****************************************/
resource "google_cloud_scheduler_job" "job" {
count = var.scheduler_job == null ? 1 : 0
name = var.job_name
project = var.project_id
region = var.region
description = var.job_description
schedule = var.job_schedule
time_zone = var.time_zone
pubsub_target {
topic_name = "projects/${var.project_id}/topics/${module.pubsub_topic.topic}"
data = var.message_data
}
}
/******************************************
PubSub Topic Definition
*****************************************/
module "pubsub_topic" {
source = "terraform-google-modules/pubsub/google"
version = "~> 7.0"
topic = var.topic_name
project_id = var.project_id
create_topic = var.scheduler_job == null ? true : false
grant_token_creator = var.grant_token_creator
topic_labels = var.topic_labels
topic_kms_key_name = var.topic_kms_key_name
}
/******************************************
Cloud Function Resource Definitions
*****************************************/
resource "random_id" "suffix" {
byte_length = 4
}
module "main" {
source = "terraform-google-modules/event-function/google"
version = "~> 4.0"
entry_point = var.function_entry_point
event_trigger = {
event_type = "google.pubsub.topic.publish"
resource = var.scheduler_job == null ? module.pubsub_topic.topic : var.topic_name
}
name = var.function_name
project_id = var.project_id
region = var.region
runtime = var.function_runtime
source_directory = var.function_source_directory
source_dependent_files = var.function_source_dependent_files
available_memory_mb = var.function_available_memory_mb
bucket_force_destroy = var.bucket_force_destroy
bucket_labels = var.function_source_archive_bucket_labels
bucket_name = var.bucket_name == "" ? "${var.project_id}-scheduled-function-${random_id.suffix.hex}" : var.bucket_name
create_bucket = var.create_bucket
description = var.function_description
environment_variables = var.function_environment_variables
secret_environment_variables = var.function_secret_environment_variables
event_trigger_failure_policy_retry = var.function_event_trigger_failure_policy_retry
files_to_exclude_in_source_dir = var.files_to_exclude_in_source_dir
labels = var.function_labels
service_account_email = var.function_service_account_email
timeout_s = var.function_timeout_s
max_instances = var.function_max_instances
ingress_settings = var.ingress_settings
docker_registry = var.function_docker_registry
docker_repository = var.function_docker_repository
kms_key_name = var.function_kms_key_name
vpc_connector = var.vpc_connector
vpc_connector_egress_settings = var.vpc_connector_egress_settings
}