diff --git a/Makefile b/Makefile index 7b302f0..8e1e35f 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,11 @@ help: ## Show this help message. cs: ## Checks for code style issues docker-compose run --rm python black --check . + terraform -chdir=terraform fmt -check -recursive . cs-fix: ## Fixes code style issues docker-compose run --rm python black . + terraform -chdir=terraform fmt -recursive . build: ## Builds the image including the setup.py file (run this when you've changed dependencies) docker-compose build python diff --git a/terraform/cloud_function/pubsub_triggered/main.tf b/terraform/cloud_function/pubsub_triggered/main.tf index a2376ee..1343b86 100644 --- a/terraform/cloud_function/pubsub_triggered/main.tf +++ b/terraform/cloud_function/pubsub_triggered/main.tf @@ -3,12 +3,12 @@ Cloud Function triggered by a message published on a PubSub topic. Often used in conjunction with bucket notifications to act on objects created in a bucket. */ - resource "google_cloudfunctions_function" "function" { available_memory_mb = var.function_memory entry_point = var.function_entry_point environment_variables = var.function_env_vars - name = format("%s%s-%s", var.function_name, var.branch_suffix, random_string.random.result) + labels = { last_deployed_at = formatdate("YYYYMMDDhhmmss", timestamp()) } + name = format("%s%s", var.function_name, var.branch_suffix) project = var.project_id runtime = var.function_runtime service_account_email = var.function_service_account_email @@ -24,13 +24,9 @@ resource "google_cloudfunctions_function" "function" { } } -resource "random_string" "random" { - length = 4 - special = false -} - resource "google_storage_bucket_object" "functioncode" { - name = format("pubsub_function_sources/%s/sourcecode%s.zip", var.function_name, random_string.random.result) + name = format("pubsub_function_sources/%s/sourcecode%s.zip", var.function_name, var.branch_suffix) bucket = var.source_code_bucket_name + labels = local.renewable_labels source = format("%s/%s/%s.zip", var.source_code_root_path, var.function_name, var.function_name) } diff --git a/terraform/cloud_function/scheduled/main.tf b/terraform/cloud_function/scheduled/main.tf index adc0902..5aefb5e 100644 --- a/terraform/cloud_function/scheduled/main.tf +++ b/terraform/cloud_function/scheduled/main.tf @@ -8,7 +8,8 @@ resource "google_cloudfunctions_function" "function" { available_memory_mb = var.function_memory entry_point = var.function_entry_point environment_variables = var.function_env_vars - name = format("%s%s-%s", var.function_name, var.branch_suffix, random_string.random.result) + labels = { last_deployed_at = formatdate("YYYYMMDDhhmmss", timestamp()) } + name = format("%s%s", var.function_name, var.branch_suffix) project = var.project_id region = var.project_region runtime = var.function_runtime @@ -21,19 +22,14 @@ resource "google_cloudfunctions_function" "function" { vpc_connector_egress_settings = var.function_vpc_connector_egress_settings } -resource "random_string" "random" { - length = 4 - special = false -} - resource "google_storage_bucket_object" "functioncode" { - name = format("http_function_sources/%s/sourcecode%s.zip", var.function_name, random_string.random.result) + name = format("http_function_sources/%s/sourcecode%s.zip", var.function_name, var.branch_suffix) bucket = var.source_code_bucket_name source = "${var.source_code_root_path}/${var.function_name}/${var.function_name}.zip" } resource "google_cloud_scheduler_job" "scheduler_job" { - for_each = {for scheduler in var.schedulers: scheduler.name => scheduler} + for_each = { for scheduler in var.schedulers : scheduler.name => scheduler } attempt_deadline = each.value.attempt_deadline != null ? each.value.attempt_deadline : "320s" name = each.value.name @@ -49,10 +45,10 @@ resource "google_cloud_scheduler_job" "scheduler_job" { http_method = each.value.request_method != null ? each.value.request_method : "POST" headers = { - "Content-Type": "application/json" + "Content-Type" : "application/json" } - uri = google_cloudfunctions_function.function.https_trigger_url + uri = google_cloudfunctions_function.function.https_trigger_url oidc_token { service_account_email = var.scheduler_service_account_email diff --git a/terraform/cloud_function/scheduled/variables.tf b/terraform/cloud_function/scheduled/variables.tf index 1eaa2ba..b2b5fee 100644 --- a/terraform/cloud_function/scheduled/variables.tf +++ b/terraform/cloud_function/scheduled/variables.tf @@ -32,11 +32,11 @@ variable "schedulers" { default = [] type = list(object({ attempt_deadline = optional(string) - name = string - schedule = string - request_body = optional(string) - request_method = optional(string) - retry_count = optional(number) + name = string + schedule = string + request_body = optional(string) + request_method = optional(string) + retry_count = optional(number) })) } variable "source_code_bucket_name" {}