This commit is contained in:
kosukesuenaga 2025-12-24 11:36:34 +09:00
parent 1259ba76c9
commit 6454e1b46b
19 changed files with 667 additions and 611 deletions

View file

@ -10,37 +10,22 @@ variable "region" {
variable "function_name" {
type = string
default = "mrt-create-log-sheet"
default = "generate-minutes"
}
# Scheduler実行用サービスアカウント
resource "google_service_account" "cf_scheduler_sa" {
project = var.project_id
account_id = "mrt-scheduler-sa"
display_name = "Cloud Functions 起動用サービスアカウント"
}
# SA
resource "google_project_iam_member" "scheduler_role" {
for_each = toset(["roles/cloudfunctions.invoker","roles/run.invoker"])
project = var.project_id
role = each.value
member = "serviceAccount:${google_service_account.cf_scheduler_sa.email}"
}
# 10 Function Scheduler
resource "google_cloud_scheduler_job" "monthly_cf_trigger" {
# 3 Function Scheduler
resource "google_cloud_scheduler_job" "daily_cf_trigger" {
project = var.project_id
name = "monthly-cf-trigger"
description = "Invoke Cloud Function on the 1st of each month at 00:00"
name = "daily-cf-trigger"
description = "Invoke Cloud Function everyday at 03:00"
region = var.region
schedule = "0 0 1 * *"
schedule = "0 3 * * *"
time_zone = "Asia/Tokyo"
http_target {
uri = "https://${var.region}-${var.project_id}.cloudfunctions.net/${var.function_name}"
uri = "https://${var.region}-${var.project_id}.cloudfunctions.net/${var.function_name}/api/dailyBatch"
http_method = "POST"
oidc_token {
service_account_email = google_service_account.cf_scheduler_sa.email