kumogata-template 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '08cd537236edb177fd1201221693623a58998108'
4
- data.tar.gz: 3c1e901ed5171b9d288f56583614f48547c1f43e
3
+ metadata.gz: e3ef42d67f39067721ba98afb39d9392c2d0551e
4
+ data.tar.gz: 2b67f7e99a815830cded5cf6ae4cb5d295bfb9da
5
5
  SHA512:
6
- metadata.gz: 76c880806ec9deced00fdf572ce244cd476d8050b746f05a744b60510cba54c80ef97b2d99db7dfe370043f7f94669e56fd552560e39b83b9ed8816d42e9d579
7
- data.tar.gz: ef155df939575cbb86246bb57819eeada6302df841f578b4f415034cfb9312c5e328a61e27812dd44d176c275faf6c0a491c94fbfdf618458feb8874a4606656
6
+ metadata.gz: 5cfcba9ce73284c4ca4de89ef518e136f165f64e8e42145c7bdfb850860a290205e2ce652023bcb0a593b6ccef6925b371608efca172b415fba7a47901a08681
7
+ data.tar.gz: 11bfdc2ace307e23e6c71e93e1bad0dfdcca46c9e5324f3ad75a334712a12bc3f19df6b93acb521212ef01644e783edb2ec94cdf724157e74e9824797569d5f3
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kumogata-template (0.0.16)
4
+ kumogata-template (0.0.17)
5
5
  aws-sdk (~> 2.3)
6
6
  kumogata (= 0.5.12)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- aws-sdk (2.7.7)
12
- aws-sdk-resources (= 2.7.7)
13
- aws-sdk-core (2.7.7)
11
+ aws-sdk (2.7.10)
12
+ aws-sdk-resources (= 2.7.10)
13
+ aws-sdk-core (2.7.10)
14
14
  aws-sigv4 (~> 1.0)
15
15
  jmespath (~> 1.0)
16
- aws-sdk-resources (2.7.7)
17
- aws-sdk-core (= 2.7.7)
16
+ aws-sdk-resources (2.7.10)
17
+ aws-sdk-core (= 2.7.10)
18
18
  aws-sdk-v1 (1.66.0)
19
19
  json (~> 1.4)
20
20
  nokogiri (>= 1.4.4)
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Helper - CloudWatch
3
3
  #
4
+ require 'kumogata/template/helper'
4
5
 
5
6
  def _cloudwatch_to_period(value)
6
7
  return value if value.nil?
@@ -40,8 +41,124 @@ def _cloudwatch_to_statistic(value)
40
41
  end
41
42
  end
42
43
 
