tfenv 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e31708fcc19537a5cf5791236366c7b073db92e0
4
- data.tar.gz: b6982294907b1711d1b2c87788087ce060a34620
3
+ metadata.gz: 7c9b29870cbdc8130df2b1a39c5cbafd05974a7d
4
+ data.tar.gz: 8d311b0051a9fd0008c87fce3456f0f8d93d26a8
5
5
  SHA512:
6
- metadata.gz: 51ad485372a2063f03ba66aadd32744889943aabf21d359aff79569cf1e5b8d9c7b1b0bd00bf11af7e8e404506b38980cea828e08ab48e0739f98e9725f89613
7
- data.tar.gz: 903ffcae898be3af7013c23841ce10e9b47ec7905979ca7a4550172f5d490b2d50c502560289d791cad0be6250ec1ad466b4d8161f533413e81ed4e54eeb8005
6
+ metadata.gz: 6d7721059f661014f4815ef6aa579341a331d482f3cddcbdad16b9aa89fb72114ff8c72698c2aa51c0329fbf675c98eb97b3b777ccff194b5e0f79a5053fd97f
7
+ data.tar.gz: fbb5ba20bd63d9311dbbdde6ff362a7987dffa7368c6e9f7e697d7e1588792c61f77d1e59ca27cfa86068e540259e16ac297ad8a5c0ce7ad3a4e665fdcacfc03
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Tfenv
1
+ # tfenv
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tfenv`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Simple gem to manage loading external Terraform module outputs from state files or consul.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,28 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Configuration options:
24
+
25
+ ````
26
+ $ tfenv -h
27
+ Usage: tfenv [options] [command]
28
+ -s, --state-file FILE Include external state output from state file
29
+ -c, --consul URL/KEY Include external state output from consul
30
+ -t, --tfvar FILE Write variables to tfvar file
31
+ -v, --[no-]verbose Run verbosely
32
+ ````
33
+
34
+ Examine outputs for given configuration:
35
+
36
+ ````
37
+ $ tfenv -s ~/main-module/terraform.tfstate
38
+ ````
39
+
40
+ Run terraform (or any other command) using configured outputs:
41
+
42
+ ````
43
+ $ tfenv -s ~/main-module/terraform.tfstate terraform plan
44
+ ````
26
45
 
27
46
  ## Development
28
47
 
@@ -32,7 +51,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
51
 
33
52
  ## Contributing
34
53
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tfenv.
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jbussdieker/tfenv.
36
55
 
37
56
 
38
57
  ## License
data/exe/tfenv CHANGED
@@ -1,80 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'optparse'
3
- require 'json'
4
- require 'yaml'
2
+ require 'tfenv/cli'
5
3
 
6
- def export_hash(hash)
7
- hash.each do |key, value|
8
- ENV["TF_VAR_#{key}"] = value
9
- end
10
- end
11
-
12
- def read_consul_uri(uri)
13
- raise "Not implemented"
14
- end
15
-
16
- def read_outputs(state_file)
17
- {}.tap do |outputs|
18
- read_state(state_file).tap do |state|
19
- state["modules"].each do |module_state|
20
- outputs.merge!(module_state["outputs"])
21
- end
22
- end
23
- end
24
- end
25
-
26
- def read_state(state_file)
27
- raw_state = File.read(state_file)
28
- JSON.parse(raw_state)
29
- end
30
-
31
- def parse_options
32
- options = {
33
- :includes => [],
34
- :consuls => []
35
- }
36
-
37
- OptionParser.new do |opts|
38
- opts.banner = "Usage: tfenv [options] [command]"
39
-
40
- opts.on("-s", "--state-file FILE", "Include external state output from state file") do |v|
41
- options[:includes] << v
42
- end
43
-
44
- opts.on("-c", "--consul URL/KEY", "Include external state output from consul") do |v|
45
- options[:consuls] << v
46
- end
47
-
48
- opts.on("-t", "--tfvar FILE", "Write variables to tfvar file") do |v|
49
- options[:tfvar] = v
50
- end
51
-
52
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
53
- options[:verbose] = v
54
- end
55
- end.parse!
56
-
57
- options
58
- end
59
-
60
- def collate_outputs(options)
61
- {}.tap do |outputs|
62
- options[:includes].each do |state_file|
63
- outputs.merge!(read_outputs(state_file))
64
- end
65
-
66
- options[:consuls].each do |consul_uri|
67
- outputs.merge!(read_consul_uri(consul_uri))
68
- end
69
- end
70
- end
71
-
72
- options = parse_options
73
- outputs = collate_outputs(options)
74
-
75
- if ARGV.length > 0
76
- export_hash(outputs)
77
- exec(*ARGV)
78
- else
79
- puts outputs.to_yaml
80
- end
4
+ TFEnv::CLI.new(ARGV).start
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ module TFEnv
7
+ class CLI
8
+ def initialize(*args)
9
+ @args = args
10
+ end
11
+
12
+ def export_hash(hash)
13
+ hash.each do |key, value|
14
+ ENV["TF_VAR_#{key}"] = value
15
+ end
16
+ end
17
+
18
+ def read_consul_uri(uri)
19
+ raise "Not implemented"
20
+ end
21
+
22
+ def read_outputs(state_file)
23
+ {}.tap do |outputs|
24
+ read_state(state_file).tap do |state|
25
+ state["modules"].each do |module_state|
26
+ outputs.merge!(module_state["outputs"])
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ def read_state(state_file)
33
+ raw_state = File.read(state_file)
34
+ JSON.parse(raw_state)
35
+ end
36
+
37
+ def parse_options
38
+ options = {
39
+ :includes => [],
40
+ :consuls => []
41
+ }
42
+
43
+ OptionParser.new do |opts|
44
+ opts.banner = "Usage: tfenv [options] [command]"
45
+
46
+ opts.on("-s", "--state-file FILE", "Include external state output from state file") do |v|
47
+ options[:includes] << v
48
+ end
49
+
50
+ opts.on("-c", "--consul URL/KEY", "Include external state output from consul") do |v|
51
+ options[:consuls] << v
52
+ end
53
+
54
+ opts.on("-t", "--tfvar FILE", "Write variables to tfvar file") do |v|
55
+ options[:tfvar] = v
56
+ end
57
+
58
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
59
+ options[:verbose] = v
60
+ end
61
+ end.parse!
62
+
63
+ options
64
+ end
65
+
66
+ def collate_outputs(options)
67
+ {}.tap do |outputs|
68
+ options[:includes].each do |state_file|
69
+ outputs.merge!(read_outputs(state_file))
70
+ end
71
+
72
+ options[:consuls].each do |consul_uri|
73
+ outputs.merge!(read_consul_uri(consul_uri))
74
+ end
75
+ end
76
+ end
77
+
78
+ def load_outputs(options)
79
+ {}.tap do |outputs|
80
+ if options[:includes].empty? && options[:consuls].empty?
81
+ if File.exists?("terraform.tfstate")
82
+ return read_outputs("terraform.tfstate")
83
+ end
84
+ else
85
+ collate_outputs(options)
86
+ end
87
+ end
88
+ end
89
+
90
+ def start
91
+ options = parse_options
92
+ outputs = load_outputs(options)
93
+
94
+ if ARGV.length > 0
95
+ export_hash(outputs)
96
+ exec(*ARGV)
97
+ else
98
+ puts outputs.to_yaml
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,3 +1,3 @@
1
1
  module Tfenv
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -20,5 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.10"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rspec", "~> 3.4", ">= 3.4.0"
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tfenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua B. Bussdieker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,22 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
45
48
  - - ">="
46
49
  - !ruby/object:Gem::Version
47
- version: '0'
50
+ version: 3.4.0
48
51
  type: :development
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.4'
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: '0'
60
+ version: 3.4.0
55
61
  description:
56
62
  email:
57
63
  - jbussdieker@gmail.com
@@ -71,6 +77,7 @@ files:
71
77
  - bin/setup
72
78
  - exe/tfenv
73
79
  - lib/tfenv.rb
80
+ - lib/tfenv/cli.rb
74
81
  - lib/tfenv/version.rb
75
82
  - tfenv.gemspec
76
83
  homepage: https://github.com/jbussdieker/tfenv
@@ -93,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
100
  version: '0'
94
101
  requirements: []
95
102
  rubyforge_project:
96
- rubygems_version: 2.4.5.1
103
+ rubygems_version: 2.5.1
97
104
  signing_key:
98
105
  specification_version: 4
99
106
  summary: Simple tool for loading external module outputs.