terraframe 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/terraframe +45 -22
- data/lib/terraframe/processor.rb +12 -8
- data/lib/terraframe/script_item.rb +6 -1
- data/lib/terraframe/state.rb +2 -2
- data/lib/terraframe/version.rb +1 -1
- data/terraframe.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2af2c4fd034f13f39c212b92ff6b62b84336238a
|
4
|
+
data.tar.gz: 879e04c38e9f2257aa5a2d0a5fc6e9429a0ff9d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08053ef0830878e586cfaa71050db9ac86cf8a87ea4acfb8d0348f6759b6fec1dc7338444914e74d46746c521f8f5b5577983162bd1eb93c259807c10890a83c
|
7
|
+
data.tar.gz: 2b81f5742f3e391302a269c4a900a223fac75464cd78a6895ae8b998438fcb6ceecb86289d65d002a58895287e1671cf031dd01ec116806e436366fce1fc2945
|
data/bin/terraframe
CHANGED
@@ -3,30 +3,53 @@
|
|
3
3
|
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
4
|
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
5
|
|
6
|
-
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
def main()
|
7
|
+
require 'logger'
|
8
|
+
require 'trollop'
|
9
|
+
require 'terraframe'
|
10
|
+
require 'awesome_print'
|
11
|
+
require 'hashie/mash'
|
12
|
+
|
13
|
+
opts = Trollop::options do
|
14
|
+
opt :input_file, "Input file(s) to process into a Terraform script.",
|
15
|
+
:short => "f", :type => :string, :multi => true, :required => true
|
16
|
+
opt :variable_file, "Variable file (YAML or JSON, not tfvars!).",
|
17
|
+
:short => "v", :type => :string, :multi => true
|
18
|
+
opt :override_variable, "'key,value' to be injected into the Terraframe args hash.",
|
19
|
+
:short => "o", :type => :string, :multi => true
|
20
|
+
opt :pretty_print, "Pretty-prints the Terraform output.", :default => true
|
21
|
+
opt :verbose, "Increases logging verbosity.", :default => false
|
22
|
+
end
|
23
|
+
|
24
|
+
processor = Terraframe::Processor.new
|
25
|
+
if opts[:verbose]
|
26
|
+
processor.logger.level = Logger::DEBUG
|
27
|
+
end
|
28
|
+
processor.logger.ap opts.inspect, :debug
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
|
30
|
+
output = processor.process_files(opts[:input_file],
|
31
|
+
opts[:variable_file] || [],
|
32
|
+
process_properties(opts[:override_variable]))
|
33
|
+
if opts[:pretty_print]
|
34
|
+
output = JSON.pretty_generate(JSON.parse(output))
|
35
|
+
end
|
36
|
+
|
37
|
+
processor.logger.info "Writing output to stdout."
|
38
|
+
puts output
|
23
39
|
end
|
24
|
-
processor.logger.debug opts.inspect
|
25
40
|
|
26
|
-
|
27
|
-
|
28
|
-
|
41
|
+
def process_properties(props)
|
42
|
+
hash = props.map { |p| p.split("=", 2) }.to_h
|
43
|
+
|
44
|
+
hash_trees = hash.map do |main_key, main_value|
|
45
|
+
main_key.to_s.split(".").reverse.inject(main_value) do |value, key|
|
46
|
+
{key.to_s => value}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
retval = {}
|
51
|
+
hash_trees.each { |h| retval.deep_merge!(h) }
|
52
|
+
retval
|
29
53
|
end
|
30
54
|
|
31
|
-
|
32
|
-
puts output
|
55
|
+
main()
|
data/lib/terraframe/processor.rb
CHANGED
@@ -32,24 +32,28 @@ module Terraframe
|
|
32
32
|
@contexts[name] = context
|
33
33
|
end
|
34
34
|
|
35
|
-
def process_files(scripts,
|
35
|
+
def process_files(scripts, variable_files, override_variables)
|
36
36
|
scripts = scripts.map { |f| File.expand_path(f) }
|
37
|
-
|
37
|
+
variable_files = variable_files.map { |f| File.expand_path(f) }
|
38
38
|
|
39
39
|
missing_scripts = scripts.reject { |f| File.exist?(f) }
|
40
|
-
|
41
|
-
unless missing_scripts.empty? &&
|
40
|
+
missing_variable_files = variable_files.reject { |f| File.exist?(f) }
|
41
|
+
unless missing_scripts.empty? && missing_variable_files.empty?
|
42
42
|
missing_scripts.each { |f| logger.fatal "Script file not found: #{f}" }
|
43
|
-
|
43
|
+
missing_variable_files.each { |f| logger.fatal "Variable file not found: #{f}" }
|
44
44
|
raise "One or more specified files were missing."
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
|
48
|
+
script_pairs = scripts.zip(scripts.map { |f| IO.read(f) })
|
49
|
+
vars = load_variable_files(variable_files).deep_merge(override_variables)
|
50
|
+
|
51
|
+
apply(script_pairs.to_h, vars)
|
48
52
|
end
|
49
53
|
|
50
|
-
def
|
54
|
+
def load_variable_files(variable_files)
|
51
55
|
vars = {}
|
52
|
-
|
56
|
+
variable_files.each { |f| vars = vars.deep_merge(YAML::load_file(f)) }
|
53
57
|
vars
|
54
58
|
end
|
55
59
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'hashie/mash'
|
2
3
|
|
3
4
|
module Terraframe
|
4
5
|
class ScriptItem
|
@@ -7,7 +8,7 @@ module Terraframe
|
|
7
8
|
|
8
9
|
def initialize(vars, &block)
|
9
10
|
@fields = {}
|
10
|
-
@vars = vars
|
11
|
+
@vars = Hashie::Mash.new(vars)
|
11
12
|
|
12
13
|
instance_eval &block
|
13
14
|
end
|
@@ -19,6 +20,10 @@ module Terraframe
|
|
19
20
|
## DSL FUNCTIONS BELOW
|
20
21
|
def method_missing(method_name, *args, &block)
|
21
22
|
if args.length == 1
|
23
|
+
if args[0] == nil
|
24
|
+
raise "Passed nil to '#{method_name}'. Generally disallowed, subclass ScriptItem if you need this."
|
25
|
+
end
|
26
|
+
|
22
27
|
@fields[method_name.to_sym] = args[0]
|
23
28
|
else
|
24
29
|
raise "Multiple fields passed to a scalar auto-argument '#{method_name}'."
|
data/lib/terraframe/state.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
-
require '
|
2
|
+
require 'hashie/mash'
|
3
3
|
|
4
4
|
module Terraframe
|
5
5
|
class State
|
@@ -10,7 +10,7 @@ module Terraframe
|
|
10
10
|
@logger = logger
|
11
11
|
logger.info "Initializing state."
|
12
12
|
|
13
|
-
@vars =
|
13
|
+
@vars = Hashie::Mash.new(vars)
|
14
14
|
logger.debug "State variables:"
|
15
15
|
logger.ap vars, :debug
|
16
16
|
|
data/lib/terraframe/version.rb
CHANGED
data/terraframe.gemspec
CHANGED
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency "trollop", "~> 2.0"
|
25
25
|
spec.add_runtime_dependency "activesupport", "~> 4.2.0"
|
26
26
|
spec.add_runtime_dependency "awesome_print", "~> 1.6.1"
|
27
|
-
spec.add_runtime_dependency
|
27
|
+
spec.add_runtime_dependency 'hashie', '~> 3.3.2'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraframe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Ropple
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,19 +81,19 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.6.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: hashie
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.3.2
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 3.3.2
|
97
97
|
description:
|
98
98
|
email:
|
99
99
|
- ed@edropple.com
|