cloud_shaped 0.0.2 → 0.1.0
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 +32 -4
- data/lib/cloud_shaped/core_methods.rb +6 -5
- data/lib/cloud_shaped/version.rb +1 -1
- data/spec/cloud_shaped/core_methods_spec.rb +39 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88837a9bfa352037ab2f2129279a0a9d7dab507b
|
4
|
+
data.tar.gz: a9082c94f9587bac9ec9642787dc87ea447b489a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab97c0a3f429b9a65f2ca75e1458a8adc37f1136b3a75085137d9c5f2f86124a6dc335857ff2e0e2dc5d2ff377c3a9cc8a88f8f53f8c7e7355697641b938be8f
|
7
|
+
data.tar.gz: 184e53169c15670cac0ad4e382fbbaeab60be518aa40cded4bda75f7eaa32cd221ae5ad4c26d8e2a958a457f3169c4e3b73770431d26eef4515fb82265e0648d
|
data/README.md
CHANGED
@@ -17,10 +17,10 @@ Add this line to your application's Gemfile:
|
|
17
17
|
require 'cloud_shaped'
|
18
18
|
require 'json'
|
19
19
|
|
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")
|
20
|
+
template = CloudShaped.template do |t|
|
21
|
+
t.def_parameter "appName"
|
22
|
+
t.def_resource "app", "AWS::Appity:AppApp", "Name" => t.ref("appName")
|
23
|
+
t.def_output "appAddress", t.ref("app", "address")
|
24
24
|
end
|
25
25
|
|
26
26
|
puts JSON.pretty_generate(template)
|
@@ -53,6 +53,34 @@ outputs
|
|
53
53
|
}
|
54
54
|
}
|
55
55
|
|
56
|
+
## Declaring resources
|
57
|
+
|
58
|
+
Declare CloudFormation resources using the `def_resource` method. It takes a resource name, type, and properties:
|
59
|
+
|
60
|
+
t.def_resource "adminEmail", "AWS::SNS::Topic",
|
61
|
+
"Subscription" => [{"Protocol" => "email", "Endpoint" => "mdub@example.com"}]
|
62
|
+
|
63
|
+
If you prefer, you can set properties using a block:
|
64
|
+
|
65
|
+
t.def_resource "adminEmail", "AWS::SNS::Topic" do |topic|
|
66
|
+
topic["Subscription"] = [
|
67
|
+
{ "Protocol" => "email", "Endpoint" => "mdub@example.com" }
|
68
|
+
]
|
69
|
+
end
|
70
|
+
|
71
|
+
### Resource macros
|
72
|
+
|
73
|
+
Typically, the "type" argument will be a string specifying a CloudFormation resource type. However, it's also possible to provide a Ruby symbol, in which case `def_resource` will call the named method, passing remaining arguments. This allows common resource patterns to be abstracted as methods:
|
74
|
+
|
75
|
+
def t.email_topic(address)
|
76
|
+
resource "AWS::SNS::Topic",
|
77
|
+
"Subscription" => [{ "Protocol" => "email", "Endpoint" => address }]
|
78
|
+
end
|
79
|
+
|
80
|
+
t.def_resource "adminEmail", :email_topic, "mdub@example.com"
|
81
|
+
|
82
|
+
## Full documentation
|
83
|
+
|
56
84
|
For more info on the DSL, see:
|
57
85
|
|
58
86
|
* {CloudShaped.template}
|
@@ -8,7 +8,7 @@ module CloudShaped
|
|
8
8
|
|
9
9
|
# Returns a CloudFormation Resource declaration.
|
10
10
|
#
|
11
|
-
# Properties can be passed in the call, or defined using an optional block.
|
11
|
+
# Properties and additional resource attributes can be passed in the call, or defined using an optional block.
|
12
12
|
#
|
13
13
|
# @example
|
14
14
|
# resource("AWS::ElasticLoadBalancing::LoadBalancer", "Scheme" => "internal") do |elb|
|
@@ -17,15 +17,16 @@ module CloudShaped
|
|
17
17
|
#
|
18
18
|
# @param type [String] the resource type
|
19
19
|
# @param properties [Hash] resource properties
|
20
|
+
# @param attributes [Hash] additional resource attributes
|
20
21
|
#
|
21
|
-
def resource(type, properties = {})
|
22
|
+
def resource(type, properties = {}, attributes = {})
|
22
23
|
properties = properties.camelate_keys
|
23
|
-
yield properties if block_given?
|
24
|
+
yield properties, attributes if block_given?
|
24
25
|
properties.select! { |k,v| v != nil }
|
25
|
-
|
26
|
+
attributes.merge(
|
26
27
|
"Type" => type,
|
27
28
|
"Properties" => properties
|
28
|
-
|
29
|
+
)
|
29
30
|
end
|
30
31
|
|
31
32
|
# Returns a CloudFormation Parameter declaration.
|
data/lib/cloud_shaped/version.rb
CHANGED
@@ -24,10 +24,13 @@ describe CloudShaped::CoreMethods do
|
|
24
24
|
|
25
25
|
context "with a block" do
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
let(:result) do
|
28
|
+
resource("AWS::Thing", "MinSize" => 1) do |thing|
|
29
29
|
thing["MaxSize"] = 3
|
30
30
|
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "allows properties to be added" do
|
31
34
|
expect(result).to eq(
|
32
35
|
"Type" => "AWS::Thing",
|
33
36
|
"Properties" => { "MinSize" => 1, "MaxSize" => 3 }
|
@@ -36,6 +39,40 @@ describe CloudShaped::CoreMethods do
|
|
36
39
|
|
37
40
|
end
|
38
41
|
|
42
|
+
context "with an attributes hash" do
|
43
|
+
|
44
|
+
let(:result) do
|
45
|
+
resource("AWS::Thing", {}, "DependsOn" => "baz")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "sets additional resource attributes" do
|
49
|
+
expect(result).to eq(
|
50
|
+
"Type" => "AWS::Thing",
|
51
|
+
"Properties" => {},
|
52
|
+
"DependsOn" => "baz"
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with a block that sets attributes" do
|
59
|
+
|
60
|
+
let(:result) do
|
61
|
+
resource("AWS::Thing") do |props, attrs|
|
62
|
+
attrs["DeletionPolicy"] = "Retain"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sets additional resource attributes" do
|
67
|
+
expect(result).to eq(
|
68
|
+
"Type" => "AWS::Thing",
|
69
|
+
"Properties" => {},
|
70
|
+
"DeletionPolicy" => "Retain"
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
39
76
|
end
|
40
77
|
|
41
78
|
describe "#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.1.0
|
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-
|
11
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|