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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69c298bb5fae6f55bd0926b9f6ee7d51317a932c
4
- data.tar.gz: 1e27ef8d075df5f45a8f32b0bc6790b303c575d3
3
+ metadata.gz: 2af2c4fd034f13f39c212b92ff6b62b84336238a
4
+ data.tar.gz: 879e04c38e9f2257aa5a2d0a5fc6e9429a0ff9d7
5
5
  SHA512:
6
- metadata.gz: 494647a04c86977f4652244a39984e201693628303619122bd50584a73e80c19c350b0e3c6df1392318de2de5829e8247f114e7b83bffd3dcb652986468b1da2
7
- data.tar.gz: 4a5b5829ce32c10cf1f39e4e72b77246ada761a612ec5fe2da3f86fe5fa153e532f42d152c49bb1984639fe11839b3ea56f68ccd7fe0067e32dd2c21d140ea92
6
+ metadata.gz: 08053ef0830878e586cfaa71050db9ac86cf8a87ea4acfb8d0348f6759b6fec1dc7338444914e74d46746c521f8f5b5577983162bd1eb93c259807c10890a83c
7
+ data.tar.gz: 2b81f5742f3e391302a269c4a900a223fac75464cd78a6895ae8b998438fcb6ceecb86289d65d002a58895287e1671cf031dd01ec116806e436366fce1fc2945
@@ -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
- require 'logger'
7
- require 'trollop'
8
- require 'terraframe'
9
- require 'awesome_print'
10
-
11
- opts = Trollop::options do
12
- opt :input_file, "Input file(s) to process into a Terraform script.",
13
- :short => "f", :type => :string, :multi => true, :required => true
14
- opt :variable_file, "Variable file (YAML or JSON, not tfvars!).",
15
- :short => "v", :type => :string, :multi => true
16
- opt :pretty_print, "Pretty-prints the Terraform output.", :default => true
17
- opt :verbose, "Increases logging verbosity.", :default => false
18
- end
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
- processor = Terraframe::Processor.new
21
- if opts[:verbose]
22
- processor.logger.level = Logger::DEBUG
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
- output = processor.process_files(opts[:input_file], opts[:variable_file] || [])
27
- if opts[:pretty_print]
28
- output = JSON.pretty_generate(JSON.parse(output))
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
- processor.logger.info "Writing output to stdout."
32
- puts output
55
+ main()
@@ -32,24 +32,28 @@ module Terraframe
32
32
  @contexts[name] = context
33
33
  end
34
34
 
35
- def process_files(scripts, variables)
35
+ def process_files(scripts, variable_files, override_variables)
36
36
  scripts = scripts.map { |f| File.expand_path(f) }
37
- variables = variables.map { |f| File.expand_path(f) }
37
+ variable_files = variable_files.map { |f| File.expand_path(f) }
38
38
 
39
39
  missing_scripts = scripts.reject { |f| File.exist?(f) }
40
- missing_variables = variables.reject { |f| File.exist?(f) }
41
- unless missing_scripts.empty? && missing_variables.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
- missing_variables.each { |f| logger.fatal "Variable file not found: #{f}" }
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
- apply(Hash[scripts.zip(scripts.map { |f| IO.read(f) })], load_variables(variables))
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 load_variables(variables)
54
+ def load_variable_files(variable_files)
51
55
  vars = {}
52
- variables.each { |f| vars = vars.deep_merge(YAML::load_file(f)) }
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}'."
@@ -1,5 +1,5 @@
1
1
  require 'json'
2
- require 'recursive_open_struct'
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 = RecursiveOpenStruct.new(vars, :recurse_over_arrays => true )
13
+ @vars = Hashie::Mash.new(vars)
14
14
  logger.debug "State variables:"
15
15
  logger.ap vars, :debug
16
16
 
@@ -1,3 +1,3 @@
1
1
  module Terraframe
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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 "recursive-open-struct", "~> 0.5.0"
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.5
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-10 00:00:00.000000000 Z
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: recursive-open-struct
84
+ name: hashie
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.5.0
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: 0.5.0
96
+ version: 3.3.2
97
97
  description:
98
98
  email:
99
99
  - ed@edropple.com