cloud_shaped 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -6
- data/examples/buckets.rb +24 -0
- data/examples/macro.rb +28 -0
- data/lib/cloud_shaped/core_methods.rb +19 -4
- data/lib/cloud_shaped/template_builder.rb +43 -11
- data/lib/cloud_shaped/version.rb +1 -1
- data/spec/cloud_shaped/core_methods_spec.rb +19 -0
- data/spec/cloud_shaped/template_builder_spec.rb +25 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21a2049dd796e57e57bc9ad49fb45effb6340239
|
4
|
+
data.tar.gz: 8e445136b05818d16ff9d1a78ee61f23097d1a08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76e13fe7b29c92d2fec4986e886f053980a9f204fbaa1b32c74349644e4fe67b8177de4a2284b520066a4038b4aa27ba4a59b2164ccb50e7ed8f9b5d6fe9d151
|
7
|
+
data.tar.gz: 0f992328cba18e1393df16ed5bc00813194162b5d6beefe077ed97e896a1b6523ee0c330a762ca471a1f6b9a51d63cfc6bd4b316e69b2971b8ed1e4a6ef8156f
|
data/README.md
CHANGED
@@ -15,15 +15,49 @@ Add this line to your application's Gemfile:
|
|
15
15
|
## Example
|
16
16
|
|
17
17
|
require 'cloud_shaped'
|
18
|
+
require 'json'
|
18
19
|
|
19
|
-
template = CloudShaped.template do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
t.def_output "appAddress", t.ref("app", "address")
|
20
|
+
template = CloudShaped.template do
|
21
|
+
def_parameter "appName"
|
22
|
+
def_resource "app", "AWS::Appity:AppApp", "Name" => ref("appName")
|
23
|
+
def_output "appAddress", ref("app", "address")
|
25
24
|
end
|
26
25
|
|
26
|
+
puts JSON.pretty_generate(template)
|
27
|
+
|
28
|
+
outputs
|
29
|
+
|
30
|
+
{
|
31
|
+
"AWSTemplateFormatVersion": "2010-09-09",
|
32
|
+
"Parameters": {
|
33
|
+
"appName": {
|
34
|
+
"Type": "String"
|
35
|
+
}
|
36
|
+
},
|
37
|
+
"Resources": {
|
38
|
+
"app": {
|
39
|
+
"Type": "AWS::Appity:AppApp",
|
40
|
+
"Properties": {
|
41
|
+
"Name": {
|
42
|
+
"Ref": "appName"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
},
|
47
|
+
"Outputs": {
|
48
|
+
"appAddress": {
|
49
|
+
"Value": {
|
50
|
+
"Fn::GetAtt": ["app", "address"]
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
For more info on the DSL, see:
|
57
|
+
|
58
|
+
* {CloudShaped.template}
|
59
|
+
* {CloudShaped::TemplateBuilder}
|
60
|
+
|
27
61
|
## Contributing
|
28
62
|
|
29
63
|
It's [on GitHub][cloud_shaped]. Fork it.
|
data/examples/buckets.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'cloud_shaped'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
class BucketMaker
|
7
|
+
|
8
|
+
def initialize(n_buckets = 1)
|
9
|
+
@n_buckets = n_buckets
|
10
|
+
end
|
11
|
+
|
12
|
+
def template
|
13
|
+
CloudShaped.template do |t|
|
14
|
+
1.upto(@n_buckets) do |i|
|
15
|
+
t.def_resource "bucket#{i}", "AWS::S3::Bucket" do |b|
|
16
|
+
b["BucketName"] = "my-bucket-#{i}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
puts YAML.dump(BucketMaker.new(3).template)
|
data/examples/macro.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'cloud_shaped'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module ScalingMacros
|
7
|
+
|
8
|
+
def asg_adjustment(asg_resource_name, adjustment, cooldown = 120)
|
9
|
+
resource("AWS::AutoScaling::ScalingPolicy") do |p|
|
10
|
+
p["AdjustmentType"] = "ChangeInCapacity"
|
11
|
+
p["AutoScalingGroupName"] = ref(asg_resource_name)
|
12
|
+
p["ScalingAdjustment"] = adjustment
|
13
|
+
p["Cooldown"] = cooldown
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
template = CloudShaped.template do
|
20
|
+
|
21
|
+
extend(ScalingMacros)
|
22
|
+
|
23
|
+
def_resource "upOne", :asg_adjustment, "autoScalingGroup", 1
|
24
|
+
def_resource "downOne", :asg_adjustment, "autoScalingGroup", -1
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
puts YAML.dump(template)
|
@@ -30,7 +30,7 @@ module CloudShaped
|
|
30
30
|
|
31
31
|
# Returns a CloudFormation Parameter declaration.
|
32
32
|
#
|
33
|
-
# @option options [String] :type ("String") the
|
33
|
+
# @option options [String] :type ("String") the parameter type
|
34
34
|
# @option options [String] :description parameter description
|
35
35
|
# @option options [String] :default a default value
|
36
36
|
#
|
@@ -56,16 +56,31 @@ module CloudShaped
|
|
56
56
|
|
57
57
|
# Returns a Tag.
|
58
58
|
#
|
59
|
-
# @param
|
59
|
+
# @param key [String] tag name
|
60
60
|
# @param value tag value
|
61
|
+
# @return [Hash] a Tag structure
|
61
62
|
#
|
62
|
-
|
63
|
+
# @example
|
64
|
+
# tag("name", "bob") #=> { "Key" => "name", "Value" => "bob "}
|
65
|
+
#
|
66
|
+
def tag(key, value, extra_properties = {})
|
63
67
|
{
|
64
|
-
"Key" =>
|
68
|
+
"Key" => key,
|
65
69
|
"Value" => value
|
66
70
|
}.merge(extra_properties)
|
67
71
|
end
|
68
72
|
|
73
|
+
# Returns a list of Tags.
|
74
|
+
#
|
75
|
+
# @param tag_map [Hash] mapping of Tag keys to values
|
76
|
+
#
|
77
|
+
# @example
|
78
|
+
# tags("application" => "atlas", "version" => "1.2.3")
|
79
|
+
#
|
80
|
+
def tags(tag_map, extra_properties = {})
|
81
|
+
tag_map.map { |k,v| tag(k,v, extra_properties) }
|
82
|
+
end
|
83
|
+
|
69
84
|
# Returns a resource reference.
|
70
85
|
#
|
71
86
|
# If attribute_name is specified, we use "Fn::GetAtt"; otherwise, we use "Ref".
|
@@ -2,8 +2,7 @@ require 'cloud_shaped/dsl'
|
|
2
2
|
|
3
3
|
module CloudShaped
|
4
4
|
|
5
|
-
# A
|
6
|
-
# in the form of Ruby data.
|
5
|
+
# A {http://en.wikipedia.org/wiki/Builder_pattern builder} for CloudFormation templates.
|
7
6
|
#
|
8
7
|
class TemplateBuilder
|
9
8
|
|
@@ -13,10 +12,8 @@ module CloudShaped
|
|
13
12
|
@outputs = {}
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
attr_reader :outputs
|
19
|
-
|
15
|
+
# @return [Hash] a CloudFormation template as Ruby data
|
16
|
+
#
|
20
17
|
def template
|
21
18
|
{
|
22
19
|
"AWSTemplateFormatVersion" => '2010-09-09',
|
@@ -28,18 +25,53 @@ module CloudShaped
|
|
28
25
|
|
29
26
|
include CloudShaped::DSL
|
30
27
|
|
31
|
-
|
32
|
-
|
28
|
+
# Declares a Parameter.
|
29
|
+
#
|
30
|
+
# @param name [String] the parameter name
|
31
|
+
# @option options [String] :type ("String") the parameter type
|
32
|
+
# @option options [String] :description parameter description
|
33
|
+
# @option options [String] :default a default value
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# def_parameter "appName"
|
37
|
+
# def_parameter "minInstances", :type => "Number"
|
38
|
+
#
|
39
|
+
def def_parameter(name, options = {})
|
40
|
+
parameters[name] = parameter(options)
|
33
41
|
end
|
34
42
|
|
43
|
+
# Declares a Resource.
|
44
|
+
#
|
45
|
+
# @param name [String] the resource name
|
46
|
+
# @param type [String, Symbol] the resource type
|
47
|
+
# @param args [Hash] resource properties
|
48
|
+
#
|
35
49
|
def def_resource(name, type, *args, &block)
|
36
|
-
resources[name] =
|
50
|
+
resources[name] = if type.is_a?(Symbol)
|
51
|
+
send(type, *args, &block)
|
52
|
+
else
|
53
|
+
resource(type, *args, &block)
|
54
|
+
end
|
37
55
|
end
|
38
56
|
|
39
|
-
|
40
|
-
|
57
|
+
# Declares an Output.
|
58
|
+
#
|
59
|
+
# @param name [String] the output name
|
60
|
+
# @param value the output value (usually a reference to a resource)
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# def_output "loadBalancerName", ref("loadBalancer")
|
64
|
+
#
|
65
|
+
def def_output(name, value)
|
66
|
+
outputs[name] = output(value)
|
41
67
|
end
|
42
68
|
|
69
|
+
protected
|
70
|
+
|
71
|
+
attr_reader :parameters
|
72
|
+
attr_reader :resources
|
73
|
+
attr_reader :outputs
|
74
|
+
|
43
75
|
end
|
44
76
|
|
45
77
|
end
|
data/lib/cloud_shaped/version.rb
CHANGED
@@ -109,6 +109,25 @@ describe CloudShaped::CoreMethods do
|
|
109
109
|
|
110
110
|
end
|
111
111
|
|
112
|
+
describe "#tags" do
|
113
|
+
|
114
|
+
it "generates a list of tags" do
|
115
|
+
expect(tags("first" => "foo", "last" => "bar")).to eq(
|
116
|
+
[
|
117
|
+
{
|
118
|
+
"Key" => "first",
|
119
|
+
"Value" => "foo"
|
120
|
+
},
|
121
|
+
{
|
122
|
+
"Key" => "last",
|
123
|
+
"Value" => "bar"
|
124
|
+
}
|
125
|
+
]
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
112
131
|
describe "#ref" do
|
113
132
|
|
114
133
|
context "with a logical resource name" do
|
@@ -25,12 +25,10 @@ describe CloudShaped::TemplateBuilder do
|
|
25
25
|
|
26
26
|
describe "#def_resource" do
|
27
27
|
|
28
|
-
before do
|
29
|
-
template_builder.def_resource("fooBar", "AWS::Foo::Bar", "foo" => "bar")
|
30
|
-
end
|
31
|
-
|
32
28
|
it "defines a Resource" do
|
33
29
|
|
30
|
+
template_builder.def_resource("fooBar", "AWS::Foo::Bar", "foo" => "bar")
|
31
|
+
|
34
32
|
expect(template["Resources"]).to eq(
|
35
33
|
"fooBar" => {
|
36
34
|
"Type" => "AWS::Foo::Bar",
|
@@ -40,6 +38,29 @@ describe CloudShaped::TemplateBuilder do
|
|
40
38
|
|
41
39
|
end
|
42
40
|
|
41
|
+
context "with a symbol as the second argument" do
|
42
|
+
|
43
|
+
before do
|
44
|
+
def template_builder.fnord(size)
|
45
|
+
resource "AWS::Fnord::Fnord", "Size" => size
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "calls the method named by the symbol to define the resource" do
|
50
|
+
|
51
|
+
template_builder.def_resource("fooBar", :fnord, "3")
|
52
|
+
|
53
|
+
expect(template["Resources"]).to eq(
|
54
|
+
"fooBar" => {
|
55
|
+
"Type" => "AWS::Fnord::Fnord",
|
56
|
+
"Properties" => {"Size" => "3"}
|
57
|
+
}
|
58
|
+
)
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
43
64
|
end
|
44
65
|
|
45
66
|
describe "#def_parameter" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_shaped
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,6 +67,8 @@ files:
|
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
69
|
- cloud_shaped.gemspec
|
70
|
+
- examples/buckets.rb
|
71
|
+
- examples/macro.rb
|
70
72
|
- lib/cloud_shaped.rb
|
71
73
|
- lib/cloud_shaped/camelate.rb
|
72
74
|
- lib/cloud_shaped/core_methods.rb
|