-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
102 lines (79 loc) · 2.21 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
# Copyright 2023 Quansight Labs.
# Use of this source code is governed by a 3-Clause BSD
# license that can be found in the LICENSE file.
terraform {
backend "remote" {
organization = "quansight"
workspaces {
name = "github-quansight-labs-jupyterlab-user-testing"
}
}
required_providers {
google = {
source = "hashicorp/google"
version = "4.54.0"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 3.0"
}
}
}
provider "google" {
region = var.region
}
provider "cloudflare" {}
resource "google_compute_firewall" "main" {
count = var.enabled ? 1 : 0
name = "http-firewall"
network = "default"
source_ranges = ["0.0.0.0/0"]
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_tags = ["web"]
}
resource "google_compute_address" "static" {
count = var.enabled ? 1 : 0
name = "ipv4-address"
}
resource "google_compute_instance" "main" {
count = var.enabled ? 1 : 0
name = "jupyterlab-a11y-testing"
machine_type = var.instance-type
zone = var.zone
tags = ["web"]
boot_disk {
initialize_params {
image = "ubuntu-2204-lts"
}
}
network_interface {
network = "default"
access_config {
nat_ip = google_compute_address.static.0.address
}
}
metadata_startup_script = <<EOT
echo "requirements.txt sha256=${filesha256("./requirements.txt")} (trigger redeploy)"
curl -L https://tljh.jupyter.org/bootstrap.py | sudo python3 - --admin ${var.admin-username} --user-requirements-txt-url https://raw.githubusercontent.com/Quansight-Labs/JupyterLab-user-testing/main/requirements.txt
sudo tljh-config set https.enabled true
sudo tljh-config set https.letsencrypt.email ${var.letsencrypt-email}
sudo tljh-config add-item https.letsencrypt.domains ${var.subdomain}.${var.domain}
sudo tljh-config reload proxy
sudo tljh-config set user_environment.default_app jupyterlab
sudo tljh-config reload hub
EOT
}
data "cloudflare_zone" "main" {
name = var.domain
}
resource "cloudflare_record" "main" {
count = var.enabled ? 1 : 0
zone_id = data.cloudflare_zone.main.id
name = var.subdomain
value = google_compute_address.static.0.address
type = "A"
proxied = false
}