-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
142 lines (117 loc) · 3.6 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
terraform {
required_providers {
google = {
source = "hashicorp/google-beta"
version = "~> 5.0"
}
local = {
source = "hashicorp/local"
version = "~> 2.0"
}
}
}
provider "google" {
user_project_override = true
}
# Value obtained from the TF_VAR_project environment variable
variable "project" {
type = string
}
# For project ID <-> project number conversion
data "google_project" "project" {
project_id = var.project
}
resource "google_project_service" "services" {
for_each = toset([
"serviceusage.googleapis.com",
"generativelanguage.googleapis.com",
"apikeys.googleapis.com",
"firestore.googleapis.com",
"firebaserules.googleapis.com",
])
project = var.project
service = each.value
disable_on_destroy = false
}
# generativelanguage.googleapis.com is designed for experimentation only. A low initial quota
# is set to protect the project. To use Gemini AI in a production environment, migrate to Vertex AI in
# Firebase. See prod.tf for more details.
resource "google_service_usage_consumer_quota_override" "generativelanguage" {
project = var.project
service = "generativelanguage.googleapis.com"
metric = urlencode("generativelanguage.googleapis.com/generate_requests_per_model")
limit = urlencode("/min/model/project")
override_value = "10"
force = true
depends_on = [google_project_service.services["generativelanguage.googleapis.com"]]
}
resource "google_apikeys_key" "generativelanguage" {
project = var.project
name = "gemini-api-key"
display_name = "Gemini API Key"
restrictions {
api_targets {
service = "generativelanguage.googleapis.com"
}
browser_key_restrictions {
allowed_referrers = ["*"]
}
}
depends_on = [google_project_service.services["apikeys.googleapis.com"]]
}
resource "google_firestore_database" "database" {
project = var.project
name = "(default)"
location_id = "nam5"
type = "FIRESTORE_NATIVE"
depends_on = [google_project_service.services]
}
resource "google_firebaserules_ruleset" "firestore" {
project = var.project
source {
files {
content = local_file.firestore_rules.content
name = "firestore.rules"
}
}
depends_on = [google_firestore_database.database]
}
resource "google_firebaserules_release" "firestore" {
project = var.project
name = "cloud.firestore"
ruleset_name = google_firebaserules_ruleset.firestore.name
}
resource "google_firebase_web_app" "example" {
project = var.project
display_name = "Make It So AI!"
}
data "google_firebase_web_app_config" "example" {
project = var.project
web_app_id = google_firebase_web_app.example.app_id
}
resource "local_file" "firestore_rules" {
content = templatefile("${path.module}/firestore.rules.tmpl", {
# Access to Firestore expires in 30 days
expiry = formatdate("YYYY, M, D", timeadd(plantimestamp(), "720h"))
})
filename = "${path.module}/firestore.rules"
}
resource "local_file" "firebaserc" {
content = jsonencode({
projects = {
default = var.project
}
})
filename = "${path.module}/.firebaserc"
}
resource "local_file" "environment_ts" {
content = templatefile("${path.module}/src/environments/environments.ts.tmpl", merge(
data.google_firebase_web_app_config.example,
{
project_id = data.google_project.project.project_id,
gemini_api_key = google_apikeys_key.generativelanguage.key_string,
debug_token = "" # Use local.uuid4 in when using Vertex AI in Firebase
}
))
filename = "${path.module}/src/environments/environments.ts"
}