sparkle_formation 3.0.10 → 3.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/LICENSE +1 -1
- data/docs/sparkle-packs.md +1 -1
- data/lib/sparkle_formation/function_struct.rb +60 -6
- data/lib/sparkle_formation/provider/aws.rb +11 -6
- data/lib/sparkle_formation/provider/terraform.rb +146 -0
- data/lib/sparkle_formation/provider.rb +1 -0
- data/lib/sparkle_formation/resources/aws_resources.json +1567 -209
- data/lib/sparkle_formation/resources/azure_resources.json +4247 -1260
- data/lib/sparkle_formation/resources/heat_resources.json +1365 -704
- data/lib/sparkle_formation/resources/rackspace_resources.json +1159 -60
- data/lib/sparkle_formation/resources/terraform.rb +47 -0
- data/lib/sparkle_formation/resources/terraform_resources.json +1 -0
- data/lib/sparkle_formation/resources.rb +1 -0
- data/lib/sparkle_formation/sparkle_attribute/aws.rb +23 -0
- data/lib/sparkle_formation/sparkle_attribute/terraform.rb +151 -0
- data/lib/sparkle_formation/sparkle_attribute.rb +1 -0
- data/lib/sparkle_formation/sparkle_formation.rb +1 -1
- data/lib/sparkle_formation/version.rb +1 -1
- data/lib/sparkle_formation.rb +1 -18
- data/sparkle_formation.gemspec +1 -0
- metadata +20 -3
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'sparkle_formation'
|
2
|
+
|
3
|
+
class SparkleFormation
|
4
|
+
|
5
|
+
# Resources helper
|
6
|
+
class Resources
|
7
|
+
|
8
|
+
# Terraform specific resources collection
|
9
|
+
class Terraform < Resources
|
10
|
+
|
11
|
+
# String to split for resource namespacing
|
12
|
+
RESOURCE_TYPE_NAMESPACE_SPLITTER = ['_']
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
include Bogo::Memoization
|
17
|
+
|
18
|
+
# Load the builtin Terraform resources
|
19
|
+
#
|
20
|
+
# @return [TrueClass]
|
21
|
+
def load!
|
22
|
+
memoize(:terraform_resources, :global) do
|
23
|
+
load(
|
24
|
+
File.join(
|
25
|
+
File.dirname(__FILE__),
|
26
|
+
'terraform_resources.json'
|
27
|
+
)
|
28
|
+
)
|
29
|
+
# NOTE: Internal resource type used for nesting
|
30
|
+
register('module',
|
31
|
+
'properties' => [],
|
32
|
+
'full_properties' => {}
|
33
|
+
)
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Auto load data when included
|
39
|
+
def included(_klass)
|
40
|
+
load!
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{}
|
@@ -9,6 +9,7 @@ class SparkleFormation
|
|
9
9
|
autoload :Google, 'sparkle_formation/resources/google'
|
10
10
|
autoload :Heat, 'sparkle_formation/resources/heat'
|
11
11
|
autoload :Rackspace, 'sparkle_formation/resources/rackspace'
|
12
|
+
autoload :Terraform, 'sparkle_formation/resources/terraform'
|
12
13
|
|
13
14
|
# Characters to be removed from supplied key on matching
|
14
15
|
RESOURCE_TYPE_TR = '_'
|
@@ -25,6 +25,18 @@ class SparkleFormation
|
|
25
25
|
end
|
26
26
|
alias_method :join!, :_cf_join
|
27
27
|
|
28
|
+
# Split generator
|
29
|
+
#
|
30
|
+
# @param string [String] string to split
|
31
|
+
# @param delimiter [String] delimiter to split string
|
32
|
+
# @return [Hash]
|
33
|
+
def _cf_split(string, delimiter)
|
34
|
+
__t_stringish(string)
|
35
|
+
__t_stringish(delimiter)
|
36
|
+
{'Fn::Split' => [delimiter, string]}
|
37
|
+
end
|
38
|
+
alias_method :split!, :_cf_split
|
39
|
+
|
28
40
|
# Ref generator
|
29
41
|
#
|
30
42
|
# @param thing [String, Symbol] reference name
|
@@ -37,6 +49,17 @@ class SparkleFormation
|
|
37
49
|
alias_method :_ref, :_cf_ref
|
38
50
|
alias_method :ref!, :_cf_ref
|
39
51
|
|
52
|
+
# ValueImport generator
|
53
|
+
#
|
54
|
+
# @param thing [String, String] value import
|
55
|
+
# @return [Hash]
|
56
|
+
def _cf_value_import(thing)
|
57
|
+
__t_stringish(thing)
|
58
|
+
{'Fn::ImportValue' => __attribute_key(thing)}
|
59
|
+
end
|
60
|
+
alias_method :_import_value, :_cf_value_import
|
61
|
+
alias_method :import_value!, :_cf_value_import
|
62
|
+
|
40
63
|
# @overload _cf_map(map_name, top_level_key, second_level_key)
|
41
64
|
# Fn::FindInMap generator
|
42
65
|
# @param map_name [String, Symbol] name of map
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'sparkle_formation'
|
2
|
+
|
3
|
+
class SparkleFormation
|
4
|
+
|
5
|
+
# Provides template helper methods
|
6
|
+
module SparkleAttribute
|
7
|
+
|
8
|
+
# Terraform specific helper implementations
|
9
|
+
module Terraform
|
10
|
+
|
11
|
+
# Set customized struct behavior
|
12
|
+
def self.included(klass)
|
13
|
+
klass.const_set(:CAMEL_KEYS, false)
|
14
|
+
end
|
15
|
+
|
16
|
+
def _var(v_name)
|
17
|
+
__t_stringish(v_name)
|
18
|
+
res = ::SparkleFormation::TerraformStruct.new('var').set!(__attribute_key(v_name))
|
19
|
+
end
|
20
|
+
alias_method :var!, :_var
|
21
|
+
alias_method :parameter!, :_var
|
22
|
+
|
23
|
+
def _path(p_name)
|
24
|
+
__t_stringish(p_name)
|
25
|
+
::SparkleFormation::TerraformStruct.new('path').set!(__attribute_key(p_name))
|
26
|
+
end
|
27
|
+
alias_method :path!, :_path
|
28
|
+
|
29
|
+
def _module(m_name)
|
30
|
+
__t_stringish(m_name)
|
31
|
+
::SparkleFormation::TerraformStruct.new('module').set!(__attribute_key(m_name))
|
32
|
+
end
|
33
|
+
alias_method :module!, :_module
|
34
|
+
|
35
|
+
def _terraform_self(s_name)
|
36
|
+
__t_stringish(s_name)
|
37
|
+
::SparkleFormation::TerraformStruct.new('self').set!(__attribute_key(s_name))
|
38
|
+
end
|
39
|
+
alias_method :self!, :_terraform_self
|
40
|
+
|
41
|
+
def _terraform_lookup(*args)
|
42
|
+
::SparkleFormation::TerraformStruct.new('lookup', *args)
|
43
|
+
end
|
44
|
+
alias_method :lookup!, :_terraform_lookup
|
45
|
+
|
46
|
+
# TODO: Add resource checking before returning structure
|
47
|
+
def _resource(r_name)
|
48
|
+
__t_stringish(r_name)
|
49
|
+
r_name = __resource_lookup(r_name)
|
50
|
+
::SparkleFormation::TerraformStruct.new(r_name)
|
51
|
+
end
|
52
|
+
alias_method :resource!, :_resource
|
53
|
+
|
54
|
+
TERRAFORM_INTRINSIC_FUNCTIONS = [
|
55
|
+
'base64decode',
|
56
|
+
'base64encode',
|
57
|
+
'base64sha256',
|
58
|
+
'cidrhost',
|
59
|
+
'cidrnetmask',
|
60
|
+
'cidrsubnet',
|
61
|
+
'coalesce',
|
62
|
+
'compact',
|
63
|
+
'concat',
|
64
|
+
'distinct',
|
65
|
+
'element',
|
66
|
+
'file',
|
67
|
+
'format',
|
68
|
+
'formatlist',
|
69
|
+
'index',
|
70
|
+
'join',
|
71
|
+
'jsonencode',
|
72
|
+
'length',
|
73
|
+
'list',
|
74
|
+
'lower',
|
75
|
+
'map',
|
76
|
+
'md5',
|
77
|
+
'merge',
|
78
|
+
'uuid',
|
79
|
+
'replace',
|
80
|
+
'sha1',
|
81
|
+
'sha256',
|
82
|
+
'signum',
|
83
|
+
'sort',
|
84
|
+
'split',
|
85
|
+
'trimspace',
|
86
|
+
'upper'
|
87
|
+
]
|
88
|
+
|
89
|
+
# NOTE: Alias implementation disabled due to Ruby 2.3 __callee__ bug
|
90
|
+
# see: https://bugs.ruby-lang.org/issues/12176
|
91
|
+
|
92
|
+
# Generate a builtin terraform function
|
93
|
+
#
|
94
|
+
# @return [SparkleFormation::FunctionStruct]
|
95
|
+
def _fn_format(*args)
|
96
|
+
src = ::Kernel.__callee__.to_s
|
97
|
+
src = ::Bogo::Utility.camel(src.sub(/(^_|\!$)/, ''), false)
|
98
|
+
::SparkleFormation::TerraformStruct.new(src, *args)
|
99
|
+
end
|
100
|
+
|
101
|
+
TERRAFORM_INTRINSIC_FUNCTIONS.map do |f_name|
|
102
|
+
::Bogo::Utility.snake(f_name)
|
103
|
+
end.each do |f_name|
|
104
|
+
# alias_method "_#{f_name}".to_sym, :_fn_format
|
105
|
+
# alias_method "#{f_name}!".to_sym, :_fn_format
|
106
|
+
|
107
|
+
define_method("_#{f_name}".to_sym) do |*args|
|
108
|
+
src = ::Kernel.__callee__.to_s
|
109
|
+
src = ::Bogo::Utility.camel(src.sub(/(^_|\!$)/, ''), false)
|
110
|
+
::SparkleFormation::TerraformStruct.new(src, *args)
|
111
|
+
end
|
112
|
+
alias_method "#{f_name}!".to_sym, "_#{f_name}".to_sym
|
113
|
+
end
|
114
|
+
|
115
|
+
def __resource_lookup(name)
|
116
|
+
resource = root!.resources[name]
|
117
|
+
if(resource.nil?)
|
118
|
+
name
|
119
|
+
else
|
120
|
+
"#{resource.type}.#{name}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Resource dependency generator
|
125
|
+
# @overload _depends_on(resource_name)
|
126
|
+
# @param resource_name [String, Symbol] logical resource name
|
127
|
+
# @overload _depends_on(resource_names)
|
128
|
+
# @param resource_names [Array<String, Symbol>] list of logical resource names
|
129
|
+
# @overload _depends_on(*resource_names)
|
130
|
+
# @param resource_names [Array<String, Symbol>] list of logical resource names
|
131
|
+
# @return [Array<String>]
|
132
|
+
# @note this will directly modify the struct at its current context to inject depends on structure
|
133
|
+
def _depends_on(*args)
|
134
|
+
_set('depends_on', [args].flatten.compact.map{|s| __attribute_key(s) })
|
135
|
+
end
|
136
|
+
alias_method :depends_on!, :_depends_on
|
137
|
+
|
138
|
+
# Reference output value from nested stack
|
139
|
+
#
|
140
|
+
# @param stack_name [String, Symbol] logical resource name of stack
|
141
|
+
# @param output_name [String, Symbol] stack output name
|
142
|
+
# @return [Hash]
|
143
|
+
def _stack_output(stack_name, output_name)
|
144
|
+
_module(stack_name)._set(output_name)
|
145
|
+
end
|
146
|
+
alias_method :stack_output!, :_stack_output
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
@@ -10,6 +10,7 @@ class SparkleFormation
|
|
10
10
|
autoload :Google, 'sparkle_formation/sparkle_attribute/google'
|
11
11
|
autoload :Heat, 'sparkle_formation/sparkle_attribute/heat'
|
12
12
|
autoload :Rackspace, 'sparkle_formation/sparkle_attribute/rackspace'
|
13
|
+
autoload :Terraform, 'sparkle_formation/sparkle_attribute/terraform'
|
13
14
|
|
14
15
|
# Return current resource name
|
15
16
|
#
|
@@ -899,7 +899,7 @@ class SparkleFormation
|
|
899
899
|
# @return [Smash<output_name:SparkleFormation>]
|
900
900
|
def collect_outputs(*args)
|
901
901
|
if(args.include?(:force) || root?)
|
902
|
-
|
902
|
+
if(!compile.outputs.nil? && !root?)
|
903
903
|
outputs = Smash[
|
904
904
|
compile.outputs.keys!.zip(
|
905
905
|
[self] * compile.outputs.keys!.size
|
data/lib/sparkle_formation.rb
CHANGED
@@ -1,21 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Chris Roberts <chris@hw-ops.com>
|
3
|
-
# Copyright:: 2013, Heavy Water Operations, LLC
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
1
|
require 'bogo'
|
20
2
|
require 'multi_json'
|
21
3
|
require 'attribute_struct'
|
@@ -36,6 +18,7 @@ class SparkleFormation
|
|
36
18
|
autoload :SparkleCollection, 'sparkle_formation/sparkle_collection'
|
37
19
|
autoload :SparkleAttribute, 'sparkle_formation/sparkle_attribute'
|
38
20
|
autoload :SparkleStruct, 'sparkle_formation/sparkle_struct'
|
21
|
+
autoload :TerraformStruct, 'sparkle_formation/function_struct'
|
39
22
|
autoload :Utils, 'sparkle_formation/utils'
|
40
23
|
autoload :Translation, 'sparkle_formation/translation'
|
41
24
|
autoload :Version, 'sparkle_formation/version'
|
data/sparkle_formation.gemspec
CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.add_runtime_dependency 'multi_json'
|
16
16
|
s.add_runtime_dependency 'bogo'
|
17
17
|
s.add_development_dependency 'minitest'
|
18
|
+
s.add_development_dependency 'rspec', '~> 3.5'
|
18
19
|
s.add_development_dependency 'rake', '~> 10'
|
19
20
|
s.add_development_dependency 'rubocop', '0.38.0'
|
20
21
|
s.add_development_dependency 'yard'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparkle_formation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: attribute_struct
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.5'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.5'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: rake
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -183,6 +197,7 @@ files:
|
|
183
197
|
- lib/sparkle_formation/provider/azure.rb
|
184
198
|
- lib/sparkle_formation/provider/google.rb
|
185
199
|
- lib/sparkle_formation/provider/heat.rb
|
200
|
+
- lib/sparkle_formation/provider/terraform.rb
|
186
201
|
- lib/sparkle_formation/resources.rb
|
187
202
|
- lib/sparkle_formation/resources/aws.rb
|
188
203
|
- lib/sparkle_formation/resources/aws_resources.json
|
@@ -194,6 +209,8 @@ files:
|
|
194
209
|
- lib/sparkle_formation/resources/heat_resources.json
|
195
210
|
- lib/sparkle_formation/resources/rackspace.rb
|
196
211
|
- lib/sparkle_formation/resources/rackspace_resources.json
|
212
|
+
- lib/sparkle_formation/resources/terraform.rb
|
213
|
+
- lib/sparkle_formation/resources/terraform_resources.json
|
197
214
|
- lib/sparkle_formation/sparkle.rb
|
198
215
|
- lib/sparkle_formation/sparkle_attribute.rb
|
199
216
|
- lib/sparkle_formation/sparkle_attribute/aws.rb
|
@@ -201,6 +218,7 @@ files:
|
|
201
218
|
- lib/sparkle_formation/sparkle_attribute/google.rb
|
202
219
|
- lib/sparkle_formation/sparkle_attribute/heat.rb
|
203
220
|
- lib/sparkle_formation/sparkle_attribute/rackspace.rb
|
221
|
+
- lib/sparkle_formation/sparkle_attribute/terraform.rb
|
204
222
|
- lib/sparkle_formation/sparkle_collection.rb
|
205
223
|
- lib/sparkle_formation/sparkle_collection/rainbow.rb
|
206
224
|
- lib/sparkle_formation/sparkle_formation.rb
|
@@ -236,4 +254,3 @@ signing_key:
|
|
236
254
|
specification_version: 4
|
237
255
|
summary: Orchestration Template Generator
|
238
256
|
test_files: []
|
239
|
-
has_rdoc:
|