Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force function deployment every time #29

Merged
merged 5 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions terraform/cloud_function/pubsub_triggered/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
16 changes: 6 additions & 10 deletions terraform/cloud_function/scheduled/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions terraform/cloud_function/scheduled/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {}
Expand Down