Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
terraform {
required_version = ">= 0.12"
}
variable project {
type = string
}
provider "google" {
project = var.project
region = "europe-west1"
}
data "google_project" "current" {
provider = google
}
resource "google_service_account" "scheduler" {
display_name = "Google Cloud Scheduler invoker"
account_id = "scheduler"
project = data.google_project.current.project_id
}
resource "google_cloud_run_service" "application" {
name = "application"
location = "europe-west1"
template {
spec {
containers {
image = "gcr.io/binx-io-public/paas-monitor:latest"
}
}
}
timeouts {
create = "10m"
}
depends_on = [google_project_service.run]
}
resource "google_cloud_run_service_iam_member" "scheduler-member-of-run-invoker" {
role = "roles/run.invoker"
member = "serviceAccount:${google_service_account.scheduler.email}"
service = google_cloud_run_service.application.name
location = google_cloud_run_service.application.location
}
resource "google_cloud_scheduler_job" "application" {
name = "application"
description = "invoke every 5 minutes"
schedule = "*/5 * * * *"
http_target {
http_method = "GET"
uri = "${google_cloud_run_service.application.status[0].url}/status"
oidc_token {
service_account_email = google_service_account.scheduler.email
}
}
depends_on = [google_app_engine_application.app, google_project_service.cloudscheduler]
}
resource "google_app_engine_application" "app" {
project = data.google_project.current.project_id
location_id = "europe-west"
depends_on = [google_project_service.appengine]
}
resource "google_project_service" "run" {
service = "run.googleapis.com"
disable_on_destroy = false
}
resource "google_project_service" "cloudscheduler" {
service = "cloudscheduler.googleapis.com"
disable_on_destroy = false
}
resource "google_project_service" "appengine" {
service = "appengine.googleapis.com"
}
terraform {
required_version = ">= 0.12"
}
variable project {
type = string
}
provider "google" {
project = var.project
region = "europe-west1"
}
data "google_project" "current" {
provider = google
}
resource "google_service_account" "scheduler" {
display_name = "Google Cloud Scheduler invoker"
account_id = "scheduler"
project = data.google_project.current.project_id
}
resource "google_cloud_run_service" "application" {
name = "application"
location = "europe-west1"
template {
spec {
containers {
image = "gcr.io/binx-io-public/paas-monitor:latest"
}
}
}
timeouts {
create = "10m"
}
depends_on = [google_project_service.run]
}
resource "google_cloud_run_service_iam_member" "scheduler-member-of-run-invoker" {
role = "roles/run.invoker"
member = "serviceAccount:${google_service_account.scheduler.email}"
service = google_cloud_run_service.application.name
location = google_cloud_run_service.application.location
}
resource "google_cloud_scheduler_job" "application" {
name = "application"
description = "invoke every 5 minutes"
schedule = "*/5 * * * *"
http_target {
http_method = "GET"
uri = "${google_cloud_run_service.application.status[0].url}/status"
oidc_token {
service_account_email = google_service_account.scheduler.email
}
}
depends_on = [google_app_engine_application.app, google_project_service.cloudscheduler]
}
resource "google_app_engine_application" "app" {
project = data.google_project.current.project_id
location_id = "europe-west"
depends_on = [google_project_service.appengine]
}
resource "google_project_service" "run" {
service = "run.googleapis.com"
disable_on_destroy = false
}
resource "google_project_service" "cloudscheduler" {
service = "cloudscheduler.googleapis.com"
disable_on_destroy = false
}
resource "google_project_service" "appengine" {
service = "appengine.googleapis.com"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment