TerraformDevKit 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04709e0dc40b2c3960bd89826014ba546243b34d
|
4
|
+
data.tar.gz: c02340b70022353947393a20281e1f2f45bba1c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b54e4a575922c7d4425497bec680c3c9cf22ecbc6a215606bca11fc5da09ca4802e83dce9b4a7926b6ec59b071514786ef0a967641b038b2ccaa463d0b7391a
|
7
|
+
data.tar.gz: f94a2bd9acc219cb01c09ee03c84bb1821d51d58f96612117d5c5dbdf8411c46f67bbb6a560da93fd54d9f6f57f0906078c4f0020fd4ca0c822ca5712d4f3998
|
@@ -2,19 +2,49 @@ require 'open3'
|
|
2
2
|
|
3
3
|
module TerraformDevKit
|
4
4
|
class Command
|
5
|
-
def self.run(cmd, directory: Dir.pwd, print_output: true)
|
5
|
+
def self.run(cmd, directory: Dir.pwd, print_output: true, close_stdin: true)
|
6
6
|
output = []
|
7
7
|
|
8
|
-
Open3.popen2e(cmd, chdir: directory) do |
|
9
|
-
|
10
|
-
|
11
|
-
puts line if print_output
|
8
|
+
Open3.popen2e(cmd, chdir: directory) do |stdin, stdout_and_stderr, thread|
|
9
|
+
stdout_thread = Thread.new do
|
10
|
+
process_output(stdout_and_stderr, print_output, output)
|
12
11
|
end
|
13
12
|
|
13
|
+
if close_stdin
|
14
|
+
stdin.close
|
15
|
+
else
|
16
|
+
input_thread = Thread.new do
|
17
|
+
loop { stdin.puts $stdin.gets }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
thread.join
|
22
|
+
stdout_thread.join
|
23
|
+
input_thread.terminate unless close_stdin
|
24
|
+
|
14
25
|
raise "Error running command #{cmd}" unless thread.value.success?
|
15
26
|
end
|
16
27
|
|
17
28
|
output
|
18
29
|
end
|
30
|
+
|
31
|
+
private_class_method
|
32
|
+
def self.process_output(stdout_and_stderr, print_output, output)
|
33
|
+
line = ''
|
34
|
+
stdout_and_stderr.each_char do |char|
|
35
|
+
$stdout.print(char) if print_output
|
36
|
+
case char
|
37
|
+
when "\r"
|
38
|
+
next
|
39
|
+
when "\n"
|
40
|
+
output << line
|
41
|
+
line = ''
|
42
|
+
else
|
43
|
+
line << char
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
output << line unless line.empty?
|
48
|
+
end
|
19
49
|
end
|
20
50
|
end
|
@@ -4,33 +4,35 @@ require 'TerraformDevKit/os'
|
|
4
4
|
module TerraformDevKit
|
5
5
|
class TerraformEnvManager
|
6
6
|
def self.exist?(env)
|
7
|
-
output = Command.run('terraform env list')
|
7
|
+
output = Command.run('terraform env list', print_output: false)
|
8
8
|
output.any? { |line| line.tr('* ', '') == env }
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.create(env)
|
12
|
-
|
12
|
+
unless exist?(env)
|
13
|
+
Command.run("terraform env new #{env}", print_output: false)
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.delete(env)
|
16
18
|
if exist?(env)
|
17
19
|
select('default')
|
18
|
-
Command.run("terraform env delete #{env}")
|
20
|
+
Command.run("terraform env delete #{env}", print_output: false)
|
19
21
|
end
|
20
22
|
rescue RuntimeError => error
|
21
23
|
# TODO: Get rid of this hack once the following issue gets fixed:
|
22
24
|
# https://github.com/hashicorp/terraform/issues/15343
|
23
|
-
puts "Error deleting terraform environment: #{error}" \
|
25
|
+
puts "Error deleting terraform environment: #{error}\n" \
|
24
26
|
'NOTE: Deleting an environment does not currently work on Windows'
|
25
27
|
end
|
26
28
|
|
27
29
|
def self.select(env)
|
28
30
|
create(env)
|
29
|
-
Command.run("terraform env select #{env}")
|
31
|
+
Command.run("terraform env select #{env}", print_output: false)
|
30
32
|
end
|
31
33
|
|
32
34
|
def self.active
|
33
|
-
output = Command.run('terraform env list')
|
35
|
+
output = Command.run('terraform env list', print_output: false)
|
34
36
|
active = output.select { |line| line.include?('*') }
|
35
37
|
raise 'Error parsing output from terraform' if active.length != 1
|
36
38
|
match = /\s*\*\s*(\S+)/.match(active[0])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: TerraformDevKit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Jimenez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|