-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookstack.tf
186 lines (155 loc) · 4.39 KB
/
bookstack.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Compute engine instance template
resource "google_compute_instance_template" "bookstack" {
name_prefix = "bookstack"
machine_type = "e2-medium"
# Container Optomized OS with bookstack container
disk {
source_image = module.gce-container.source_image
}
# Persistent disk to store config, images, etc...
disk {
source = google_compute_disk.bookstack.name
device_name = google_compute_disk.bookstack.name
auto_delete = false
boot = false
mode = "READ_WRITE"
}
network_interface {
network = data.google_compute_network.default.name
# Without this the container will not start on the instance
access_config {
# Ephemeral public IP
}
}
metadata = {
gce-container-declaration = module.gce-container.metadata_value
google-logging-enabled = "true"
google-monitoring-enabled = "true"
}
labels = {
container-vm = module.gce-container.vm_container_label
}
service_account {
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
email = google_service_account.bookstack.email
scopes = ["cloud-platform"]
}
tags = [var.healthcheck_network_tag]
lifecycle {
create_before_destroy = true
}
}
# BookStack Docker Container
module "gce-container" {
source = "terraform-google-modules/container-vm/google"
version = "~> 3.0"
container = {
image = "ghcr.io/linuxserver/bookstack:22.03.1"
env = [
{
name = "APP_URL"
value = "https://${var.domain}"
},
{
name = "DB_HOST"
value = google_sql_database_instance.mysql.private_ip_address
},
{
name = "DB_DATABASE"
value = google_sql_database.database.name
},
{
name = "DB_USER"
value = random_string.bookstack_sql_user_name.result
},
{
name = "DB_PASS"
value = random_password.bookstack_sql_user_password.result
},
{
name = "GOOGLE_APP_ID"
value = var.oauth.google_app_id
},
{
name = "GOOGLE_APP_SECRET"
value = var.oauth.google_app_secret
},
{
name = "GOOGLE_AUTO_REGISTER"
value = true
},
{
name = "GOOGLE_AUTO_CONFIRM_EMAIL"
value = true
},
{
name = "STORAGE_TYPE"
value = "local_secure"
}
]
volumeMounts = [
{
mountPath = "/config"
name = google_compute_disk.bookstack.name
readOnly = false
},
]
}
volumes = [
{
name = google_compute_disk.bookstack.name
gcePersistentDisk = {
pdName = google_compute_disk.bookstack.name
fsType = "ext4"
}
},
]
restart_policy = "Always"
}
# Service account
resource "google_service_account" "bookstack" {
account_id = "bookstack"
display_name = "BookStack Service Account"
}
# IAM role with Compute Disks permissions
resource "google_project_iam_custom_role" "compute-disks" {
role_id = "compute_disks"
title = "Compute disks permissions"
permissions = [
# https://github.com/terraform-google-modules/terraform-google-container-vm#configure-a-service-account
"compute.disks.addResourcePolicies",
"compute.disks.create",
"compute.disks.createSnapshot",
"compute.disks.createTagBinding",
"compute.disks.delete",
"compute.disks.deleteTagBinding",
"compute.disks.get",
"compute.disks.getIamPolicy",
"compute.disks.list",
"compute.disks.listTagBindings",
"compute.disks.removeResourcePolicies",
"compute.disks.resize",
"compute.disks.setIamPolicy",
"compute.disks.setLabels",
"compute.disks.update",
"compute.disks.use",
"compute.disks.useReadOnly",
"compute.diskTypes.get",
"compute.diskTypes.list"
]
}
# BookStack service account compute disks IAM member
resource "google_project_iam_member" "compute-disks" {
project = var.gcp.project_id
role = google_project_iam_custom_role.compute-disks.id
member = "serviceAccount:${google_service_account.bookstack.email}"
}
# Persistent Disk
resource "google_compute_disk" "bookstack" {
name = "bookstack"
type = "pd-standard"
zone = var.gcp.zone
size = 50 # Gigabytes
# This disk has been formatted manually (outside of this terraform configuration) as follows:
# https://cloud.google.com/compute/docs/disks/add-persistent-disk#formatting
}