kumogata-template 0.0.18 → 0.0.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3ef42d67f39067721ba98afb39d9392c2d0551e
4
- data.tar.gz: 2b67f7e99a815830cded5cf6ae4cb5d295bfb9da
3
+ metadata.gz: a072c9287be025226a5046066132716048ede1a2
4
+ data.tar.gz: ccfe43986bc296bec97d755cce6f3f1bc96cf291
5
5
  SHA512:
6
- metadata.gz: 5cfcba9ce73284c4ca4de89ef518e136f165f64e8e42145c7bdfb850860a290205e2ce652023bcb0a593b6ccef6925b371608efca172b415fba7a47901a08681
7
- data.tar.gz: 11bfdc2ace307e23e6c71e93e1bad0dfdcca46c9e5324f3ad75a334712a12bc3f19df6b93acb521212ef01644e783edb2ec94cdf724157e74e9824797569d5f3
6
+ metadata.gz: 6f6e0278162a801dcb24ff85836fe6879b14f374926b42c91484405c46f468ba09a8adf58f5c52e1049453af70e65a89c408e1f20e2078202996cffce85a868d
7
+ data.tar.gz: d78e60f26dd322470bada79d3884f134a4f1deb5c5e3826d5949ae64ff0e144a2a809be8d8147e0b51d4defdb2b37c908a3c1c7d11fe2c0284b6ecde970ea606
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kumogata-template (0.0.17)
4
+ kumogata-template (0.0.18)
5
5
  aws-sdk (~> 2.3)
6
6
  kumogata (= 0.5.12)
