cloudformation-dsl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +29 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +201 -0
- data/README.md +102 -0
- data/Rakefile +1 -0
- data/bin/cfntemplate-to-ruby +345 -0
- data/cloudformation-dsl.gemspec +37 -0
- data/docs/Contributing.md +21 -0
- data/docs/Releasing.md +20 -0
- data/examples/cloudformation-ruby-script.rb +204 -0
- data/examples/maps/map.json +9 -0
- data/examples/maps/map.rb +5 -0
- data/examples/maps/map.yaml +5 -0
- data/examples/maps/more_maps/map1.json +8 -0
- data/examples/maps/more_maps/map2.json +8 -0
- data/examples/maps/more_maps/map3.json +8 -0
- data/examples/maps/table.txt +5 -0
- data/examples/maps/vpc.txt +25 -0
- data/examples/userdata.sh +4 -0
- data/initial_contributions.md +5 -0
- data/lib/cloudformation-dsl.rb +14 -0
- data/lib/cloudformation-dsl/helpers.rb +118 -0
- data/lib/cloudformation-dsl/template.rb +100 -0
- data/lib/cloudformation-dsl/version.rb +19 -0
- metadata +114 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'json'
|
2
|
+
module CloudFormationDSL
|
3
|
+
class Template
|
4
|
+
include CloudFormationDSL::Helpers
|
5
|
+
|
6
|
+
# You can supply:
|
7
|
+
# - filename
|
8
|
+
# - block
|
9
|
+
# The file located at the filename is evaluated
|
10
|
+
# The block will also be evaluated
|
11
|
+
#
|
12
|
+
# If both filename and block are passed, then the filename
|
13
|
+
# is evaluated first before the block is evaluated.
|
14
|
+
def initialize(filename = nil, &block)
|
15
|
+
@template_file = filename
|
16
|
+
@template_block = block
|
17
|
+
@dict = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def aws_region
|
21
|
+
ENV['EC2_REGION'] || ENV['AWS_DEFAULT_REGION'] || 'us-east-1'
|
22
|
+
end
|
23
|
+
|
24
|
+
def evaluated_data
|
25
|
+
# Once evaluated, treat this as immutable. This allows us to lazy eval the template.
|
26
|
+
return @dict unless @dict.empty?
|
27
|
+
|
28
|
+
# See: http://stackoverflow.com/questions/4667158/ruby-instance-eval-a-file-while-maintaining-fileline-in-stacktrace
|
29
|
+
instance_eval(File.read(@template_file), @template_file) if @template_file
|
30
|
+
instance_eval(@template_block) if @template_block
|
31
|
+
return @dict
|
32
|
+
end
|
33
|
+
|
34
|
+
def value(values)
|
35
|
+
@dict.update(values)
|
36
|
+
end
|
37
|
+
|
38
|
+
def default(key, value)
|
39
|
+
@dict[key] ||= value
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_json(*args)
|
43
|
+
evaluated_data.to_json(*args)
|
44
|
+
end
|
45
|
+
|
46
|
+
def print()
|
47
|
+
puts JSON.pretty_generate(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# DSL for major sections
|
52
|
+
def parameter(name, options)
|
53
|
+
default(:Parameters, {})[name] = options
|
54
|
+
end
|
55
|
+
|
56
|
+
def condition(name, options) default(:Conditions, {})[name] = options end
|
57
|
+
|
58
|
+
def resource(name, options) default(:Resources, {})[name] = options end
|
59
|
+
|
60
|
+
def output(name, options) default(:Outputs, {})[name] = options end
|
61
|
+
|
62
|
+
def mapping(name, options)
|
63
|
+
# if options is a string and a valid file then the script will process the external file.
|
64
|
+
default(:Mappings, {})[name] = if options.is_a?(Hash)
|
65
|
+
options
|
66
|
+
elsif options.is_a?(String)
|
67
|
+
load_from_file(options)['Mappings'][name]
|
68
|
+
else
|
69
|
+
raise("Options for mapping #{name} is neither a string or a hash. Error!")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def tag(tag)
|
74
|
+
tag.each do | name, value |
|
75
|
+
default(:Tags, {})[name] = value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Cleanup
|
80
|
+
|
81
|
+
# Find parameters where the specified attribute is true then remove the attribute from the cfn template.
|
82
|
+
def excise_parameter_attribute!(attribute)
|
83
|
+
marked_parameters = []
|
84
|
+
@dict.fetch(:Parameters, {}).each do |param, options|
|
85
|
+
if options.delete(attribute.to_sym) or options.delete(attribute.to_s)
|
86
|
+
marked_parameters << param
|
87
|
+
end
|
88
|
+
end
|
89
|
+
marked_parameters
|
90
|
+
end
|
91
|
+
|
92
|
+
def excise_tags!
|
93
|
+
tags = @dict.fetch(:Tags, {})
|
94
|
+
@dict.delete(:Tags)
|
95
|
+
tags
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2013-2014 Bazaarvoice, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# Streamlined by Ho-Sheng Hsiao <talktohosh@gmail.com>
|
16
|
+
|
17
|
+
module CloudFormationDSL
|
18
|
+
VERSION = "0.1.0"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudformation-dsl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shawn Smith
|
8
|
+
- Dave Barcelo
|
9
|
+
- Morgan Fletcher
|
10
|
+
- Csongor Gyuricza
|
11
|
+
- Igor Polishchuk
|
12
|
+
- Nathaniel Eliot
|
13
|
+
- Jona Fenocchi
|
14
|
+
- Tony Cui
|
15
|
+
- Ho-Sheng Hsiao
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
type: :runtime
|
29
|
+
prerelease: false
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
type: :runtime
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
description: Ruby DSL library that provides a wrapper around the CloudFormation.
|
50
|
+
email:
|
51
|
+
- Shawn.Smith@bazaarvoice.com
|
52
|
+
- Dave.Barcelo@bazaarvoice.com
|
53
|
+
- Morgan.Fletcher@bazaarvoice.com
|
54
|
+
- Csongor.Gyuricza@bazaarvoice.com
|
55
|
+
- Igor.Polishchuk@bazaarvoice.com
|
56
|
+
- Nathaniel.Eliot@bazaarvoice.com
|
57
|
+
- Jona.Fenocchi@bazaarvoice.com
|
58
|
+
- Tony.Cui@bazaarvoice.com
|
59
|
+
- talktohosh@gmail.com
|
60
|
+
executables:
|
61
|
+
- cfntemplate-to-ruby
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/cfntemplate-to-ruby
|
71
|
+
- cloudformation-dsl.gemspec
|
72
|
+
- docs/Contributing.md
|
73
|
+
- docs/Releasing.md
|
74
|
+
- examples/cloudformation-ruby-script.rb
|
75
|
+
- examples/maps/map.json
|
76
|
+
- examples/maps/map.rb
|
77
|
+
- examples/maps/map.yaml
|
78
|
+
- examples/maps/more_maps/map1.json
|
79
|
+
- examples/maps/more_maps/map2.json
|
80
|
+
- examples/maps/more_maps/map3.json
|
81
|
+
- examples/maps/table.txt
|
82
|
+
- examples/maps/vpc.txt
|
83
|
+
- examples/userdata.sh
|
84
|
+
- initial_contributions.md
|
85
|
+
- lib/cloudformation-dsl.rb
|
86
|
+
- lib/cloudformation-dsl/helpers.rb
|
87
|
+
- lib/cloudformation-dsl/template.rb
|
88
|
+
- lib/cloudformation-dsl/version.rb
|
89
|
+
homepage: http://github.com/hosh/cloudformation-dsl-rb
|
90
|
+
licenses: []
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
- bin
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Ruby DSL library that provides a wrapper around the CloudFormation. Written
|
113
|
+
by [Bazaarvoice](http://www.bazaarvoice.com).
|
114
|
+
test_files: []
|