blob: 629ac8a1dcdfe6323ad3c6c5dcb5a994d76a42d3 (
plain)
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
|
variable "demo_region" { default = "us-east4" }
variable "demo_zone" { default = "us-east4-c" }
variable "praefect_demo_cluster_name" { }
variable "ssh_user" { }
variable "ssh_pubkey" { }
variable "os_image" { default = "ubuntu-os-cloud/ubuntu-1804-lts" }
variable "startup_script" {
default = <<EOF
set -e
if [ -d /opt/gitlab ] ; then exit; fi
curl -s https://packages.gitlab.com/install/repositories/gitlab/nightly-builds/script.deb.sh | sudo bash
sudo apt-get install -y gitlab-ee
EOF
}
variable "gitaly_machine_type" { default = "n1-standard-2" }
variable "gitaly_disk_size" { default = "100" }
variable "praefect_sql_password" { }
provider "google" {
version = "~> 3.12"
project = "gitlab-internal-153318"
region = var.demo_region
zone = var.demo_zone
}
resource "random_id" "db_name_suffix" {
byte_length = 4
}
resource "google_sql_database_instance" "praefect_sql" {
# It appears CloudSQL does not like Terraform re-using database names.
# Adding a random ID prevents name reuse.
name = "${var.praefect_demo_cluster_name}-praefect-postgresql-${random_id.db_name_suffix.hex}"
database_version = "POSTGRES_9_6"
region = var.demo_region
settings {
tier = "db-f1-micro"
ip_configuration{
ipv4_enabled = true
authorized_networks {
name = "praefect"
value = google_compute_instance.praefect.network_interface[0].access_config[0].nat_ip
}
}
}
}
output "praefect_postgresql_ip" {
value = google_sql_database_instance.praefect_sql.public_ip_address
}
resource "google_sql_user" "users" {
name = "praefect"
instance = google_sql_database_instance.praefect_sql.name
password = var.praefect_sql_password
}
resource "google_sql_database" "praefect-database" {
name = "praefect_production"
instance = google_sql_database_instance.praefect_sql.name
}
resource "google_compute_instance" "gitlab" {
name = format("%s-gitlab", var.praefect_demo_cluster_name)
machine_type = "n1-standard-2"
boot_disk {
initialize_params {
image = var.os_image
size = var.gitaly_disk_size
}
}
network_interface {
subnetwork = "default"
access_config {}
}
metadata = {
ssh-keys = format("%s:%s", var.ssh_user, var.ssh_pubkey)
startup-script = var.startup_script
}
tags = ["http-server", "https-server"]
}
output "gitlab_internal_ip" {
value = google_compute_instance.gitlab.network_interface[0].network_ip
}
output "gitlab_external_ip" {
value = google_compute_instance.gitlab.network_interface[0].access_config[0].nat_ip
}
resource "google_compute_instance" "praefect" {
name = format("%s-praefect", var.praefect_demo_cluster_name)
machine_type = "n1-standard-1"
boot_disk {
initialize_params {
image = var.os_image
}
}
network_interface {
subnetwork = "default"
access_config {}
}
metadata = {
ssh-keys = format("%s:%s", var.ssh_user, var.ssh_pubkey)
startup-script = var.startup_script
}
}
output "praefect_internal_ip" {
value = google_compute_instance.praefect.network_interface[0].network_ip
}
output "praefect_ssh_ip" {
value = google_compute_instance.praefect.network_interface[0].access_config[0].nat_ip
}
resource "google_compute_instance" "gitaly" {
count = 3
name = "${var.praefect_demo_cluster_name}-gitaly-${count.index + 1}"
machine_type = var.gitaly_machine_type
boot_disk {
initialize_params {
image = var.os_image
size = var.gitaly_disk_size
}
}
network_interface {
subnetwork = "default"
access_config {}
}
metadata = {
ssh-keys = format("%s:%s", var.ssh_user, var.ssh_pubkey)
startup-script = var.startup_script
}
}
output "gitaly_internal_ip" {
value = {
for instance in google_compute_instance.gitaly:
instance.name => instance.network_interface[0].network_ip
}
}
output "gitaly_ssh_ip" {
value = {
for instance in google_compute_instance.gitaly:
instance.name => instance.network_interface[0].access_config[0].nat_ip
}
}
|