Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2020-04-06 18:01:47 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2020-04-06 18:01:47 +0300
commitfd3dc68ca8ec4b91f07724ff44995d2735828a8f (patch)
tree6eefe983433693dd6599cc9c268e148888cb7344
parent519ee93f755ba6320c929d3cee790650d59a88f9 (diff)
parent86e90ec2711025a69ab3bb696783de324fdf9b51 (diff)
Merge branch 'jv-terraform-cloudsql' into 'master'
Create Gitaly HA PostgreSQL instance with Terraform See merge request gitlab-org/gitaly!1990
-rwxr-xr-x_support/terraform/create-demo-cluster14
-rw-r--r--_support/terraform/main.tf64
-rw-r--r--_support/terraform/terraform.tfvars.erb1
3 files changed, 54 insertions, 25 deletions
diff --git a/_support/terraform/create-demo-cluster b/_support/terraform/create-demo-cluster
index 4c59c9163..e2d8c681e 100755
--- a/_support/terraform/create-demo-cluster
+++ b/_support/terraform/create-demo-cluster
@@ -3,6 +3,7 @@
require 'erb'
require 'etc'
+require 'io/console'
require_relative 'helper.rb'
@@ -29,6 +30,14 @@ def praefect_demo_cluster_name
get_input('Enter a name for your demo cluster', default_name)
end
+def praefect_sql_password
+ get_input(
+ 'Enter a password for the praefect PostgreSQL user',
+ 'PRAEFECT_SQL_PASSWORD',
+ echo: false
+ )
+end
+
def username
Etc.getlogin
end
@@ -46,11 +55,12 @@ def ssh_pubkey
pubkey
end
-def get_input(prompt, default)
+def get_input(prompt, default, echo: true)
puts "#{prompt} (default: #{default})."
print "> "
- input = gets.chomp
+ input = echo ? gets.chomp : STDIN.noecho(&:gets).chomp
+
input.empty? ? default : input
end
diff --git a/_support/terraform/main.tf b/_support/terraform/main.tf
index 6b0af6ec5..629ac8a1d 100644
--- a/_support/terraform/main.tf
+++ b/_support/terraform/main.tf
@@ -9,13 +9,13 @@ variable "startup_script" {
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
+ 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" { }
+variable "praefect_sql_password" { }
provider "google" {
version = "~> 3.12"
@@ -25,27 +25,45 @@ provider "google" {
zone = var.demo_zone
}
-# resource "google_sql_database_instance" "praefect_sql" {
-# name = format("%s-praefect-postgresql", var.praefect_demo_cluster_name)
-# database_version = "POSTGRES_9_6"
-# region = var.demo_region
-#
-# settings {
-# # Second-generation instance tiers are based on the machine
-# # type. See argument reference below.
-# tier = "db-f1-micro"
-# }
-# }
-#
-# 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 "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)
diff --git a/_support/terraform/terraform.tfvars.erb b/_support/terraform/terraform.tfvars.erb
index 73bd7778b..4ddb89ee0 100644
--- a/_support/terraform/terraform.tfvars.erb
+++ b/_support/terraform/terraform.tfvars.erb
@@ -3,3 +3,4 @@ praefect_demo_cluster_name = "<%= praefect_demo_cluster_name %>"
ssh_user = "<%= username %>"
ssh_pubkey = "<%= ssh_pubkey %>"
+praefect_sql_password = "<%= praefect_sql_password %>"