1919 *****************************************/
2020
2121resource "google_cloud_scheduler_job" "job" {
22- name = " ${ var . job_name } "
23- project = " ${ var . project_id } "
24- region = " ${ var . region } "
25- description = " ${ var . job_description } "
26- schedule = " ${ var . job_schedule } "
27- time_zone = " ${ var . time_zone } "
22+ name = var. job_name
23+ project = var. project_id
24+ region = var. region
25+ description = var. job_description
26+ schedule = var. job_schedule
27+ time_zone = var. time_zone
2828
29- pubsub_target = {
29+ pubsub_target {
3030 topic_name = " projects/${ var . project_id } /topics/${ module . pubsub_topic . topic } "
31- data = " ${ var . message_data } "
31+ data = var. message_data
3232 }
3333}
3434
@@ -37,45 +37,46 @@ resource "google_cloud_scheduler_job" "job" {
3737 *****************************************/
3838
3939module "pubsub_topic" {
40- source = " github.com/terraform-google-modules/terraform-google-pubsub?ref=v0.1.0"
41- topic = " ${ var . topic_name } "
42- project_id = " ${ var . project_id } "
40+ source = " terraform-google-modules/pubsub/google"
41+ version = " ~> 1.0"
42+ topic = var. topic_name
43+ project_id = var. project_id
4344}
4445
4546/* *****************************************
4647 Cloud Function Resource Definitions
4748 *****************************************/
4849
4950resource "google_cloudfunctions_function" "main" {
50- name = " ${ var . function_name } "
51- source_archive_bucket = " ${ google_storage_bucket . main . name } "
52- source_archive_object = " ${ google_storage_bucket_object . main . name } "
53- description = " ${ var . function_description } "
54- available_memory_mb = " ${ var . function_available_memory_mb } "
55- timeout = " ${ var . function_timeout_s } "
56- entry_point = " ${ var . function_entry_point } "
51+ name = var. function_name
52+ source_archive_bucket = google_storage_bucket. main . name
53+ source_archive_object = google_storage_bucket_object. main . name
54+ description = var. function_description
55+ available_memory_mb = var. function_available_memory_mb
56+ timeout = var. function_timeout_s
57+ entry_point = var. function_entry_point
5758
5859 event_trigger {
5960 event_type = " google.pubsub.topic.publish"
60- resource = " ${ module . pubsub_topic . topic } "
61+ resource = module. pubsub_topic . topic
6162
6263 failure_policy {
63- retry = " ${ var . function_event_trigger_failure_policy_retry } "
64+ retry = var. function_event_trigger_failure_policy_retry
6465 }
6566 }
6667
67- labels = " ${ var . function_labels } "
68- runtime = " ${ var . function_runtime } "
69- environment_variables = " ${ var . function_environment_variables } "
70- project = " ${ var . project_id } "
71- region = " ${ var . region } "
72- service_account_email = " ${ var . function_service_account_email } "
68+ labels = var. function_labels
69+ runtime = var. function_runtime
70+ environment_variables = var. function_environment_variables
71+ project = var. project_id
72+ region = var. region
73+ service_account_email = var. function_service_account_email
7374}
7475
7576data "archive_file" "main" {
7677 type = " zip"
77- output_path = " ${ pathexpand (" ${ var . function_source_directory } .zip" )} "
78- source_dir = " ${ pathexpand (" ${ var . function_source_directory } " ) } "
78+ output_path = pathexpand (" ${ var . function_source_directory } .zip" )
79+ source_dir = pathexpand (var. function_source_directory )
7980}
8081
8182resource "random_string" "random_suffix" {
@@ -85,18 +86,21 @@ resource "random_string" "random_suffix" {
8586}
8687
8788resource "google_storage_bucket" "main" {
88- name = " ${ coalesce (var. bucket_name , " ${ var . project_id } -scheduled-function-${ random_string . random_suffix . result } " )} "
89+ name = coalesce (
90+ var. bucket_name ,
91+ " ${ var . project_id } -scheduled-function-${ random_string . random_suffix . result } " ,
92+ )
8993 force_destroy = " true"
90- location = " ${ var . region } "
91- project = " ${ var . project_id } "
94+ location = var. region
95+ project = var. project_id
9296 storage_class = " REGIONAL"
93- labels = " ${ var . function_source_archive_bucket_labels } "
97+ labels = var. function_source_archive_bucket_labels
9498}
9599
96100resource "google_storage_bucket_object" "main" {
97101 name = " event_function-${ random_string . random_suffix . result } .zip"
98- bucket = " ${ google_storage_bucket . main . name } "
99- source = " ${ data . archive_file . main . output_path } "
102+ bucket = google_storage_bucket. main . name
103+ source = data. archive_file . main . output_path
100104 content_disposition = " attachment"
101105 content_encoding = " gzip"
102106 content_type = " application/zip"
0 commit comments