yutani 0.1.15 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yutani/cli.rb +8 -7
- data/lib/yutani/remote_config.rb +67 -0
- data/lib/yutani/resource.rb +3 -2
- data/lib/yutani/stack.rb +23 -34
- data/lib/yutani/utils.rb +7 -1
- data/lib/yutani/version.rb +1 -1
- data/lib/yutani.rb +3 -5
- metadata +2 -2
- data/lib/yutani/directory_tree.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb2d4ad0c04c2786185ef8c2fc5dee90be6460a3
|
4
|
+
data.tar.gz: f178131e875565618b1ce5d80bec675d2139e2cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 680b9f75c7ac957e049625be0ed4008f4e4ee00806f3877deca9333770692d2d5db3efffade73d7cb945387fc7835facaff6a81704b985f6a15ca2c207aaa99e
|
7
|
+
data.tar.gz: ba161b43a65b0f9269964e9f4dc093630762b69986223ac7f50433493c177958193290862f6aeac51c5dac07adb810b280b81616ffc922ae663a742fa92221e1
|
data/lib/yutani/cli.rb
CHANGED
@@ -22,7 +22,7 @@ module Yutani
|
|
22
22
|
|
23
23
|
desc 'build', 'Evaluates DSL scripts and creates terraform files'
|
24
24
|
def build
|
25
|
-
scripts_dir = Yutani
|
25
|
+
scripts_dir = Yutani.config['scripts_dir']
|
26
26
|
|
27
27
|
files = Dir.glob(File.join(scripts_dir, '*.rb'))
|
28
28
|
if files.empty?
|
@@ -32,10 +32,6 @@ module Yutani
|
|
32
32
|
files.each do |script|
|
33
33
|
Yutani.eval_file(script)
|
34
34
|
end
|
35
|
-
|
36
|
-
unless Yutani.stacks.empty?
|
37
|
-
Yutani.stacks.each {|s| s.to_fs}
|
38
|
-
end
|
39
35
|
end
|
40
36
|
|
41
37
|
# we need to know these things:
|
@@ -45,8 +41,9 @@ module Yutani
|
|
45
41
|
desc 'watch', 'Run build upon changes to scripts'
|
46
42
|
def watch
|
47
43
|
Listen.to(
|
48
|
-
Yutani
|
49
|
-
Yutani
|
44
|
+
Yutani.config['scripts_dir'],
|
45
|
+
Yutani.config['includes_dir'],
|
46
|
+
Yutani.config['templates_dir']
|
50
47
|
) do |m, a, d|
|
51
48
|
|
52
49
|
Yutani.logger.info "Re-build triggered: #{m} modified" unless m.empty?
|
@@ -133,6 +130,10 @@ module Yutani
|
|
133
130
|
FileUtils.mkdir Yutani::Config::DEFAULTS['includes_dir']
|
134
131
|
end
|
135
132
|
|
133
|
+
unless Dir.exists? Yutani::Config::DEFAULTS['templates_dir']
|
134
|
+
FileUtils.mkdir Yutani::Config::DEFAULTS['templates_dir']
|
135
|
+
end
|
136
|
+
|
136
137
|
hiera_dir = Yutani::Config::DEFAULTS['hiera_config'][:yaml][:datadir]
|
137
138
|
FileUtils.mkdir hiera_dir unless Dir.exists? hiera_dir
|
138
139
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Yutani
|
4
|
+
class TerraformCommandError < StandardError; end
|
5
|
+
|
6
|
+
class RemoteConfig
|
7
|
+
include Hiera
|
8
|
+
|
9
|
+
def initialize(&block)
|
10
|
+
Docile.dsl_eval(self, &block) if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
def command
|
14
|
+
cmds = []
|
15
|
+
cmds << "terraform remote config"
|
16
|
+
cmds << "-backend=#{@backend}"
|
17
|
+
|
18
|
+
@backend_config.fields.each do |k,v|
|
19
|
+
cmds << "-backend-config=\"#{k}=#{v}\""
|
20
|
+
end
|
21
|
+
|
22
|
+
cmds << "-pull=false"
|
23
|
+
|
24
|
+
cmds.join(' ')
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute!
|
28
|
+
_, stderr, ret_code = Open3.capture3(command)
|
29
|
+
|
30
|
+
if ret_code != 0
|
31
|
+
raise TerraformCommandError,
|
32
|
+
"running the command \"#{command}\" returned error: #{stderr}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def backend(backend_type)
|
37
|
+
@backend = backend_type
|
38
|
+
end
|
39
|
+
|
40
|
+
def backend_config(&block)
|
41
|
+
@backend_config = BackendConfig.new(&block)
|
42
|
+
end
|
43
|
+
|
44
|
+
class BackendConfig
|
45
|
+
attr_reader :fields
|
46
|
+
|
47
|
+
def initialize(&block)
|
48
|
+
@fields = {}
|
49
|
+
|
50
|
+
Docile.dsl_eval(self, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def respond_to_missing?(method_name, include_private = false)
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
def method_missing(name, *args, &block)
|
58
|
+
if block_given?
|
59
|
+
raise StandardError,
|
60
|
+
"backend_config properties do not accept blocks as parameters"
|
61
|
+
else
|
62
|
+
@fields[name] = args.first
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/yutani/resource.rb
CHANGED
@@ -13,7 +13,7 @@ module Yutani
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def resource_name
|
16
|
-
@namespace.
|
16
|
+
@namespace.to_underscored_string
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_h
|
@@ -25,7 +25,8 @@ module Yutani
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def ref(resource_type, *namespace, attr)
|
28
|
-
"${%s}" % [resource_type, namespace.
|
28
|
+
"${%s}" % [resource_type, namespace.to_underscored_string, attr].
|
29
|
+
join('.')
|
29
30
|
end
|
30
31
|
|
31
32
|
def template(path, **kv)
|
data/lib/yutani/stack.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module Yutani
|
4
5
|
class Stack
|
@@ -7,17 +8,18 @@ module Yutani
|
|
7
8
|
attr_accessor :resources, :providers, :outputs, :variables
|
8
9
|
|
9
10
|
def initialize(*namespace, &block)
|
10
|
-
@resources
|
11
|
-
@providers
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
11
|
+
@resources = []
|
12
|
+
@providers = []
|
13
|
+
@remote_config = nil
|
14
|
+
@outputs = {}
|
15
|
+
@variables = {}
|
16
|
+
@namespace = namespace
|
15
17
|
|
16
18
|
Docile.dsl_eval(self, &block) if block_given?
|
17
19
|
end
|
18
20
|
|
19
21
|
def name
|
20
|
-
@namespace.
|
22
|
+
@namespace.to_underscored_string
|
21
23
|
end
|
22
24
|
|
23
25
|
def resource(resource_type, *namespace, &block)
|
@@ -30,6 +32,10 @@ module Yutani
|
|
30
32
|
Provider.new(name, &block)
|
31
33
|
end
|
32
34
|
|
35
|
+
def remote_config(&block)
|
36
|
+
@remote_config = RemoteConfig.new(&block)
|
37
|
+
end
|
38
|
+
|
33
39
|
# troposphere-like methods
|
34
40
|
def add_resource(resource)
|
35
41
|
@resources << resource
|
@@ -40,15 +46,14 @@ module Yutani
|
|
40
46
|
end
|
41
47
|
|
42
48
|
def inc(&block)
|
43
|
-
|
44
|
-
path = File.join(includes_dir, yield)
|
49
|
+
path = File.join(Yutani.config['includes_dir'], yield)
|
45
50
|
|
46
51
|
eval File.read(path), block.binding, path
|
47
52
|
end
|
48
53
|
|
49
54
|
# this generates the contents of *.tf.main
|
50
55
|
def to_h
|
51
|
-
h = {
|
56
|
+
h = {
|
52
57
|
resource: @resources.inject(DeepMergeHash.new){|resources,r|
|
53
58
|
resources.deep_merge!(r.to_h)
|
54
59
|
},
|
@@ -74,34 +79,18 @@ module Yutani
|
|
74
79
|
end
|
75
80
|
|
76
81
|
def dir_path
|
77
|
-
name
|
78
|
-
end
|
79
|
-
|
80
|
-
def tar(filename)
|
81
|
-
File.open(filename, 'w+') do |tarball|
|
82
|
-
create_dir_tree('./').to_tar(tarball)
|
83
|
-
end
|
82
|
+
File.join(Yutani.config['terraform_dir'], name)
|
84
83
|
end
|
85
84
|
|
86
|
-
def to_fs
|
87
|
-
|
88
|
-
|
85
|
+
def to_fs
|
86
|
+
FileUtils.mkdir_p(dir_path)
|
87
|
+
FileUtils.cd(dir_path) do
|
88
|
+
File.open('main.tf.json', 'w+', 0644) do |f|
|
89
|
+
f.write pretty_json
|
90
|
+
end
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
def dir_tree(dt, prefix)
|
95
|
-
full_dir_path = File.join(prefix, self.dir_path)
|
96
|
-
main_tf_path = File.join(full_dir_path, 'main.tf.json')
|
97
|
-
|
98
|
-
dt.add_file(
|
99
|
-
main_tf_path,
|
100
|
-
0644,
|
101
|
-
self.pretty_json
|
102
|
-
)
|
103
|
-
|
104
|
-
dt
|
92
|
+
@remote_config.execute! unless @remote_config.nil?
|
93
|
+
end
|
105
94
|
end
|
106
95
|
end
|
107
96
|
end
|
data/lib/yutani/utils.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'hashie'
|
2
2
|
|
3
|
+
class Array
|
4
|
+
def to_underscored_string
|
5
|
+
map{|n| n.to_s.gsub('-', '_') }.join('_')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
module Yutani
|
4
10
|
class IndifferentHash < Hash
|
5
11
|
include Hashie::Extensions::MergeInitializer
|
@@ -31,6 +37,6 @@ module Yutani
|
|
31
37
|
v
|
32
38
|
end
|
33
39
|
end
|
34
|
-
end
|
40
|
+
end
|
35
41
|
end
|
36
42
|
end
|
data/lib/yutani/version.rb
CHANGED
data/lib/yutani.rb
CHANGED
@@ -7,19 +7,17 @@ require 'yutani/version'
|
|
7
7
|
require 'yutani/config'
|
8
8
|
require 'yutani/hiera'
|
9
9
|
require 'yutani/cli'
|
10
|
-
require 'yutani/directory_tree'
|
11
10
|
require 'yutani/stack'
|
12
11
|
require 'yutani/resource'
|
12
|
+
require 'yutani/remote_config'
|
13
13
|
require 'yutani/provider'
|
14
14
|
require 'yutani/template'
|
15
15
|
require 'yutani/utils'
|
16
16
|
|
17
17
|
module Yutani
|
18
|
-
@stacks = []
|
19
|
-
|
20
18
|
class << self
|
21
19
|
# do we need :logger?
|
22
|
-
attr_accessor :hiera, :
|
20
|
+
attr_accessor :hiera, :logger
|
23
21
|
|
24
22
|
def logger
|
25
23
|
@logger ||= (
|
@@ -32,7 +30,7 @@ module Yutani
|
|
32
30
|
# DSL statement
|
33
31
|
def stack(*namespace, &block)
|
34
32
|
s = Stack.new(*namespace, &block)
|
35
|
-
|
33
|
+
s.to_fs
|
36
34
|
s
|
37
35
|
end
|
38
36
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yutani
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis Garman
|
@@ -172,9 +172,9 @@ files:
|
|
172
172
|
- lib/yutani.rb
|
173
173
|
- lib/yutani/cli.rb
|
174
174
|
- lib/yutani/config.rb
|
175
|
-
- lib/yutani/directory_tree.rb
|
176
175
|
- lib/yutani/hiera.rb
|
177
176
|
- lib/yutani/provider.rb
|
177
|
+
- lib/yutani/remote_config.rb
|
178
178
|
- lib/yutani/resource.rb
|
179
179
|
- lib/yutani/stack.rb
|
180
180
|
- lib/yutani/template.rb
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'rubygems/package'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module Yutani
|
5
|
-
# An abstraction of a real directory tree on disk
|
6
|
-
# Permits us to decide later whether this will be written to disk
|
7
|
-
# or embedded in a tarball, or sent over scp, etc.
|
8
|
-
class DirectoryTree
|
9
|
-
File = Struct.new(:path, :permissions, :content)
|
10
|
-
|
11
|
-
attr_reader :files, :prefix
|
12
|
-
|
13
|
-
def initialize(prefix = './')
|
14
|
-
@prefix = prefix
|
15
|
-
@files = []
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_file(path, permissions, content)
|
19
|
-
@files << File.new(::File.join(@prefix, path), permissions.to_i, content)
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_fs
|
23
|
-
@files.each do |f|
|
24
|
-
FileUtils.mkdir_p(::File.dirname(f.path))
|
25
|
-
::File.open(f.path, 'w+', f.permissions) do |new_f|
|
26
|
-
new_f.write f.content
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_tar(io = STDOUT)
|
32
|
-
Gem::Package::TarWriter.new(io) do |tar|
|
33
|
-
@files.each do |f|
|
34
|
-
tar.mkdir(::File.dirname(f.path), '0755')
|
35
|
-
|
36
|
-
tar.add_file_simple(f.path, f.permissions, f.content.bytes.size) do |tar_file|
|
37
|
-
tar_file.write f.content
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|