7
7
 
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # kumogata-template
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/kumogata-template.svg)](http://badge.fury.io/rb/kumogata-template)
3
4
  [![Build Status](https://travis-ci.org/n0ts/kumogata-template.svg?branch=master)](https://travis-ci.org/n0ts/kumogata-template)
4
5
 
5
6
  ## About
@@ -3,19 +3,51 @@
3
3
  #
4
4
  require 'kumogata/template/helper'
5
5
 
6
- def _alb_certificates(args)
7
- certificates = args[:certificates] || []
6
+ def _alb_to_lb_attribute_access_log(args)
7
+ {
8
+ "access_logs.s3.enabled": true,
9
+ "access_logs.s3.bucket": args[:bucket],
10
+ "access_logs.s3.prefix": args[:prefix],
11
+ }
12
+ end
8
13
 
9
- array = []
10
- certificates.each do |certificate|
11
- cert = _ref_string("value", { value: certificate }, "certificate")
12
- next if cert.empty?
14
+ def _alb_to_lb_attribute_delete_protection
15
+ {
16
+ "deletion_protection.enabled": true
17
+ }
18
+ end
13
19
 
14
- array << _{
15
- CertificateArn cert
16
- }
17
- end
18
- array
20
+ def _alb_to_lb_attribute_idle_timeout(value)
21
+ # idle timeout seconds 1-3600
22
+ {
23
+ "idle_timeout.timeout_seconds": value
24
+ }
25
+ end
26
+
27
+ def _alb_to_target_group_attribute_delay_timeout(value)
28
+ # wait before changing the state of a deregistering target from draining to unused 0-3600 seconds.
29
+ {
30
+ "deregistration_delay.timeout_seconds": value
31
+ }
32
+ end
33
+
34
+ def _alb_to_target_group_stickiness(value)
35
+ # 1 second to 1 week (604800 seconds). The default value is 1 day (86400 seconds).
36
+ {
37
+ "stickiness.enabled": true,
38
+ "stickiness.type": "lb_cookie",
39
+ "stickiness.lb_cookie.duration_seconds": value
40
+ }
41
+ end
42
+
43
+ def _alb_certificates(args)
44
+ certificate = _ref_string("certificate", args)
45
+
46
+ [
47
+ _{
48
+ CertificateArn certificate
49
+ }
50
+ ]
19
51
  end
20
52
 
21
53
  def _alb_actions(args)
@@ -92,7 +92,7 @@ def _autoscaling_tags(args)
92
92
  tags = [
93
93
  _{
94
94
  Key "Name"
95
- Value _tag_name(args[:tag_name] || args[:name])
95
+ Value _tag_name(args)
96
96
  PropagateAtLaunch _bool("tag_name_launch", args, true)
97
97
  },
98
98
  _{
@@ -2,19 +2,22 @@
2
2
  # AWS Constants
3
3
  #
4
4
 
5
+ # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions
5
6
  AWS_REGION = {
6
7
  virginia: "us-east-1",
7
8
  ohio: "us-east-2",
8
- oregon: "us-west-2",
9
9
  california: "us-west-1",
10
+ oregon: "us-west-2",
11
+ canada: "ca-central-1",
10
12
  ireland: "eu-west-1",
11
13
  frankfurt: "eu-central-1",
12
- singapore: "ap-southeast-1",
14
+ london: "eu-west-2",
13
15
  tokyo: "ap-northeast-1",
14
- sydney: "ap-southeast-2",
15
16
  seoul: "ap-northeast-2",
16
- saopaulo: "sa-east-1",
17
+ singapore: "ap-southeast-1",
18
+ sydney: "ap-southeast-2",
17
19
  mumbai: "ap-south-1",
20
+ saopaulo: "sa-east-1",
18
21
  }
19
22
 
20
23
  PORT = {
@@ -21,7 +21,8 @@ def _array(args)
21
21
  end
22
22
 
23
23
  def _bool(name, args, default = false)
24
- args.key?(name.to_sym) ? args[name.to_sym].to_s : default.to_s
24
+ bool = args.key?(name.to_sym) ? args[name.to_sym] : default
25
+ bool.to_s == 'true'
25
26
  end
26
27
 
27
28
  def _integer(name, args, default = 0)
@@ -32,6 +33,12 @@ def _capitalize(name)
32
33
  name.split(' ').map(&:capitalize).join()
33
34
  end
34
35
 
36
+ def _description(name)
37
+ name.gsub("\n", ' ').
38
+ gsub(/\s+/, ' ').gsub(/^\s/, '').gsub(/\s$/, '').
39
+ chomp.slice(0, 1024)
40
+ end
41
+
35
42
  def _valid_values(value, values, default = nil)
36
43
  return default if value.nil?
37
44
  values.collect{|v| return v if v =~ /^#{value}$/i }
@@ -81,12 +88,13 @@ def _ref_attr_string(name, attr, args, ref_name = '')
81
88
  end
82
89
 
83
90
  def _ref_name(name, args, ref_name = '')
91
+ return _{ Ref _resource_name(args["ref_raw_#{name}".to_sym], ref_name) } if args.key? "ref_raw_#{name}".to_sym
84
92
  return args["raw_#{name}".to_sym] if args.key? "raw_#{name}".to_sym
85
93
  name = _ref_string(name, args, ref_name)
86
94
  if name.empty?
87
- _{ Fn__Join "-", [ _{ Ref "Service" }, _{ Ref "Name" } ] }
95
+ _{ Fn__Join "-", [ _{ Ref _resource_name("service") }, _{ Ref _resource_name("name") } ] }
88
96
  elsif name.is_a? Hash
89
- _{ Fn__Join "-", [ _{ Ref "Service" }, name ] }
97
+ _{ Fn__Join "-", [ _{ Ref _resource_name("service") }, name ] }
90
98
  else
91
99
  name.gsub(' ', '-')
92
100
  end
@@ -132,7 +140,7 @@ def _tags(args)
132
140
  tags = [
133
141
  _{
134
142
  Key "Name"
135
- Value _tag_name(args[:name])
143
+ Value _tag_name(args)
136
144
  },
137
145
  _{
138
146
  Key "Service"
@@ -147,10 +155,16 @@ def _tags(args)
147
155
  tags
148
156
  end
149
157
 
150
- def _tag_name(name)
151
- _{
152
- Fn__Join [ "-", [ _{ Ref _resource_name("service") }, name.to_s.gsub(' ', '-') ] ]
153
- }
158
+ def _tag_name(args)
159
+ return _{ Ref _resource_name(args["ref_raw_tag_name".to_sym]) } if args.key? "ref_raw_tag_name".to_sym
160
+ return args["raw_tag_name".to_sym] if args.key? "raw_tag_name".to_sym
161
+
162
+ tag_name = _ref_string("tag_name", args)
163
+ return tag_name unless tag_name.empty?
164
+
165
+ tag_name = _ref_string("name", args)
166
+ tag_name = tag_name.gsub(' ', '-') if tag_name.is_a? String
167
+ _{ Fn__Join [ "-", [ _{ Ref _resource_name(args[:tag_service] || "service") }, tag_name ] ] }
154
168
  end
155
169
 
156
170
  def _availability_zone(args, use_subnet = true)
@@ -1 +1 @@
1
- KUMOGATA_TEMPLATE_VERSION = '0.0.18'
1
+ KUMOGATA_TEMPLATE_VERSION = '0.0.19'
@@ -10,13 +10,13 @@ certificates = _alb_certificates(args)
10
10
  defaults = _alb_actions(args)
11
11
  lb = _ref_string("lb", args, "load balancer")
12
12
  port = args[:port] || 80
13
- protocol = _valid_values("protocol", %w( http https ), "http")
13
+ protocol = _valid_values(args[:protocol], %w( http https ), "http")
14
14
  ssl = args[:ssl] || ""
15
15
 
16
16
  _(name) do
17
17
  Type "AWS::ElasticLoadBalancingV2::Listener"
18
18
  Properties do
19
- Certificates certificates unless certificates.empty?
19
+ Certificates certificates if protocol == "https"
20
20
  DefaultActions defaults
21
21
  LoadBalancerArn lb
22
22
  Port port
@@ -11,8 +11,14 @@ matcher = _alb_matcher(args)
11
11
  target_name = _ref_name("target_name", args)
12
12
  target_name = args[:name] if target_name.empty?
13
13
  attributes = _alb_attributes(args)
14
- port = args[:port] || 80
15
- protocol = _valid_values("protocol", %w( http https ), "http")
14
+ full_name = _ref_string("full_name", args)
15
+ protocol = _valid_values(args[:protocol], %w( http https ), "http")
16
+ port =
17
+ if PORT.key? protocol.to_sym
18
+ PORT[protocol.to_sym]
19
+ else
20
+ args[:port] || PORT[:http]
21
+ end
16
22
  tags = _tags(args)
17
23
  targets = _alb_targets(args)
18
24
  vpc = _ref_string("vpc", args, "vpc")
@@ -31,8 +37,9 @@ _(name) do
31
37
  Port port
32
38
  Protocol protocol.upcase
33
39
  Tags tags
34
- TargetGroupAttributes attributes
35
- Targets targets
40
+ TargetGroupAttributes attributes unless attributes.empty?
41
+ TargetGroupFullName full_name unless full_name.empty?
42
+ Targets targets unless targets.empty?
36
43
  UnhealthyThresholdCount health_check[:unhealthly]
37
44
  VpcId vpc
38
45
  end
@@ -19,9 +19,10 @@ max = desired if max < desired
19
19
  min = _integer("min", args, -1)
20
20
  min = desired if min < desired
21
21
 
22
+ # 0 - 6 Sunday to Saturday
22
23
  recurrence =
23
- if args.key? :recurrence
24
- case args[:recurrence]
24
+ if args.key? :cron
25
+ case args[:cron]
25
26
  when "every 5 min"
26
27
  "*/5 * * * *"
27
28
  when "every 30 min"
@@ -31,21 +32,19 @@ recurrence =
31
32
  when "every day"
32
33
  "0 0 * * *"
33
34
  when "every week"
34
- "0 0 * * Tue"
35
+ "0 0 * * #{args[:cron_day] || 'Tue'}"
35
36
  when /\*/
36
- args[:recurrence]
37
- else
38
- _timestamp_utc(args[:recurrence], "cron")
37
+ args[:cron]
39
38
  end
39
+ elsif args[:cron_time]
40
+ _timestamp_utc(args[:cron_time], "cron")
40
41
  else
41
42
  ""
42
43
  end
43
- start_time =
44
- if args.key? :start_time
45
- _timestamp_utc(args[:start_time])
46
- else
47
- _timestamp_utc(Time.now + 3600)
48
- end
44
+ start_time = _timestamp_utc(args[:start_time] || Time.now + 3600)
45
+
46
+ ## FIXME if older dot not empty
47
+
49
48
 
50
49
  _(name) do
51
50
  Type "AWS::AutoScaling::ScheduledAction"
@@ -12,20 +12,24 @@ AWSInstanceType2Arch do
12
12
  end
13
13
 
14
14
  # Amazon Linux AMI (HVM / 64-bit)
15
- # https://aws.amazon.com/marketplace/pp/B00CIYTQTC/ref=srh_res_product_title?ie=UTF8&sr=0-3&qid=1460447105907
15
+ # https://aws.amazon.com/marketplace/pp/B00CIYTQTC/
16
16
  AWSRegionArch2AMIAmazonLinuxOfficial do
17
- # 2016.03
17
+ # 2016.09
18
18
  image_id = {
19
- virginia: "08111162",
20
- oregon: "c229c0a2",
21
- california: "1b0f7d7b",
22
- frankfurt: "e2df388d",
23
- ireland: "31328842",
24
- singapore: "e90dc68a",
25
- sydney: "f2210191",
26
- tokyo: "f80e0596",
27
- seoul: "6598510b",
28
- saopaulo: "1e159872",
19
+ virginia: "0b33d91d",
20
+ ohio: "c55673a0",
21
+ california: "165a0876",
22
+ oregon: "f173cc91",
23
+ canada: "ebed508f",
24
+ ireland: "70edb016",
25
+ frankfurt: "af0fc0c0",
26
+ london: "f1949e95",
27
+ tokyo: "56d4ad31",
28
+ seoul: "dac312b4",
29
+ singapore: "dc9339bf",
30
+ sydney: "1c47407f",
31
+ mumbai: "f9daac96",
32
+ saopaulo: "80086dec",
29
33
  }
30
34
 
31
35
  AWS_REGION.each do |key, region|
@@ -37,20 +41,24 @@ end
37
41
 
38
42
  # CentOS 7 (x86_64) with Updates HVM
39
43
  # https://wiki.centos.org/Cloud/AWS
40
- # https://aws.amazon.com/marketplace/ordering/ref=dtl_psb_continue?ie=UTF8&productId=b7ee8a69-ee97-4a49-9e68-afaee216db2e
44
+ # https://aws.amazon.com/marketplace/pp/B00O7WM7QW/
41
45
  AWSRegionArch2AMICentos7Official do
42
46
  # 1602, released 02/26/2016
43
47
  image_id = {
44
- virginia: "6d1c2007",
45
- oregon: "d2c924b2",
48
+ virginia: "6d1c2007",
49
+ ohio: "6a2d760f",
46
50
  california: "af4333cf",
47
- ireland: "7abd0209",
48
- frankfurt: "9bf712f4",
49
- singapore: "f068a193",
50
- tokyo: "eec1c380",
51
- sydney: "fedafc9d",
52
- seoul: "c74789a9",
53
- saopaulo: "26b93b4a",
51
+ oregon: "d2c924b2",
52
+ canada: "af62d0cb",
53
+ ireland: "7abd0209",
54
+ frankfurt: "9bf712f4",
55
+ london: "bb373ddf",
56
+ tokyo: "eec1c380",
57
+ seoul: "c74789a9",
58
+ singapore: "f068a193",
59
+ sydney: "fedafc9d",
60
+ mumbai: "95cda6fa",
61
+ saopaulo: "26b93b4a",
54
62
  }
55
63
 
56
64
  AWS_REGION.each do |key, region|
@@ -62,19 +70,24 @@ end
62
70
 
63
71
  # Ubuntu Server 16.04 LTS
64
72
  # https://cloud-images.ubuntu.com/locator/ec2/
73
+ # https://aws.amazon.com/marketplace/pp/B01JBL2M0O
65
74
  AWSRegionArch2AMIUbuntu16Official do
66
75
  # 16.04 LTS 20160907.1 hvm:ebs-ssd
67
76
  image_id = {
68
- virginia: "2ef48339",
69
- oregon: "746aba14",
70
- california: "a9a8e4c9",
71
- frankfurt: "a9a557c6",
72
- ireland: "643d4217",
73
- singapore: "42934921",
74
- sydney: "623c0d01",
75
- tokyo: "919cd68",
76
- seoul: "", ## N/A
77
- saopaulo: "60bd2d0c",
77
+ virginia: "3267bb24",
78
+ ohio: "e5be9b80",
79
+ california: "456f3125",
80
+ oregon: "df25a6bf",
81
+ canada: "", ## N/A
82
+ ireland: "cdfed1ab",
83
+ frankfurt: "f6dd0899",
84
+ london: "bcc5d0d8",
85
+ tokyo: "0c05506b",
86
+ seoul: "fc38e892",
87
+ singapore: "4a299829",
88
+ sydney: "d02d2eb3",
89
+ mumbai: "", ## N/A
90
+ saopaulo: "4cacca20",
78
91
  }
79
92
 
80
93
  AWS_REGION.each do |key, region|
@@ -2,7 +2,9 @@
2
2
  # Output ec2
3
3
  #
4
4
 
5
+ public_ip = args[:public_ip] || false
6
+
5
7
  _output "#{args[:name]} instance", ref_value: "#{args[:name]} instance"
6
8
  _output "#{args[:name]} instance az", ref_value: [ "#{args[:name]} instance", "AvailabilityZone" ]
7
- _output "#{args[:name]} instance public ip", ref_value: [ "#{args[:name]} instance", "PublicIp" ] if args.key? :public_ip
9
+ _output "#{args[:name]} instance public ip", ref_value: [ "#{args[:name]} instance", "PublicIp" ] if public_ip
8
10
  _output "#{args[:name]} instance private ip", ref_value: [ "#{args[:name]} instance", "PrivateIp" ]
@@ -12,5 +12,5 @@ _output "#{args[:name]} load balancer dns name",
12
12
  ref_value: [ "#{args[:name]} load balancer", "DNSName" ]
13
13
  _output "#{args[:name]} load balancer security group name",
14
14
  ref_value: [ "#{args[:name]} load balancer", "SourceSecurityGroup.GroupName" ]
15
- _output "#{args[:name]} load balancer securiry group owner",
15
+ _output "#{args[:name]} load balancer security group owner",
16
16
  ref_value: [ "#{args[:name]} load balancer", "SourceSecurityGroup.OwnerAlias" ]
@@ -0,0 +1,6 @@
1
+ #
2
+ # Output IAM instance profile
3
+ #
4
+
5
+ _output "#{args[:name]} instance profile", ref_value: "#{args[:name]} instance profile"
6
+ _output "#{args[:name]} instance profile arn", ref_value: [ "#{args[:name]} instance profile", "Arn" ]
@@ -0,0 +1,6 @@
1
+ #
2
+ # Output IAM role
3
+ #
4
+
5
+ _output "#{args[:name]} role", ref_value: "#{args[:name]} role"
6
+ _output "#{args[:name]} role arn", ref_value: [ "#{args[:name]} role", "Arn" ]
data/test/ec2_test.rb CHANGED
@@ -171,7 +171,7 @@ Test _ec2_security_group_egress(to: 80, group: "test")
171
171
  assert_equal exp_template.chomp, act_template
172
172
  end
173
173
 
174
- def test_ec2_securiry_group_ingresses
174
+ def test_ec2_security_group_ingresses
175
175
  template = <<-EOS
176
176
  args = { ingress: [ from: 80 ] }
177
177
  Test _ec2_security_group_ingresses("ingress", args)
@@ -317,6 +317,28 @@ Test _ec2_image("test", { image_id: false })
317
317
  EOS
318
318
  act_template = run_client_as_json(template)
319
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
+ }
336
+
337
+ template = <<-EOS
338
+ Test _ec2_image("test", { image_id: nil })
339
+ EOS
340
+ act_template = run_client_as_json(template)
341
+ exp_template = <<-EOS
320
342
  {
321
343
  "Test": {
322
344
  "Fn::FindInMap": [
data/test/helper_test.rb CHANGED
@@ -16,10 +16,10 @@ class HelperTest < Minitest::Test
16
16
  end
17
17
 
18
18
  def test_bool
19
- assert_equal _bool("test", { test: true }), "true"
20
- assert_equal _bool("test", { test: false }), "false"
21
- assert_equal _bool("test", { test1: false }, true), "true"
22
- assert_equal _bool("test", { test1: false }, false), "false"
19
+ assert_equal _bool("test", { test: true }), true
20
+ assert_equal _bool("test", { test: false }), false
21
+ assert_equal _bool("test", { test1: false }, true), true
22
+ assert_equal _bool("test", { test1: false }, false), false
23
23
  end
24
24
 
25
25
  def test_integer
@@ -33,6 +33,14 @@ class HelperTest < Minitest::Test
33
33
  assert_equal _capitalize("test test"), "TestTest"
34
34
  end
35
35
 
36
+ def test_description
37
+ description = _description <<-EOS
38
+ test description,
39
+ test
40
+ EOS
41
+ assert_equal description, "test description, test"
42
+ end
43
+
36
44
  def test_valid_values
37
45
  assert_equal _valid_values("test1", ["test1", "test2"]), "test1"
38
46
  assert_equal _valid_values("test3", ["test1", "test2"], "test1"), "test1"
@@ -201,6 +209,30 @@ Test _ref_name("test", ref_test: "test")
201
209
  EOS
202
210
  assert_equal exp_template.chomp, act_template
203
211
 
212
+ template = <<-EOS
213
+ Test _ref_name("test", raw_test: "test")
214
+ EOS
215
+ act_template = run_client_as_json(template)
216
+ exp_template = <<-EOS
217
+ {
218
+ "Test": "test"
219
+ }
220
+ EOS
221
+ assert_equal exp_template.chomp, act_template
222
+
223
+ template = <<-EOS
224
+ Test _ref_name("test", ref_raw_test: "test")
225
+ EOS
226
+ act_template = run_client_as_json(template)
227
+ exp_template = <<-EOS
228
+ {
229
+ "Test": {
230
+ "Ref": "Test"
231
+ }
232
+ }
233
+ EOS
234
+ assert_equal exp_template.chomp, act_template
235
+
204
236
  template = <<-EOS
205
237
  Test _ref_name("test", {})
206
238
  EOS
@@ -416,7 +448,7 @@ Test _tags({ name: "test", tags_append: { ref_test: "test" } })
416
448
 
417
449
  def test_tag_name
418
450
  template = <<-EOS
419
- Test _tag_name("test")
451
+ Test _tag_name(name: "test")
420
452
  EOS
421
453
  act_template = run_client_as_json(template)
422
454
  exp_template = <<-EOS
@@ -432,6 +464,111 @@ Test _tag_name("test")
432
464
  ]
433
465
  ]
434
466
  }
467
+ }
468
+ EOS
469
+ assert_equal exp_template.chomp, act_template
470
+
471
+ template = <<-EOS
472
+ Test _tag_name(ref_name: "test")
473
+ EOS
474
+ act_template = run_client_as_json(template)
475
+ exp_template = <<-EOS
476
+ {
477
+ "Test": {
478
+ "Fn::Join": [
479
+ "-",
480
+ [
481
+ {
482
+ "Ref": "Service"
483
+ },
484
+ {
485
+ "Ref": "Test"
486
+ }
487
+ ]
488
+ ]
489
+ }
490
+ }
491
+ EOS
492
+ assert_equal exp_template.chomp, act_template
493
+
494
+ template = <<-EOS
495
+ Test _tag_name(tag_name: "test")
496
+ EOS
497
+ act_template = run_client_as_json(template)
498
+ exp_template = <<-EOS
499
+ {
500
+ "Test": "test"
501
+ }
502
+ EOS
503
+ assert_equal exp_template.chomp, act_template
504
+
505
+ template = <<-EOS
506
+ Test _tag_name(ref_tag_name: "test")
507
+ EOS
508
+ act_template = run_client_as_json(template)
509
+ exp_template = <<-EOS
510
+ {
511
+ "Test": {
512
+ "Ref": "Test"
513
+ }
514
+ }
515
+ EOS
516
+ assert_equal exp_template.chomp, act_template
517
+
518
+ template = <<-EOS
519
+ Test _tag_name({ name: "test", ref_tag_name: "test" })
520
+ EOS
521
+ act_template = run_client_as_json(template)
522
+ exp_template = <<-EOS
523
+ {
524
+ "Test": {
525
+ "Ref": "Test"
526
+ }
527
+ }
528
+ EOS
529
+ assert_equal exp_template.chomp, act_template
530
+
531
+ template = <<-EOS
532
+ Test _tag_name(ref_raw_tag_name: "test")
533
+ EOS
534
+ act_template = run_client_as_json(template)
535
+ exp_template = <<-EOS
536
+ {
537
+ "Test": {
538
+ "Ref": "Test"
539
+ }
540
+ }
541
+ EOS
542
+ assert_equal exp_template.chomp, act_template
543
+
544
+ template = <<-EOS
545
+ Test _tag_name(raw_tag_name: "test")
546
+ EOS
547
+ act_template = run_client_as_json(template)
548
+ exp_template = <<-EOS
549
+ {
550
+ "Test": "test"
551
+ }
552
+ EOS
553
+ assert_equal exp_template.chomp, act_template
554
+
555
+ template = <<-EOS
556
+ Test _tag_name(name: "test", tag_service: "test")
557
+ EOS
558
+ act_template = run_client_as_json(template)
559
+ exp_template = <<-EOS
560
+ {
561
+ "Test": {
562
+ "Fn::Join": [
563
+ "-",
564
+ [
565
+ {
566
+ "Ref": "Test"
567
+ },
568
+ "test"
569
+ ]
570
+ ]
571
+ }
435
572
  }
436
573
  EOS
437
574
  assert_equal exp_template.chomp, act_template
@@ -477,6 +614,7 @@ Test _availability_zone({})
477
614
  }
478
615
  EOS
479
616
  assert_equal exp_template.chomp, act_template
617
+
480
618
  end
481
619
 
482
620
  def test_availability_zones
@@ -3,47 +3,7 @@ require 'kumogata/template/const'
3
3
 
4
4
  class MappingsEc2Test < Minitest::Test
5
5
  def test_normal
6
- # from mappings-ec2
7
- amazon_image_id = {
8
- virginia: "08111162",
9
- oregon: "c229c0a2",
10
- california: "1b0f7d7b",
11
- frankfurt: "e2df388d",
12
- ireland: "31328842",
13
- singapore: "e90dc68a",
14
- sydney: "f2210191",
15
- tokyo: "f80e0596",
16
- seoul: "6598510b",
17
- saopaulo: "1e159872",
18
- }
19
- amazon_images = get_image_values(amazon_image_id)
20
- centos7_image_id = {
21
- virginia: "6d1c2007",
22
- oregon: "d2c924b2",
23
- california: "af4333cf",
24
- ireland: "7abd0209",
25
- frankfurt: "9bf712f4",
26
- singapore: "f068a193",
27
- tokyo: "eec1c380",
28
- sydney: "fedafc9d",
29
- seoul: "c74789a9",
30
- saopaulo: "26b93b4a",
31
- }
32
- centos7_images = get_image_values(centos7_image_id)
33
- ubuntu16_image_id = {
34
- virginia: "2ef48339",
35
- oregon: "746aba14",
36
- california: "a9a8e4c9",
37
- frankfurt: "a9a557c6",
38
- ireland: "643d4217",
39
- singapore: "42934921",
40
- sydney: "623c0d01",
41
- tokyo: "919cd68",
42
- seoul: "", ## N/A
43
- saopaulo: "60bd2d0c",
44
- }
45
- ubuntu16_images = get_image_values(ubuntu16_image_id)
46
-
6
+ images = generate_image_values
47
7
  archs = ""
48
8
  EC2_INSTANCE_TYPES.each_with_index do |type, i|
49
9
  archs += <<-EOS
@@ -56,20 +16,21 @@ class MappingsEc2Test < Minitest::Test
56
16
  template = <<-EOS
57
17
  _mappings_ec2 "test"
58
18
  EOS
59
- act_template = run_client_as_json(template)
19
+ act_template = convert_image_values(run_client_as_json(template))
20
+
60
21
  exp_template = <<-EOS
61
22
  {
62
23
  "AWSInstanceType2Arch": {
63
24
  #{archs.chomp}
64
25
  },
65
26
  "AWSRegionArch2AMIAmazonLinuxOfficial": {
66
- #{amazon_images.chomp}
27
+ #{images.chomp}
67
28
  },
68
29
  "AWSRegionArch2AMICentos7Official": {
69
- #{centos7_images.chomp}
30
+ #{images.chomp}
70
31
  },
71
32
  "AWSRegionArch2AMIUbuntu16Official": {
72
- #{ubuntu16_images.chomp}
33
+ #{images.chomp}
73
34
  }
74
35
  }
75
36
  EOS
@@ -77,16 +38,35 @@ _mappings_ec2 "test"
77
38
  end
78
39
 
79
40
  private
80
- def get_image_values image_ids
41
+ def generate_image_values
81
42
  values = ''
82
43
  AWS_REGION.each_with_index do |v, i|
83
44
  region, location = v
84
45
  values += <<-EOS
85
46
  "#{location}": {
86
- "HVM64": "ami-#{image_ids[region]}"
47
+ "HVM64": "ami-*"
87
48
  }#{i == (AWS_REGION.size - 1) ? '' : ','}
88
49
  EOS
89
50
  end
90
51
  values
91
52
  end
53
+
54
+ def convert_image_values(values)
55
+ result = {}
56
+ JSON.parse(values).each do |k ,v|
57
+ if k == "AWSInstanceType2Arch"
58
+ result[k] = v
59
+ next
60
+ else
61
+ result[k] = {}
62
+ end
63
+ v.each do |kk, vv|
64
+ result[k][kk] = {}
65
+ vv.each do |kkk, vvv|
66
+ result[k][kk][kkk] = vvv.gsub(/^ami-(.*)/, 'ami-*')
67
+ end
68
+ end
69
+ end
70
+ JSON.pretty_generate(result)
71
+ end
92
72
  end
@@ -32,8 +32,8 @@ _output_elb "test"
32
32
  ]
33
33
  }
34
34
  },
35
- "TestLoadBalancerSecuriryGroupOwner": {
36
- "Description": "description of TestLoadBalancerSecuriryGroupOwner",
35
+ "TestLoadBalancerSecurityGroupOwner": {
36
+ "Description": "description of TestLoadBalancerSecurityGroupOwner",
37
37
  "Value": {
38
38
  "Fn::GetAtt": [
39
39
  "TestLoadBalancer",
@@ -93,8 +93,8 @@ _output_elb "test", route53: true
93
93
  ]
94
94
  }
95
95
  },
96
- "TestLoadBalancerSecuriryGroupOwner": {
97
- "Description": "description of TestLoadBalancerSecuriryGroupOwner",
96
+ "TestLoadBalancerSecurityGroupOwner": {
97
+ "Description": "description of TestLoadBalancerSecurityGroupOwner",
98
98
  "Value": {
99
99
  "Fn::GetAtt": [
100
100
  "TestLoadBalancer",
@@ -0,0 +1,30 @@
1
+ require 'abstract_unit'
2
+
3
+ class OutputIamInstancerProfileTest < Minitest::Test
4
+ def test_normal
5
+ template = <<-EOS
6
+ _output_iam_instance_profile "test"
7
+ EOS
8
+ act_template = run_client_as_json(template)
9
+ exp_template = <<-EOS
10
+ {
11
+ "TestInstanceProfile": {
12
+ "Description": "description of TestInstanceProfile",
13
+ "Value": {
14
+ "Ref": "TestInstanceProfile"
15
+ }
16
+ },
17
+ "TestInstanceProfileArn": {
18
+ "Description": "description of TestInstanceProfileArn",
19
+ "Value": {
20
+ "Fn::GetAtt": [
21
+ "TestInstanceProfile",
22
+ "Arn"
23
+ ]
24
+ }
25
+ }
26
+ }
27
+ EOS
28
+ assert_equal exp_template.chomp, act_template
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'abstract_unit'
2
+
3
+ class OutputIamRoleTest < Minitest::Test
4
+ def test_normal
5
+ template = <<-EOS
6
+ _output_iam_role "test"
7
+ EOS
8
+ act_template = run_client_as_json(template)
9
+ exp_template = <<-EOS
10
+ {
11
+ "TestRole": {
12
+ "Description": "description of TestRole",
13
+ "Value": {
14
+ "Ref": "TestRole"
15
+ }
16
+ },
17
+ "TestRoleArn": {
18
+ "Description": "description of TestRoleArn",
19
+ "Value": {
20
+ "Fn::GetAtt": [
21
+ "TestRole",
22
+ "Arn"
23
+ ]
24
+ }
25
+ }
26
+ }
27
+ EOS
28
+ assert_equal exp_template.chomp, act_template
29
+ end
30
+ end
@@ -3,7 +3,7 @@ require 'abstract_unit'
3
3
  class RdsDbInstanceTest < Minitest::Test
4
4
  def test_normal
5
5
  template = <<-EOS
6
- _rds_db_instance "test", ref_db_name: "test", ref_port: "test", ref_subnet_group: "test", ref_security_groups: "test", ref_user_name: "test", ref_user_password: "test"
6
+ _rds_db_instance "test", ref_db_name: "test", ref_port: "test", ref_subnet_group: "test", ref_security_groups: "test", ref_user_name: "test", ref_user_password: "test", az: "test"
7
7
  EOS
8
8
  act_template = run_client_as_json(template)
9
9
  exp_template = <<-EOS
@@ -14,6 +14,7 @@ _rds_db_instance "test", ref_db_name: "test", ref_port: "test", ref_subnet_group
14
14
  "AllocatedStorage": "5",
15
15
  "AllowMajorVersionUpgrade": "true",
16
16
  "AutoMinorVersionUpgrade": "true",
17
+ "AvailabilityZone": "test",
17
18
  "BackupRetentionPeriod": "7",
18
19
  "DBInstanceClass": "db.t2.medium",
19
20
  "DBInstanceIdentifier": {
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.18
4
+ version: 0.0.19
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-28 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -214,6 +214,8 @@ files:
214
214
  - template/output-elasticache.rb
215
215
  - template/output-elb.rb
216
216
  - template/output-emr.rb
217
+ - template/output-iam-instance-profile.rb
218
+ - template/output-iam-role.rb
217
219
  - template/output-name.rb
218
220
  - template/output-rds.rb
219
221
  - template/output-redshift.rb
@@ -354,6 +356,8 @@ files:
354
356
  - test/template/output-elasticache_test.rb
355
357
  - test/template/output-elb_test.rb
356
358
  - test/template/output-emr_test.rb
359
+ - test/template/output-iam-instance-profile_test.rb
360
+ - test/template/output-iam-role_test.rb
357
361
  - test/template/output-name_test.rb
358
362
  - test/template/output-rds_test.rb
359
363
  - test/template/output-redshift_test.rb
@@ -519,6 +523,8 @@ test_files:
519
523
  - test/template/output-elasticache_test.rb
520
524
  - test/template/output-elb_test.rb
521
525
  - test/template/output-emr_test.rb
526
+ - test/template/output-iam-instance-profile_test.rb
527
+ - test/template/output-iam-role_test.rb
522
528
  - test/template/output-name_test.rb
523
529
  - test/template/output-rds_test.rb
524
530
  - test/template/output-redshift_test.rb