43
- def _cloudwatch_convert_operator(operator)
44
- case operator
44
+ def _cloudwatch_to_metric(value)
45
+ prefix = $1 if value =~ /^(\w+) /
46
+ # http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CW_Support_For_AWS.html
47
+ case prefix
48
+ when "ec2", "ec2 spot", "ecs", "eb", "ebs", "efs", "elb", "alb", "emr", "es",
49
+ "transcoder", "iot",
50
+ "kinesis firehose", "firehose", "kinesis", "kms",
51
+ "lambda", "ml",
52
+ "ops works", "ow",
53
+ "polly",
54
+ "redshift",
55
+ "rds", "route53",
56
+ "ses", "sns", "sqs", "s3", "swf", "storage", "storage gateway",
57
+ "waf", "work spaces", "ws"
58
+ value.slice!(/^#{prefix} /)
59
+ value = value.split(" ").collect! do |v|
60
+ case v
61
+ when "cpu", "iops"
62
+ v.upcase
63
+ else
64
+ v.capitalize
65
+ end
66
+ end.join("")
67
+ end
68
+ value
69
+ end
70
+
71
+ def _cloudwatch_to_namespace(value)
72
+ return value if value.include? "/"
73
+ # http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-namespaces.html
74
+ value =
75
+ case value
76
+ when "api gateway"
77
+ "ApiGateway"
78
+ when "auto scaling"
79
+ "AutoScaling"
80
+ when "billing"
81
+ "Billing"
82
+ when "cloud front"
83
+ "CloudFront"
84
+ when "cloud search"
85
+ "CloudSearch"
86
+ when "cloudwatch events"
87
+ "Events"
88
+ when "cloudwatch logs"
89
+ "Logs"
90
+ when "dynamodb", "dynamod db"
91
+ "DynamoDB"
92
+ when "ec2"
93
+ "EC2"
94
+ when "ec2 spot"
95
+ "EC2Spot"
96
+ when "ecs"
97
+ "ECS"
98
+ when "eb"
99
+ "ElasticBeanstalk"
100
+ when "ebs"
101
+ "EBS"
102
+ when "efs"
103
+ "EFS"
104
+ when "elb"
105
+ "ELB"
106
+ when "alb"
107
+ "ApplicationELB"
108
+ when "transcoder"
109
+ "ElasticTranscoder"
110
+ when "elasti cache", "cache"
111
+ "ElastiCache"
112
+ when "es"
113
+ "ES"
114
+ when "emr"
115
+ "ElasticMapReduce"
116
+ when "iot"
117
+ "IoT"
118
+ when "kms"
119
+ "KMS"
120
+ when "kinesis analytics"
121
+ "KinesisAnalytics"
122
+ when "kinesis firehose", "firehose"
123
+ "Firehose"
124
+ when "kinesis"
125
+ "Kinesis"
126
+ when "lambda"
127
+ "Lambda"
128
+ when "ml"
129
+ "ML"
130
+ when "ops works", "ow"
131
+ "OpsWorks"
132
+ when "polly"
133
+ "Polly"
134
+ when "redshift"
135
+ "Redshift"
136
+ when "rds"
137
+ "RDS"
138
+ when "route53"
139
+ "Route53"
140
+ when "ses"
141
+ "SES"
142
+ when "sns"
143
+ "SNS"
144
+ when "sqs"
145
+ "SQS"
146
+ when "s3"
147
+ "S3"
148
+ when "swf"
149
+ "SWF"
150
+ when "storage", "storage gateway"
151
+ "StorageGateway"
152
+ when "waf"
153
+ "WAF"
154
+ when "work spaces", "ws"
155
+ "WorkSpaces"
156
+ end
157
+ "AWS/#{value}"
158
+ end
159
+
160
+ def _cloudwatch_to_operator(value)
161
+ case value
45
162
  when ">="
46
163
  "GreaterThanOrEqualToThreshold"
47
164
  when ">"
@@ -51,16 +168,109 @@ def _cloudwatch_convert_operator(operator)
51
168
  when "<"
52
169
  "LessThanThreshold"
53
170
  else
54
- _valid_values(operator,
171
+ _valid_values(value,
55
172
  %w( GreaterThanOrEqualToThreshold GreaterThanThreshold
56
173
  LessThanOrEqualToThreshold LessThanThreshold ),
57
174
  "GreaterThanThreshold")
58
175
  end
59
176
  end
60
177
 
178
+ def _cloudwatch_to_unit(value)
179
+ case value
180
+ when "sec"
181
+ "Seconds"
182
+ when "ms"
183
+ "Microseconds"
184
+ when "mms"
185
+ "Milliseconds"
186
+ when "B"
187
+ "Bytes"
188
+ when "KB"
189
+ "Kilobytes"
190
+ when "MB"
191
+ "Megabytes"
192
+ when "GB"
193
+ "Gigabytes"
194
+ when "TB"
195
+ "Terabytes"
196
+ when "b"
197
+ "Bits"
198
+ when "kb", "Kb"
199
+ "Kilobits"
200
+ when "mb", "Mb"
201
+ "Megabits"
202
+ when "gb", "Gb"
203
+ "Gigabits"
204
+ when "tb", "Tb"
205
+ "Terabits"
206
+ when "%", "percent"
207
+ "Percent"
208
+ when "count"
209
+ "Count"
210
+ when "B/s"
211
+ "Bytes/Second"
212
+ when "KB/s"
213
+ "Kilobytes/Second"
214
+ when "MB/s"
215
+ "Megabytes/Second"
216
+ when "GB/s"
217
+ "Gigabyes/Second"
218
+ when "TB/s"
219
+ "Terabytes/Second"
220
+ when "bps"
221
+ "Bits/Second"
222
+ when "kbps"
223
+ "Kilobits/Second"
224
+ when "mbps"
225
+ "Megabits/Second"
226
+ when "gbps"
227
+ "Gigabits/Second"
228
+ when "tbps"
229
+ "Terabits/Second"
230
+ when "cps"
231
+ "Count/Second"
232
+ else
233
+ _valid_values(value,
234
+ %w(Seconds Microseconds Milliseconds Bytes Kilobytes Megabytes Gigabytes Terabytes Bits Kilobits Megabits Gigabits Terabits Percent Count Bytes/Second Kilobytes/Second Megabytes/Second Gigabytes/Second Terabytes/Second Bits/Second Kilobits/Second Megabits/Second Gigabits/Second Terabits/Second Count/Second None),
235
+ "")
236
+ end
237
+ end
238
+
239
+ def _cloudwatch_to_ec2_action(value)
240
+ value = _valid_values(value, %w( recover stop terminate reboot ), "recover")
241
+ _{
242
+ Fn__Join "", [
243
+ "arn:aws:automate:",
244
+ _{
245
+ Ref "AWS::Region"
246
+ },
247
+ ":ec2:#{value}"
248
+ ]
249
+ }
250
+ end
251
+
61
252
  def _cloudwatch_dimension(args)
62
253
  _{
63
254
  Name args[:name]
64
255
  Value _ref_string("value", args)
65
256
  }
66
257
  end
258
+
259
+ def _cloudwatch_actions(args)
260
+ actions = args[:actions] || args[:ref_actions] || []
261
+ is_ref = args.key? :ref_actions
262
+
263
+ array = []
264
+ actions.each do |v|
265
+ if v =~ /ec2 (\w)/
266
+ array << _cloudwatch_to_ec2_action($1)
267
+ else
268
+ if is_ref
269
+ array << _ref_string("action", { ref_action: v })
270
+ else
271
+ array << v
272
+ end
273
+ end
274
+ end
275
+ array
276
+ end
@@ -148,7 +148,9 @@ def _ec2_network_interface(args, is_spot = false)
148
148
  end
149
149
 
150
150
  def _ec2_image(instance_type, args)
151
- return args[:image_id] if args.key? :image_id
151
+ image_id = args[:image_id] || false
152
+ return args[:image_id] if image_id
153
+
152
154
  resource_image = _resource_name(args[:image] || EC2_DEFAULT_IMAGE)
153
155
  _find_in_map("AWSRegionArch2AMI#{resource_image}",
154
156
  _{ Ref "AWS::Region" },
@@ -24,6 +24,10 @@ def _bool(name, args, default = false)
24
24
  args.key?(name.to_sym) ? args[name.to_sym].to_s : default.to_s
25
25
  end
26
26
 
27
+ def _integer(name, args, default = 0)
28
+ args.key?(name.to_sym) ? args[name.to_sym].to_i : default
29
+ end
30
+
27
31
  def _capitalize(name)
28
32
  name.split(' ').map(&:capitalize).join()
29
33
  end
@@ -1 +1 @@
1
- KUMOGATA_TEMPLATE_VERSION = '0.0.17'
1
+ KUMOGATA_TEMPLATE_VERSION = '0.0.18'
@@ -7,16 +7,18 @@ require 'kumogata/template/helper'
7
7
  name = _resource_name(args[:name], "autoscaling scheduled action")
8
8
  autoscaling = _ref_string("autoscaling", args, "autoscaling group")
9
9
  autoscaling = _ref_resource_name(args, "autoscaling group") if autoscaling.empty?
10
- desired = args[:desired].to_s || ""
10
+ desired = _integer("desired", args, -1)
11
11
  end_time =
12
12
  if args.key? :end_time
13
13
  _timestamp_utc(args[:end_time])
14
14
  else
15
15
  ""
16
16
  end
17
- max = args[:max].to_s || ""
18
- min = args[:min].to_s || ""
19
- min = desired.to_s if args.key? :desired and desired.to_i < min.to_i
17
+ max = _integer("max", args, -1)
18
+ max = desired if max < desired
19
+ min = _integer("min", args, -1)
20
+ min = desired if min < desired
21
+
20
22
  recurrence =
21
23
  if args.key? :recurrence
22
24
  case args[:recurrence]
@@ -49,10 +51,10 @@ _(name) do
49
51
  Type "AWS::AutoScaling::ScheduledAction"
50
52
  Properties do
51
53
  AutoScalingGroupName autoscaling
52
- DesiredCapacity desired unless desired.empty?
54
+ DesiredCapacity desired if desired > -1
53
55
  EndTime end_time unless end_time.empty?
54
- MaxSize max unless max.empty?
55
- MinSize min unless min.empty?
56
+ MaxSize max if max > -1
57
+ MinSize min if min > -1
56
58
  Recurrence recurrence unless recurrence.empty?
57
59
  StartTime start_time unless start_time.empty?
58
60
  end
@@ -7,21 +7,21 @@ require 'kumogata/template/cloudwatch'
7
7
 
8
8
  name = _resource_name(args[:name], "alarm")
9
9
  enabled = _bool("enabled", args, true)
10
- actions = _ref_array("actions", args)
10
+ actions = _cloudwatch_actions(args)
11
11
  description = args[:description] || ""
12
12
  alarm_name = _ref_name("alarm_name", args)
13
- operator = _cloudwatch_convert_operator(args[:operator])
13
+ operator = _cloudwatch_to_operator(args[:operator])
14
14
  dimensions = (args[:dimensions] || []).collect{|v| _cloudwatch_dimension(v) }
15
15
  evaluation = args[:evaluation] || 3
16
16
  insufficients = args[:insufficients] || []
17
- metric = args[:metric]
18
- namespace = args[:namespace]
17
+ metric = _cloudwatch_to_metric(args[:metric])
18
+ namespace = _cloudwatch_to_namespace(args[:namespace])
19
19
  ok_actions = args[:ok_actions] || []
20
20
  period = _cloudwatch_to_period(args[:period] || "5m")
21
21
  statistic = _valid_values(_cloudwatch_to_statistic(args[:statistic]),
22
22
  %w(SampleCount Average Sum Minimum Maximum), "Average")
23
23
  threshold = args[:threshold] || 60
24
- unit = _valid_values(args[:unit], %w(Seconds Microseconds Milliseconds Bytes Kilobytes Megabytes Gigabytes Terabytes Bits Kilobits Megabits Gigabits Terabits Percent Count Bytes/Second Kilobytes/Second Megabytes/Second Gigabytes/Second Terabytes/Second Bits/Second Kilobits/Second Megabits/Second Gigabits/Second Terabits/Second Count/Second None), "")
24
+ unit = _cloudwatch_to_unit(args[:unit])
25
25
 
26
26
  _(name) do
27
27
  Type "AWS::CloudWatch::Alarm"
@@ -30,6 +30,8 @@ port = PORT[engine.to_sym] if port.empty?
30
30
  az = _availability_zone(args, false)
31
31
  azs = _availability_zones(args, false)
32
32
  maintenance = _maintenance_window("elasticache", args[:maintenance] || DEFAULT_MAINTENANCE_TIME[:elasticache])
33
+ snapshot_arn = args[:snapshot_arn] || ""
34
+ snapshot_name = args[:snapshot_name] || ""
33
35
  snapshot_retention = args[:snapshot_retention] || DEFAULT_SNAPSHOT_NUM
34
36
  snapshot_window = _window_time("elasticache", args[:snapshot_window_start] || DEFAULT_SNAPSHOT_TIME[:elasticache])
35
37
  tags = _tags(args)
@@ -42,7 +44,7 @@ _(name) do
42
44
  AZMode azmode unless azmode.empty? and engine == "redis"
43
45
  CacheNodeType node
44
46
  CacheParameterGroupName parameter
45
- #CacheSecurityGroupNamesk security_groups if security_group_ids.empty?
47
+ #CacheSecurityGroupNames
46
48
  CacheSubnetGroupName subnet
47
49
  ClusterName cluster
48
50
  Engine engine
@@ -53,8 +55,8 @@ _(name) do
53
55
  PreferredAvailabilityZone az if engine == "redis" and !az.empty?
54
56
  PreferredAvailabilityZones azs if engine == "memached" and !azs.empty?
55
57
  PreferredMaintenanceWindow maintenance
56
- #SnapshotArns
57
- #SnapshotName
58
+ SnapshotArns snapshot_arn unless snapshot_arn.empty?
59
+ SnapshotName snapshot_name unless snapshot_name.empty?
58
60
  SnapshotRetentionLimit snapshot_retention if engine == "redis"
59
61
  SnapshotWindow snapshot_window if engine == "redis"
60
62
  Tags tags
@@ -30,7 +30,10 @@ azs = _availability_zones(args, false)
30
30
  maintenance = _maintenance_window("elasticache", args[:maintenance] || DEFAULT_MAINTENANCE_TIME[:elasticache])
31
31
  description = args[:description] || "#{args[:name]} cache replication group description"
32
32
  security_groups = _ref_array("security_groups", args, "security group")
33
+ snapshot_arn = args[:snapshot_arn] || ""
34
+ snapshot_name = args[:snapshot_name] || ""
33
35
  snapshot_retention = args[:snapshot_retention] || DEFAULT_SNAPSHOT_NUM
36
+ snapshot_id = args[:snapshot_id] || ""
34
37
  snapshot_window = _window_time("elasticache", args[:snapshot_window_start] || DEFAULT_SNAPSHOT_TIME[:elasticache])
35
38
  tags = _tags(args)
36
39
 
@@ -52,8 +55,10 @@ _(name) do
52
55
  PreferredMaintenanceWindow maintenance
53
56
  ReplicationGroupDescription description
54
57
  SecurityGroupIds security_groups unless security_groups.empty?
55
- #SnapshotArns
58
+ SnapshotArns snapshot_arn unless snapshot_arn.empty?
59
+ SnapshotName snapshot_name unless snapshot_name.empty?
56
60
  SnapshotRetentionLimit snapshot_retention if 0 < snapshot_retention
61
+ SnapshottingClusterId snapshot_id unless snapshot_id.empty?
57
62
  SnapshotWindow snapshot_window unless snapshot_retention < 0 and snapshot_window.empty?
58
63
  Tags tags
59
64
  end
@@ -0,0 +1,151 @@
1
+ require 'abstract_unit'
2
+ require 'kumogata/template/cloudwatch'
3
+
4
+ class CloudWatchTest < Minitest::Test
5
+ def test_cloudwatch_to_period
6
+ template = <<-EOS
7
+ Test _cloudwatch_to_period("1m")
8
+ EOS
9
+ act_template = run_client_as_json(template)
10
+ exp_template = <<-EOS
11
+ {
12
+ "Test": "60"
13
+ }
14
+ EOS
15
+ assert_equal exp_template.chomp, act_template
16
+ end
17
+
18
+ def test_cloudwatch_to_statistic
19
+ template = <<-EOS
20
+ Test _cloudwatch_to_statistic("avg")
21
+ EOS
22
+ act_template = run_client_as_json(template)
23
+ exp_template = <<-EOS
24
+ {
25
+ "Test": "Average"
26
+ }
27
+ EOS
28
+ assert_equal exp_template.chomp, act_template
29
+ end
30
+
31
+ def test_cloudwatch_to_metric
32
+ template = <<-EOS
33
+ Test _cloudwatch_to_metric("ec2 cpu utilization")
34
+ EOS
35
+ act_template = run_client_as_json(template)
36
+ exp_template = <<-EOS
37
+ {
38
+ "Test": "CPUUtilization"
39
+ }
40
+ EOS
41
+ assert_equal exp_template.chomp, act_template
42
+ end
43
+
44
+ def test_cloudwatch_to_namespace
45
+ template = <<-EOS
46
+ Test _cloudwatch_to_namespace("ec2")
47
+ EOS
48
+ act_template = run_client_as_json(template)
49
+ exp_template = <<-EOS
50
+ {
51
+ "Test": "AWS/EC2"
52
+ }
53
+ EOS
54
+ assert_equal exp_template.chomp, act_template
55
+ end
56
+
57
+ def test_cloudwatch_to_operator
58
+ template = <<-EOS
59
+ Test _cloudwatch_to_operator(">=")
60
+ EOS
61
+ act_template = run_client_as_json(template)
62
+ exp_template = <<-EOS
63
+ {
64
+ "Test": "GreaterThanOrEqualToThreshold"
65
+ }
66
+ EOS
67
+ assert_equal exp_template.chomp, act_template
68
+ end
69
+
70
+ def test_cloudwatch_to_unit
71
+ template = <<-EOS
72
+ Test _cloudwatch_to_unit("sec")
73
+ EOS
74
+ act_template = run_client_as_json(template)
75
+ exp_template = <<-EOS
76
+ {
77
+ "Test": "Seconds"
78
+ }
79
+ EOS
80
+ assert_equal exp_template.chomp, act_template
81
+ end
82
+
83
+ def test_cloudwatch_to_ec2_action
84
+ template = <<-EOS
85
+ Test _cloudwatch_to_ec2_action("revoert")
86
+ EOS
87
+ act_template = run_client_as_json(template)
88
+ exp_template = <<-EOS
89
+ {
90
+ "Test": {
91
+ "Fn::Join": [
92
+ "",
93
+ [
94
+ "arn:aws:automate:",
95
+ {
96
+ "Ref": "AWS::Region"
97
+ },
98
+ ":ec2:recover"
99
+ ]
100
+ ]
101
+ }
102
+ }
103
+ EOS
104
+ assert_equal exp_template.chomp, act_template
105
+ end
106
+
107
+ def test_cloudwatch_dimension
108
+ template = <<-EOS
109
+ Test _cloudwatch_dimension({ name: "test", value: "test" })
110
+ EOS
111
+ act_template = run_client_as_json(template)
112
+ exp_template = <<-EOS
113
+ {
114
+ "Test": {
115
+ "Name": "test",
116
+ "Value": "test"
117
+ }
118
+ }
119
+ EOS
120
+ assert_equal exp_template.chomp, act_template
121
+ end
122
+
123
+ def test_cloudwatch_actions
124
+ template = <<-EOS
125
+ Test _cloudwatch_actions(ref_actions: [ "ec2 recover", "test" ])
126
+ EOS
127
+ act_template = run_client_as_json(template)
128
+ exp_template = <<-EOS
129
+ {
130
+ "Test": [
131
+ {
132
+ "Fn::Join": [
133
+ "",
134
+ [
135
+ "arn:aws:automate:",
136
+ {
137
+ "Ref": "AWS::Region"
138
+ },
139
+ ":ec2:recover"
140
+ ]
141
+ ]
142
+ },
143
+ {
144
+ "Ref": "Test"
145
+ }
146
+ ]
147
+ }
148
+ EOS
149
+ assert_equal exp_template.chomp, act_template
150
+ end
151
+ end
data/test/ec2_test.rb CHANGED
@@ -308,6 +308,31 @@ Test _ec2_image("test", { image_id: "test" })
308
308
  exp_template = <<-EOS
309
309
  {
310
310
  "Test": "test"
311
+ }
312
+ EOS
313
+ assert_equal exp_template.chomp, act_template
314
+
315
+ template = <<-EOS
316
+ Test _ec2_image("test", { image_id: false })
317
+ EOS
318
+ act_template = run_client_as_json(template)
319
+ exp_template = <<-EOS
320
+ {
321
+ "Test": {
322
+ "Fn::FindInMap": [
323
+ "AWSRegionArch2AMIAmazonLinuxOfficial",
324
+ {
325
+ "Ref": "AWS::Region"
326
+ },
327
+ {
328
+ "Fn::FindInMap": [
329
+ "AWSInstanceType2Arch",
330
+ "test",
331
+ "Arch"
332
+ ]
333
+ }
334
+ ]
335
+ }
311
336
  }
312
337
  EOS
313
338
  assert_equal exp_template.chomp, act_template
data/test/helper_test.rb CHANGED
@@ -22,6 +22,13 @@ class HelperTest < Minitest::Test
22
22
  assert_equal _bool("test", { test1: false }, false), "false"
23
23
  end
24
24
 
25
+ def test_integer
26
+ assert_equal _integer("test", { test: 1 }), 1
27
+ assert_equal _integer("test", { test: 2 }, 1), 2
28
+ assert_equal _integer("test", { test1: 1 }), 0
29
+ assert_equal _integer("test", { test1: 1 }, 2), 2
30
+ end
31
+
25
32
  def test_capitalize
26
33
  assert_equal _capitalize("test test"), "TestTest"
27
34
  end
@@ -218,6 +225,21 @@ Test _ref_name("test", {})
218
225
  assert_equal exp_template.chomp, act_template
219
226
  end
220
227
 
228
+ def test_ref_name_default
229
+ template = <<-EOS
230
+ Test _ref_name_default("test", { name: "test1" })
231
+ EOS
232
+ act_template = run_client_as_json(template)
233
+ exp_template = <<-EOS
234
+ {
235
+ "Test": "test1"
236
+ }
237
+ EOS
238
+ assert_equal exp_template.chomp, act_template
239
+
240
+ # _ref_name_default(name, args, ref_name = '')
241
+ end
242
+
221
243
  def test_attr_string
222
244
  template = <<-EOS
223
245
  Test _attr_string("test", "test1")
@@ -3,7 +3,30 @@ require 'abstract_unit'
3
3
  class AutoscalingScheduledActionTest < Minitest::Test
4
4
  def test_normal
5
5
  template = <<-EOS
6
- _autoscaling_scheduled_action "test", ref_autoscaling: "test", max: "1", min: "1", recurrence: Time.local(2016, 3, 31, 15)
6
+ _autoscaling_scheduled_action "test", ref_autoscaling: "test", desired: "10"
7
+ EOS
8
+ act_template = run_client_as_json(template)
9
+ start_time = _timestamp_utc(Time.now + 3600)
10
+ exp_template = <<-EOS
11
+ {
12
+ "TestAutoscalingScheduledAction": {
13
+ "Type": "AWS::AutoScaling::ScheduledAction",
14
+ "Properties": {
15
+ "AutoScalingGroupName": {
16
+ "Ref": "TestAutoscalingGroup"
17
+ },
18
+ "DesiredCapacity": "10",
19
+ "MaxSize": "10",
20
+ "MinSize": "10",
21
+ "StartTime": "#{start_time}"
22
+ }
23
+ }
24
+ }
25
+ EOS
26
+ assert_equal exp_template.chomp, act_template
27
+
28
+ template = <<-EOS
29
+ _autoscaling_scheduled_action "test", ref_autoscaling: "test", max: 1, min: 1, recurrence: Time.local(2016, 3, 31, 15)
7
30
  EOS
8
31
  act_template = run_client_as_json(template)
9
32
  start_time = _timestamp_utc(Time.now + 3600)
@@ -3,7 +3,7 @@ require 'abstract_unit'
3
3
  class CloudWatchAlarmTest < Minitest::Test
4
4
  def test_normal
5
5
  template = <<-EOS
6
- _cloudwatch_alarm "test", actions: "test", alarm_name: "test", namespace: "test", operator: "<", metric: "test", dimensions: [ { name: "test", value: "test" } ]
6
+ _cloudwatch_alarm "test", actions: [ "test" ], alarm_name: "test", namespace: "ec2", operator: "<", metric: "test", dimensions: [ { name: "test", value: "test" } ]
7
7
  EOS
8
8
  act_template = run_client_as_json(template)
9
9
  exp_template = <<-EOS
@@ -25,7 +25,7 @@ _cloudwatch_alarm "test", actions: "test", alarm_name: "test", namespace: "test"
25
25
  ],
26
26
  "EvaluationPeriods": "3",
27
27
  "MetricName": "test",
28
- "Namespace": "test",
28
+ "Namespace": "AWS/EC2",
29
29
  "Period": "300",
30
30
  "Statistic": "Average",
31
31
  "Threshold": "60"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoya Nakazawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-12 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -248,6 +248,7 @@ files:
248
248
  - test/alb_test.rb
249
249
  - test/autoscaling_test.rb
250
250
  - test/cloudfront_test.rb
251
+ - test/cloudwatch_test.rb
251
252
  - test/codebuild_test.rb
252
253
  - test/codedeploy_test.rb
253
254
  - test/data/lambda_function.py
@@ -412,6 +413,7 @@ test_files:
412
413
  - test/alb_test.rb
413
414
  - test/autoscaling_test.rb
414
415
  - test/cloudfront_test.rb
416
+ - test/cloudwatch_test.rb
415
417
  - test/codebuild_test.rb
416
418
  - test/codedeploy_test.rb
417
419
  - test/data/lambda_function.py