convection 0.2.32 → 0.2.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +1 -2
- data/Gemfile +2 -1
- data/Rakefile +3 -7
- data/lib/convection.rb +2 -2
- data/lib/convection/control/stack.rb +49 -10
- data/lib/convection/model/event.rb +3 -2
- data/lib/convection/model/template.rb +13 -1
- data/lib/convection/model/template/metadata.rb +22 -0
- data/lib/convection/model/template/resource/aws_ec2_subnet.rb +1 -0
- data/lib/convection/model/template/resource/aws_events_rule.rb +4 -0
- data/spec/cf_client_context.rb +10 -0
- data/spec/collect_availability_zones_task_context.rb +17 -0
- data/spec/convection/control/stack/after_create_tasks_spec.rb +51 -0
- data/spec/convection/control/stack/after_delete_tasks_spec.rb +51 -0
- data/spec/convection/control/stack/after_update_tasks_spec.rb +54 -0
- data/spec/convection/control/stack/before_create_tasks_spec.rb +52 -0
- data/spec/convection/control/stack/before_delete_tasks_spec.rb +51 -0
- data/spec/convection/control/stack/before_update_tasks_spec.rb +55 -0
- data/spec/convection/dsl/intrinsic_functions_spec.rb +88 -0
- data/spec/convection/model/template/condition_spec.rb +38 -0
- data/spec/convection/model/template/resource/directoryservice_simple_ad_spec.rb +39 -0
- data/spec/convection/model/template/resource/ec2_security_group_spec.rb +39 -0
- data/spec/convection/model/template/resource/ec2_subnet_spec.rb +48 -0
- data/spec/convection/model/template/resource/elasticache_cache_cluster_spec.rb +52 -0
- data/spec/convection/model/template/resource/elasticache_parameter_group_spec.rb +38 -0
- data/spec/convection/model/template/resource/elasticache_security_group_ingress_spec.rb +40 -0
- data/spec/convection/model/template/resource/elasticache_security_group_spec.rb +32 -0
- data/spec/convection/model/template/resource/events_rule_spec.rb +44 -0
- data/spec/convection/model/template/resource/iam_role_spec.rb +37 -0
- data/spec/convection/model/template/resource/lambdas_spec.rb +70 -0
- data/spec/convection/model/template/resource/loggroups_spec.rb +34 -0
- data/spec/convection/model/template/resource/permission_spec.rb +43 -0
- data/spec/convection/model/template/resource/rds_security_groups_spec.rb +50 -0
- data/spec/convection/model/template/resource/vpc_endpoints_spec.rb +65 -0
- data/spec/convection/model/template/resource_attribute/update_policies_spec.rb +66 -0
- data/spec/convection/model/template/template_spec.rb +60 -0
- data/spec/convection/model/template/validate_bytesize_spec.rb +49 -0
- data/spec/convection/model/template/validate_description_spec.rb +31 -0
- data/spec/convection/model/template/validate_mappings_spec.rb +88 -0
- data/spec/convection/model/template/validate_outputs_spec.rb +62 -0
- data/spec/convection/model/template/validate_parameters_spec.rb +84 -0
- data/spec/convection/model/template/validate_resources_spec.rb +50 -0
- data/spec/ec2_client_context.rb +18 -0
- data/spec/spec_helper.rb +11 -0
- metadata +72 -40
- data/test/convection/model/test_conditions.rb +0 -121
- data/test/convection/model/test_directory_service.rb +0 -40
- data/test/convection/model/test_elasticache.rb +0 -97
- data/test/convection/model/test_lambdas.rb +0 -53
- data/test/convection/model/test_loggroups.rb +0 -25
- data/test/convection/model/test_permission.rb +0 -31
- data/test/convection/model/test_rds.rb +0 -76
- data/test/convection/model/test_template.rb +0 -64
- data/test/convection/model/test_trust.rb +0 -28
- data/test/convection/model/test_update_policies.rb +0 -54
- data/test/convection/model/test_validation.rb +0 -216
- data/test/convection/model/test_vpc_endpoint.rb +0 -51
- data/test/convection/tasks/test_after_create_tasks.rb +0 -66
- data/test/convection/tasks/test_after_delete_tasks.rb +0 -66
- data/test/convection/tasks/test_after_update_tasks.rb +0 -71
- data/test/convection/tasks/test_before_create_tasks.rb +0 -66
- data/test/convection/tasks/test_before_delete_tasks.rb +0 -66
- data/test/convection/tasks/test_before_update_tasks.rb +0 -71
- data/test/test_helper.rb +0 -72
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Convection::Model::Template
|
4
|
+
describe '#validate_resources' do
|
5
|
+
context 'with regular Resource name' do
|
6
|
+
subject do
|
7
|
+
Convection.template do
|
8
|
+
description 'Validations Test Template - Regular Resource Name'
|
9
|
+
|
10
|
+
resource 'Resource0'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'raises an excessive resource name error' do
|
15
|
+
rendered = subject.render
|
16
|
+
expect { subject.validate(rendered) }.to_not raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with excessive Resource name' do
|
21
|
+
subject do
|
22
|
+
Convection.template do
|
23
|
+
description 'Validations Test Template - Excessive Resource Name'
|
24
|
+
|
25
|
+
resource '0' * (CF_MAX_RESOURCE_NAME + 1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'raises an excessive resource name error' do
|
30
|
+
rendered = subject.render
|
31
|
+
expect { subject.validate(rendered) }.to raise_error(ExcessiveResourceNameError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with excessive Resources' do
|
36
|
+
subject do
|
37
|
+
Convection.template do
|
38
|
+
description 'Validations Test Template - Too Many Resources'
|
39
|
+
|
40
|
+
(CF_MAX_RESOURCES + 1).times { |i| resource "TestResource#{i}" }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'raises an excessive resources error' do
|
45
|
+
rendered = subject.render
|
46
|
+
expect { subject.validate(rendered) }.to raise_error(ExcessiveResourcesError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec.shared_context 'with a mock EC2 client' do
|
2
|
+
let(:ec2_availability_zone_description) do
|
3
|
+
zones = %w(eu-central-1 eu-west-1).map do |name|
|
4
|
+
double("availability zone (#{name})", zone_name: name)
|
5
|
+
end
|
6
|
+
|
7
|
+
double(:availability_zone_description, availability_zones: zones)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:ec2_client) do
|
11
|
+
client = double(:ec2_client, describe_availability_zones: ec2_availability_zone_description)
|
12
|
+
allow(client).to receive(:describe_stacks) {
|
13
|
+
fail Aws::CloudFormation::Errors::ValidationError.new(context, 'Stack does not exist.')
|
14
|
+
}
|
15
|
+
|
16
|
+
client
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_group 'Control', 'lib/convection/control'
|
4
|
+
add_group 'Model', 'lib/convection/model'
|
5
|
+
add_group 'DSL', 'lib/convection/dsl'
|
6
|
+
end
|
7
|
+
|
8
|
+
require_relative '../lib/convection'
|
9
|
+
require_relative './cf_client_context'
|
10
|
+
require_relative './collect_availability_zones_task_context'
|
11
|
+
require_relative './ec2_client_context'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Manero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/convection/model/template.rb
|
127
127
|
- lib/convection/model/template/condition.rb
|
128
128
|
- lib/convection/model/template/mapping.rb
|
129
|
+
- lib/convection/model/template/metadata.rb
|
129
130
|
- lib/convection/model/template/output.rb
|
130
131
|
- lib/convection/model/template/parameter.rb
|
131
132
|
- lib/convection/model/template/resource.rb
|
@@ -220,25 +221,40 @@ files:
|
|
220
221
|
- lib/convection/model/template/resource_property/aws_s3_cors_configuration.rb
|
221
222
|
- lib/convection/model/template/resource_property/aws_s3_cors_configuration_rule.rb
|
222
223
|
- lib/convection/version.rb
|
223
|
-
-
|
224
|
-
-
|
225
|
-
-
|
226
|
-
-
|
227
|
-
-
|
228
|
-
-
|
229
|
-
-
|
230
|
-
-
|
231
|
-
-
|
232
|
-
-
|
233
|
-
-
|
234
|
-
-
|
235
|
-
-
|
236
|
-
-
|
237
|
-
-
|
238
|
-
-
|
239
|
-
-
|
240
|
-
-
|
241
|
-
-
|
224
|
+
- spec/cf_client_context.rb
|
225
|
+
- spec/collect_availability_zones_task_context.rb
|
226
|
+
- spec/convection/control/stack/after_create_tasks_spec.rb
|
227
|
+
- spec/convection/control/stack/after_delete_tasks_spec.rb
|
228
|
+
- spec/convection/control/stack/after_update_tasks_spec.rb
|
229
|
+
- spec/convection/control/stack/before_create_tasks_spec.rb
|
230
|
+
- spec/convection/control/stack/before_delete_tasks_spec.rb
|
231
|
+
- spec/convection/control/stack/before_update_tasks_spec.rb
|
232
|
+
- spec/convection/dsl/intrinsic_functions_spec.rb
|
233
|
+
- spec/convection/model/template/condition_spec.rb
|
234
|
+
- spec/convection/model/template/resource/directoryservice_simple_ad_spec.rb
|
235
|
+
- spec/convection/model/template/resource/ec2_security_group_spec.rb
|
236
|
+
- spec/convection/model/template/resource/ec2_subnet_spec.rb
|
237
|
+
- spec/convection/model/template/resource/elasticache_cache_cluster_spec.rb
|
238
|
+
- spec/convection/model/template/resource/elasticache_parameter_group_spec.rb
|
239
|
+
- spec/convection/model/template/resource/elasticache_security_group_ingress_spec.rb
|
240
|
+
- spec/convection/model/template/resource/elasticache_security_group_spec.rb
|
241
|
+
- spec/convection/model/template/resource/events_rule_spec.rb
|
242
|
+
- spec/convection/model/template/resource/iam_role_spec.rb
|
243
|
+
- spec/convection/model/template/resource/lambdas_spec.rb
|
244
|
+
- spec/convection/model/template/resource/loggroups_spec.rb
|
245
|
+
- spec/convection/model/template/resource/permission_spec.rb
|
246
|
+
- spec/convection/model/template/resource/rds_security_groups_spec.rb
|
247
|
+
- spec/convection/model/template/resource/vpc_endpoints_spec.rb
|
248
|
+
- spec/convection/model/template/resource_attribute/update_policies_spec.rb
|
249
|
+
- spec/convection/model/template/template_spec.rb
|
250
|
+
- spec/convection/model/template/validate_bytesize_spec.rb
|
251
|
+
- spec/convection/model/template/validate_description_spec.rb
|
252
|
+
- spec/convection/model/template/validate_mappings_spec.rb
|
253
|
+
- spec/convection/model/template/validate_outputs_spec.rb
|
254
|
+
- spec/convection/model/template/validate_parameters_spec.rb
|
255
|
+
- spec/convection/model/template/validate_resources_spec.rb
|
256
|
+
- spec/ec2_client_context.rb
|
257
|
+
- spec/spec_helper.rb
|
242
258
|
homepage: https://github.com/rapid7/convection
|
243
259
|
licenses:
|
244
260
|
- MIT
|
@@ -264,22 +280,38 @@ signing_key:
|
|
264
280
|
specification_version: 4
|
265
281
|
summary: A fully generic, modular DSL for AWS CloudFormation
|
266
282
|
test_files:
|
267
|
-
-
|
268
|
-
-
|
269
|
-
-
|
270
|
-
-
|
271
|
-
-
|
272
|
-
-
|
273
|
-
-
|
274
|
-
-
|
275
|
-
-
|
276
|
-
-
|
277
|
-
-
|
278
|
-
-
|
279
|
-
-
|
280
|
-
-
|
281
|
-
-
|
282
|
-
-
|
283
|
-
-
|
284
|
-
-
|
285
|
-
-
|
283
|
+
- spec/cf_client_context.rb
|
284
|
+
- spec/collect_availability_zones_task_context.rb
|
285
|
+
- spec/convection/control/stack/after_create_tasks_spec.rb
|
286
|
+
- spec/convection/control/stack/after_delete_tasks_spec.rb
|
287
|
+
- spec/convection/control/stack/after_update_tasks_spec.rb
|
288
|
+
- spec/convection/control/stack/before_create_tasks_spec.rb
|
289
|
+
- spec/convection/control/stack/before_delete_tasks_spec.rb
|
290
|
+
- spec/convection/control/stack/before_update_tasks_spec.rb
|
291
|
+
- spec/convection/dsl/intrinsic_functions_spec.rb
|
292
|
+
- spec/convection/model/template/condition_spec.rb
|
293
|
+
- spec/convection/model/template/resource/directoryservice_simple_ad_spec.rb
|
294
|
+
- spec/convection/model/template/resource/ec2_security_group_spec.rb
|
295
|
+
- spec/convection/model/template/resource/ec2_subnet_spec.rb
|
296
|
+
- spec/convection/model/template/resource/elasticache_cache_cluster_spec.rb
|
297
|
+
- spec/convection/model/template/resource/elasticache_parameter_group_spec.rb
|
298
|
+
- spec/convection/model/template/resource/elasticache_security_group_ingress_spec.rb
|
299
|
+
- spec/convection/model/template/resource/elasticache_security_group_spec.rb
|
300
|
+
- spec/convection/model/template/resource/events_rule_spec.rb
|
301
|
+
- spec/convection/model/template/resource/iam_role_spec.rb
|
302
|
+
- spec/convection/model/template/resource/lambdas_spec.rb
|
303
|
+
- spec/convection/model/template/resource/loggroups_spec.rb
|
304
|
+
- spec/convection/model/template/resource/permission_spec.rb
|
305
|
+
- spec/convection/model/template/resource/rds_security_groups_spec.rb
|
306
|
+
- spec/convection/model/template/resource/vpc_endpoints_spec.rb
|
307
|
+
- spec/convection/model/template/resource_attribute/update_policies_spec.rb
|
308
|
+
- spec/convection/model/template/template_spec.rb
|
309
|
+
- spec/convection/model/template/validate_bytesize_spec.rb
|
310
|
+
- spec/convection/model/template/validate_description_spec.rb
|
311
|
+
- spec/convection/model/template/validate_mappings_spec.rb
|
312
|
+
- spec/convection/model/template/validate_outputs_spec.rb
|
313
|
+
- spec/convection/model/template/validate_parameters_spec.rb
|
314
|
+
- spec/convection/model/template/validate_resources_spec.rb
|
315
|
+
- spec/ec2_client_context.rb
|
316
|
+
- spec/spec_helper.rb
|
317
|
+
has_rdoc:
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'json'
|
3
|
-
require 'pp'
|
4
|
-
|
5
|
-
class TestConditions < Minitest::Test
|
6
|
-
def setup
|
7
|
-
# Inspired by http://www.unixdaemon.net/cloud/intro-to-cloudformations-conditionals.html
|
8
|
-
@template = ::Convection.template do
|
9
|
-
description 'Conditions Test Template'
|
10
|
-
|
11
|
-
parameter 'DeploymentEnvironment' do
|
12
|
-
type 'String'
|
13
|
-
description 'The environment this stack is being deployed to.'
|
14
|
-
default 'dev'
|
15
|
-
|
16
|
-
allow 'dev'
|
17
|
-
allow 'stage'
|
18
|
-
allow 'prod'
|
19
|
-
end
|
20
|
-
|
21
|
-
condition 'InProd' do
|
22
|
-
fn_equals(fn_ref('DeploymentEnvironment'), 'prod')
|
23
|
-
end
|
24
|
-
|
25
|
-
condition 'NotInProd' do
|
26
|
-
fn_or(
|
27
|
-
fn_equals(fn_ref('DeploymentEnvironment'), 'stage'),
|
28
|
-
fn_equals(fn_ref('DeploymentEnvironment'), 'dev')
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
resource 'SomeSG' do
|
33
|
-
type 'AWS::EC2::SecurityGroup'
|
34
|
-
condition 'NotInProd'
|
35
|
-
end
|
36
|
-
|
37
|
-
resource 'SQLDB' do
|
38
|
-
type 'AWS::RDS::DBInstance'
|
39
|
-
property 'Iops', fn_if('InProd', '1000', fn_ref('AWS::NoValue'))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def from_json
|
45
|
-
JSON.parse(@template.to_json)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_inprod_condition
|
49
|
-
# Expected JSON:
|
50
|
-
# "InProd": { "Fn::Equals" : [ { "Ref" : "DeploymentEnvironment" }, "prod" ] },
|
51
|
-
json = from_json['Conditions']['InProd']
|
52
|
-
func_args = json['Fn::Equals']
|
53
|
-
|
54
|
-
assert func_args.is_a? Array
|
55
|
-
assert_equal 2, func_args.size
|
56
|
-
|
57
|
-
perform_parameter_ref_comparison func_args, 'DeploymentEnvironment', 'prod'
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_notinprod_condition
|
61
|
-
# Expected JSON:
|
62
|
-
# "NotInProd": {
|
63
|
-
# "Fn::Or" : [
|
64
|
-
# { "Fn::Equals" : [ { "Ref" : "DeploymentEnvironment"}, "stage" ] },
|
65
|
-
# { "Fn::Equals" : [ { "Ref" : "DeploymentEnvironment"}, "dev" ] }
|
66
|
-
# ]
|
67
|
-
# }
|
68
|
-
json = from_json['Conditions']['NotInProd']
|
69
|
-
func_args = json['Fn::Or']
|
70
|
-
|
71
|
-
assert func_args.is_a? Array
|
72
|
-
assert_equal 2, func_args.size
|
73
|
-
|
74
|
-
subfunc1 = func_args[0]['Fn::Equals'] # check for 'stage'
|
75
|
-
subfunc2 = func_args[1]['Fn::Equals'] # check for 'dev'
|
76
|
-
|
77
|
-
perform_parameter_ref_comparison subfunc1, 'DeploymentEnvironment', 'stage'
|
78
|
-
perform_parameter_ref_comparison subfunc2, 'DeploymentEnvironment', 'dev'
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_resource_uses_condition
|
82
|
-
json = from_json['Resources']['SomeSG']
|
83
|
-
|
84
|
-
assert json.is_a? Hash
|
85
|
-
assert json.key? 'Condition'
|
86
|
-
assert_equal 'NotInProd', json['Condition']
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_property_uses_condition
|
90
|
-
iops_property = from_json['Resources']['SQLDB']['Properties']['Iops']
|
91
|
-
# Expected JSON:
|
92
|
-
# "Iops" : { "Fn::If" : [ "InProd", "1000", { "Ref" : "AWS::NoValue" }
|
93
|
-
|
94
|
-
# Check we have an IF function
|
95
|
-
assert iops_property.is_a? Hash
|
96
|
-
assert_equal 1, iops_property.size
|
97
|
-
assert iops_property.key? 'Fn::If'
|
98
|
-
|
99
|
-
# Check the 3 arguments to the IF function: (condition, true_value, false_value)
|
100
|
-
if_cond = iops_property['Fn::If']
|
101
|
-
assert if_cond.is_a? Array
|
102
|
-
assert_equal 3, if_cond.size
|
103
|
-
|
104
|
-
assert_equal 'InProd', if_cond[0]
|
105
|
-
assert_equal '1000', if_cond[1]
|
106
|
-
assert if_cond[2].is_a? Hash
|
107
|
-
assert_equal 'AWS::NoValue', if_cond[2]['Ref']
|
108
|
-
end
|
109
|
-
|
110
|
-
private
|
111
|
-
|
112
|
-
def perform_parameter_ref_comparison(comparison_array, parameter_name, expected_value)
|
113
|
-
parameter_ref = comparison_array[0]
|
114
|
-
assert parameter_ref.is_a? Hash
|
115
|
-
assert_equal 1, parameter_ref.size
|
116
|
-
assert parameter_ref.key? 'Ref'
|
117
|
-
assert parameter_ref.value? parameter_name
|
118
|
-
|
119
|
-
assert_equal expected_value, comparison_array[1]
|
120
|
-
end
|
121
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
describe 'AWS::DirectoryService' do
|
5
|
-
let(:simple_ad_template) do
|
6
|
-
::Convection.template do
|
7
|
-
directoryservice_simple_ad 'SimpleActiveDirectory' do
|
8
|
-
description 'Example simple AD'
|
9
|
-
enable_sso false
|
10
|
-
name 'ExampleSimpleAD'
|
11
|
-
password 'directory.password'
|
12
|
-
short_name 'directory.name'
|
13
|
-
size 'Small'
|
14
|
-
|
15
|
-
vpc_settings 'SubnetIds', ['subnet-deadb33f']
|
16
|
-
vpc_settings 'VpcId', 'vpc-deadb33f'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'SimpleAD' do
|
22
|
-
it 'sets VpcSettings.SubnetIds' do
|
23
|
-
vpc_settings = simple_ad_json.fetch('Properties').fetch('VpcSettings')
|
24
|
-
assert_equal vpc_settings.fetch('SubnetIds'), ['subnet-deadb33f']
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'sets VpcSettings.VpcId' do
|
28
|
-
vpc_settings = simple_ad_json.fetch('Properties').fetch('VpcSettings')
|
29
|
-
assert_equal vpc_settings.fetch('VpcId'), 'vpc-deadb33f'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def simple_ad_json
|
36
|
-
JSON.parse(simple_ad_template.to_json)
|
37
|
-
.fetch('Resources')
|
38
|
-
.fetch('SimpleActiveDirectory')
|
39
|
-
end
|
40
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'json'
|
3
|
-
require 'pp'
|
4
|
-
|
5
|
-
class TestElasticache < Minitest::Test
|
6
|
-
def setup
|
7
|
-
# Inspired by http://www.unixdaemon.net/cloud/intro-to-cloudformations-conditionals.html
|
8
|
-
@template = ::Convection.template do
|
9
|
-
description 'Elasticache Test Template'
|
10
|
-
|
11
|
-
ec2_security_group 'MyEC2SecGroup' do
|
12
|
-
ingress_rule(:tcp, 22, 'my.ip.address')
|
13
|
-
end
|
14
|
-
|
15
|
-
elasticache_security_group 'MyRedisSecGroup' do
|
16
|
-
description 'Redis cache security group'
|
17
|
-
end
|
18
|
-
|
19
|
-
elasticache_security_group_ingress 'MyRedisSecGroupIngress' do
|
20
|
-
cache_security_group_name fn_ref('MyRedisSecGroup')
|
21
|
-
ec2_security_group_name(fn_ref('MyEC2SecGroup'))
|
22
|
-
ec2_security_group_owner_id('123456789012')
|
23
|
-
end
|
24
|
-
|
25
|
-
elasticache_parameter_group 'MyRedisParmGroup' do
|
26
|
-
cache_parameter_group_family 'redis2.8'
|
27
|
-
description 'Redis cache parameter group'
|
28
|
-
parameter 'my_parm_key', 'my_parm_value'
|
29
|
-
end
|
30
|
-
|
31
|
-
elasticache_cache_cluster 'MyRedisCluster' do
|
32
|
-
cluster_name 'demo'
|
33
|
-
|
34
|
-
auto_minor_version_upgrade true
|
35
|
-
cache_node_type 'cache.m3.medium'
|
36
|
-
cache_parameter_group_name fn_ref('MyRedisParmGroup')
|
37
|
-
cache_security_group_names [fn_ref('MyRedisSecGroup')]
|
38
|
-
engine 'redis'
|
39
|
-
engine_version '2.8.6'
|
40
|
-
num_cache_nodes 1
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def from_json
|
46
|
-
JSON.parse(@template.to_json)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_elasticache_instance
|
50
|
-
json = from_json['Resources']['MyRedisCluster']
|
51
|
-
secgroups = json['Properties']['CacheSecurityGroupNames']
|
52
|
-
|
53
|
-
assert secgroups.is_a? Array
|
54
|
-
assert_equal 1, secgroups.size
|
55
|
-
|
56
|
-
perform_parameter_ref_comparison secgroups, 'MyRedisSecGroup', nil
|
57
|
-
end
|
58
|
-
|
59
|
-
# XXX Which method is correct implementation? @aburke
|
60
|
-
# def test_elasticache_secgroup_ingress
|
61
|
-
# json = from_json['Resources']['MyRedisSecGroupIngress']
|
62
|
-
# cachesecgroup = json['Properties']['CacheSecurityGroupName']
|
63
|
-
#
|
64
|
-
# assert cachesecgroup.is_a? Hash
|
65
|
-
# assert_equal 1, cachesecgroup.size
|
66
|
-
# assert cachesecgroup.key? 'Ref'
|
67
|
-
# assert cachesecgroup.value? 'MyRedisSecGroup'
|
68
|
-
#
|
69
|
-
# ec2_secgroup = json['Properties']['EC2SecurityGroupName']
|
70
|
-
# assert ec2_secgroup.is_a? Hash
|
71
|
-
# assert_equal 1, ec2_secgroup.size
|
72
|
-
# assert ec2_secgroup.key? 'Ref'
|
73
|
-
# assert ec2_secgroup.value? 'MyEC2SecGroup'
|
74
|
-
# end
|
75
|
-
|
76
|
-
def test_elasticache_secgroup_ingress
|
77
|
-
json = from_json['Resources']['MyRedisParmGroup']
|
78
|
-
parms = json['Properties']['Properties']
|
79
|
-
|
80
|
-
assert parms.is_a? Hash
|
81
|
-
assert_equal 1, parms.size
|
82
|
-
assert parms.key? 'my_parm_key'
|
83
|
-
assert parms.value? 'my_parm_value'
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def perform_parameter_ref_comparison(comparison_array, parameter_name, expected_value)
|
89
|
-
parameter_ref = comparison_array[0]
|
90
|
-
assert parameter_ref.is_a? Hash
|
91
|
-
assert_equal 1, parameter_ref.size
|
92
|
-
assert parameter_ref.key? 'Ref'
|
93
|
-
assert parameter_ref.value? parameter_name
|
94
|
-
|
95
|
-
assert_equal expected_value, comparison_array[1]
|
96
|
-
end
|
97
|
-
end
|