-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
61 lines (51 loc) · 1.41 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
variable "PROJECT" {
type = string
nullable = false
description = "google cloud project name"
}
terraform {
required_providers {
google = {
source = "hashicorp/google"
}
}
backend "gcs" {
bucket = "cambridge-accommodation"
prefix = "accommodations"
}
}
provider "google" {
project = var.PROJECT
region = "europe-west2"
}
data "google_cloudfunctions_function" "scrapper" {
name = "accommodation-scrapper"
}
resource "google_cloud_scheduler_job" "timer" {
name = "accommodation-invoker"
description = "Triggers accommodation scrapper twice an hour"
schedule = "*/30 * * * *"
attempt_deadline = format("%ds", data.google_cloudfunctions_function.scrapper.timeout)
retry_config {
retry_count = 3
}
http_target {
http_method = "GET"
uri = data.google_cloudfunctions_function.scrapper.https_trigger_url
oidc_token {
service_account_email = google_service_account.function_invoker.email
}
}
}
resource "google_service_account" "function_invoker" {
account_id = "function-invoker"
display_name = "Function Invoker"
description = "Service account to invoke functions"
}
resource "google_project_iam_binding" "function_invoker_role" {
project = var.PROJECT
role = "roles/cloudfunctions.invoker"
members = [
format("serviceAccount:%s", google_service_account.function_invoker.email),
]
}