Skip to content

Commit c29a3f0

Browse files
update feed status terraform daily (#1047)
1 parent b177c26 commit c29a3f0

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

infra/functions-python/main.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,27 @@ resource "google_cloud_scheduler_job" "export_csv_scheduler" {
836836
attempt_deadline = "600s"
837837
}
838838

839+
resource "google_cloud_scheduler_job" "update_feed_status_scheduler" {
840+
name = "update-feed-status-${var.environment}"
841+
description = "Schedule the update_feed_status function daily"
842+
time_zone = "Etc/UTC"
843+
schedule = var.update_feed_status_schedule
844+
region = var.gcp_region
845+
paused = var.environment == "prod" ? false : true
846+
depends_on = [google_cloudfunctions2_function.update_feed_status, google_cloudfunctions2_function_iam_member.update_feed_status_invoker]
847+
http_target {
848+
http_method = "POST"
849+
uri = google_cloudfunctions2_function.update_feed_status.url
850+
oidc_token {
851+
service_account_email = google_service_account.functions_service_account.email
852+
}
853+
headers = {
854+
"Content-Type" = "application/json"
855+
}
856+
}
857+
attempt_deadline = "600s"
858+
}
859+
839860

840861
# IAM entry for all users to invoke the function
841862
# 12. functions/reverse_geolocation_populate cloud function
@@ -1311,6 +1332,14 @@ resource "google_cloudfunctions2_function_iam_member" "export_csv_invoker" {
13111332
member = "serviceAccount:${google_service_account.functions_service_account.email}"
13121333
}
13131334

1335+
resource "google_cloudfunctions2_function_iam_member" "update_feed_status_invoker" {
1336+
project = var.project_id
1337+
location = var.gcp_region
1338+
cloud_function = google_cloudfunctions2_function.update_feed_status.name
1339+
role = "roles/cloudfunctions.invoker"
1340+
member = "serviceAccount:${google_service_account.functions_service_account.email}"
1341+
}
1342+
13141343
# Grant permissions to the service account to create bigquery jobs
13151344
resource "google_project_iam_member" "bigquery_job_user" {
13161345
project = var.project_id

infra/functions-python/vars.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,10 @@ variable "export_csv_schedule" {
8585
type = string
8686
description = "Schedule the export_csv function"
8787
default = "0 4 * * 2,5" # At 4am every Tuesday and Friday.
88+
}
89+
90+
variable "update_feed_status_schedule" {
91+
type = string
92+
description = "Schedule the update_feed_status function"
93+
default = "0 4 * * *" # At 4am every day.
8894
}

0 commit comments

Comments
 (0)