blob: e2d8c681eaa59cebfbf2e636c6ac76ee53db0f5e (
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
|
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'erb'
require 'etc'
require 'io/console'
require_relative 'helper.rb'
TFVARS = 'terraform.tfvars'
def main
unless gcloud_appliction_default_logged_in?
run!(%w[gcloud auth application-default login])
end
unless terraform_initialized?
run!(%w[terraform init])
end
unless File.exist?(TFVARS)
render!(TFVARS, 'terraform.tfvars.erb')
end
run!(%w[terraform apply])
end
def praefect_demo_cluster_name
default_name = "#{username}-#{Time.now.utc.strftime('%Y%m%d')}"
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
def ssh_pubkey
default_path = File.join(Etc.getpwnam(username).dir, '.ssh/id_rsa.pub')
pubkey_path = get_input('Enter the path to your SSH public key', default_path)
pubkey = File.read(pubkey_path).chomp
unless pubkey.start_with?('ssh-')
# Protect against accidentally using the private key
abort "contents of #{path} do not look like an SSH pubkey"
end
pubkey
end
def get_input(prompt, default, echo: true)
puts "#{prompt} (default: #{default})."
print "> "
input = echo ? gets.chomp : STDIN.noecho(&:gets).chomp
input.empty? ? default : input
end
def render!(file, template_path)
IO.write(file, ERB.new(File.read(template_path)).result(binding))
end
def gcloud_appliction_default_logged_in?
system(
*%w[gcloud auth application-default print-access-token],
out: '/dev/null',
err: '/dev/null'
)
end
main
|