kumogata-template 0.0.29 → 0.0.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/Gemfile.lock +13 -40
  4. data/README.md +34 -83
  5. data/bin/kumogata-template +2 -2
  6. data/kumogata-template.gemspec +4 -4
  7. data/lib/kumogata/template/autoscaling.rb +19 -0
  8. data/lib/kumogata/template/cloudwatch.rb +1 -9
  9. data/lib/kumogata/template/const.rb +22 -4
  10. data/lib/kumogata/template/ec2.rb +18 -8
  11. data/lib/kumogata/template/ecs.rb +34 -0
  12. data/lib/kumogata/template/elasticbeanstalk.rb +937 -3
  13. data/lib/kumogata/template/ext/kumogata.rb +64 -16
  14. data/lib/kumogata/template/helper.rb +146 -19
  15. data/lib/kumogata/template/iam.rb +2 -3
  16. data/lib/kumogata/template/lambda.rb +10 -1
  17. data/lib/kumogata/template/version.rb +1 -1
  18. data/template/_template.rb +20 -3
  19. data/template/alb-load-balancer.rb +8 -1
  20. data/template/autoscaling-launch-configuration.rb +2 -11
  21. data/template/autoscaling-scheduled-action.rb +2 -17
  22. data/template/ec2-instance.rb +5 -7
  23. data/template/ec2-network-acl-entry.rb +3 -1
  24. data/template/ec2-route.rb +3 -1
  25. data/template/ec2-security-group.rb +2 -0
  26. data/template/ec2-subnet.rb +2 -1
  27. data/template/ec2-vpc.rb +2 -1
  28. data/template/ecs-service.rb +4 -0
  29. data/template/ecs-task-definition.rb +6 -4
  30. data/template/elasticbeanstalk-application-version.rb +9 -4
  31. data/template/elasticbeanstalk-application.rb +4 -3
  32. data/template/elasticbeanstalk-configuration-template.rb +7 -2
  33. data/template/elasticbeanstalk-environment.rb +10 -10
  34. data/template/emr-cluster.rb +8 -3
  35. data/template/iam-instance-profile.rb +2 -0
  36. data/template/lambda-function.rb +8 -3
  37. data/template/mappings-ec2.rb +44 -44
  38. data/template/output-access-key.rb +7 -2
  39. data/template/output-alb.rb +16 -11
  40. data/template/output-arn.rb +6 -3
  41. data/template/output-autoscaling.rb +7 -2
  42. data/template/output-dynamodb.rb +7 -2
  43. data/template/output-ec2-subnet.rb +14 -0
  44. data/template/output-ec2.rb +13 -4
  45. data/template/output-elasticache.rb +23 -7
  46. data/template/output-elasticbeanstalk-environment.rb +8 -0
  47. data/template/output-elb.rb +13 -6
  48. data/template/output-emr.rb +8 -3
  49. data/template/output-iam-instance-profile.rb +7 -2
  50. data/template/output-iam-role.rb +7 -2
  51. data/template/output-name.rb +3 -1
  52. data/template/output-rds.rb +7 -3
  53. data/template/output-redshift.rb +7 -3
  54. data/template/output-s3.rb +11 -3
  55. data/template/output-security-group.rb +4 -1
  56. data/template/output-sqs.rb +4 -1
  57. data/template/output-topic.rb +8 -3
  58. data/template/output-vpc.rb +16 -4
  59. data/template/output.rb +3 -1
  60. data/template/rds-db-instance.rb +7 -0
  61. data/template/redshift-cluster.rb +2 -0
  62. data/template/sqs-queue.rb +14 -0
  63. data/test/abstract_unit.rb +31 -8
  64. data/test/elasticbeanstalk_test.rb +3 -3
  65. data/test/helper_test.rb +431 -0
  66. data/test/template/autoscaling-launch-configuration_test.rb +1 -4
  67. data/test/template/ec2-instance_test.rb +2 -2
  68. data/test/template/ec2-vpc_test.rb +2 -2
  69. data/test/template/ecs-task-definition_test.rb +13 -13
  70. data/test/template/elasticbeanstalk-application-version_test.rb +13 -3
  71. data/test/template/elasticbeanstalk-template_test.rb +1 -1
  72. data/test/template/iam-instance-profile_test.rb +20 -0
  73. data/test/template/lambda-function_test.rb +60 -4
  74. data/test/template/{output-az_test.rb → output-ec2-subet_test.rb} +7 -8
  75. data/test/template/output-elasticache_test.rb +18 -0
  76. data/test/template/output_test.rb +23 -0
  77. data/test/template/rds-db-instance_test.rb +1 -1
  78. metadata +22 -22
  79. data/lib/kumogata/template/ext/argument_parser.rb +0 -8
  80. data/template/output-az.rb +0 -6
@@ -1,11 +1,13 @@
1
- require 'kumogata'
2
- require 'kumogata/argument_parser'
1
+ require 'kumogata2'
2
+ require 'kumogata2/cli/option_parser'
3
+ require 'kumogata2/logger'
4
+ require 'kumogata2/plugin/ruby'
3
5
 
4
- class Kumogata::Client
6
+ class Kumogata2::Client
5
7
  def init(stack_name)
6
8
  begin
7
9
  base_template = ''
8
- File.open(get_template_path('_template'), 'r'){|f|
10
+ File.open(Kumogata2::Client::get_template_path('_template'), 'r'){|f|
9
11
  base_template = f.read
10
12
  }
11
13
  raise 'initialize template is empty' if base_template.empty?
@@ -21,16 +23,71 @@ class Kumogata::Client
21
23
  template = base_template.gsub('#{NAME}', stack_name)
22
24
  f.write(template)
23
25
  }
24
- Kumogata.logger.info("Saved template to #{stack_name}.rb".green)
26
+ Kumogata2::Logger::Helper.log(:info, "Saved template to #{stack_name}.rb".green)
25
27
  rescue => e
26
- Kumogata.logger.info("Failed to template #{stack_name} - #{e}".red)
28
+ Kumogata2::Logger::Helper.log(:error, "Failed to template #{stack_name} - #{e}".red)
27
29
  end
28
30
  nil
29
31
  end
30
32
 
33
+ def self.get_template_path(file = nil)
34
+ template_path = File.expand_path(File.join(File.dirname(__FILE__),
35
+ '..', '..', '..','..', 'template'))
36
+ template_path = File.join(template_path, "#{file}.rb") unless file.nil?
37
+ template_path
38
+ end
39
+ end
40
+
41
+ class Kumogata2::Plugin::Ruby
42
+ def parse(str)
43
+ str = <<EOS
44
+ template do
45
+ #{str}
46
+ end
47
+ EOS
48
+ context = Kumogata2::Plugin::Ruby::Context.new(@options)
49
+ context.instance_eval(str, @options.path_or_url)
50
+ @post = context.instance_variable_get(:@_post)
51
+ context.instance_variable_get(:@_template)
52
+ end
53
+ end
54
+
55
+ class Kumogata2::Plugin::Ruby::Context
56
+ def template(&block)
57
+ key_converter = proc do |key|
58
+ key = key.to_s
59
+ unless @options.skip_replace_underscore?
60
+ key.gsub!('__', '::')
61
+ key.gsub!('_', ':')
62
+ end
63
+ key
64
+ end
65
+
66
+ value_converter = proc do |v|
67
+ case v
68
+ when Hash, Array
69
+ v
70
+ else
71
+ v.to_s
72
+ end
73
+ end
74
+
75
+ @_template = Dslh.eval({
76
+ key_conv: key_converter,
77
+ value_conv: value_converter,
78
+ scope_hook: proc {|scope|
79
+ define_template_func(scope, @options.path_or_url)
80
+ },
81
+ filename: @options.path_or_url,
82
+ ignore_methods: IGNORE_METHODS,
83
+ }, &block)
84
+ end
85
+
86
+ private
87
+
31
88
  def define_template_func(scope, path_or_url)
32
89
  functions = ''
33
- Dir.glob(File.join(get_template_path, '*.rb')).all? do |file|
90
+ Dir.glob(File.join(Kumogata2::Client::get_template_path, '*.rb')).all? do |file|
34
91
  functions << include_func(path_or_url, file)
35
92
  functions << "\n\n"
36
93
  end
@@ -71,9 +128,6 @@ class Kumogata::Client
71
128
  EOS
72
129
  end
73
130
 
74
-
75
- private ###########################################################
76
-
77
131
  def include_func(path_or_url, file)
78
132
  <<-EOS
79
133
  def _#{get_funcname(file)}(name, args = {})
@@ -93,10 +147,4 @@ class Kumogata::Client
93
147
  def get_funcname(file)
94
148
  File.basename(file, '.rb').gsub('-', '_')
95
149
  end
96
-
97
- def get_template_path(file = nil)
98
- template_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..','..', 'template'))
99
- template_path = File.join(template_path, "#{file}.rb") unless file.nil?
100
- template_path
101
- end
102
150
  end
@@ -52,16 +52,30 @@ def _valid_numbers(value, min = 0, max = 0, default = nil)
52
52
  end
53
53
 
54
54
  def _real_name(name)
55
- name.to_s.gsub(' ', '-')
55
+ name.to_s.gsub(" ", "-")
56
+ end
57
+
58
+ def _ref_key?(name, args, ref_name = '')
59
+ return true if args.key? "import_#{name}".to_sym
60
+ return true if args.key? "ref_#{name}".to_sym
61
+ return true unless args[name.to_sym].to_s.empty?
62
+ false
56
63
  end
57
64
 
58
65
  def _ref_string(name, args, ref_name = '')
66
+ return _import(args["import_#{name}".to_sym]) if args.key? "import_#{name}".to_sym
59
67
  return args[name.to_sym].to_s || '' unless args.key? "ref_#{name}".to_sym
60
68
 
61
- _{ Ref _resource_name(args["ref_#{name}".to_sym].to_s, ref_name) }
69
+ _ref(_resource_name(args["ref_#{name}".to_sym].to_s, ref_name))
70
+ end
71
+
72
+ def _ref_string_default(name, args, ref_name = '', default = '')
73
+ ref_string = _ref_string(name, args, ref_name)
74
+ ref_string.empty? ? default : ref_string
62
75
  end
63
76
 
64
77
  def _ref_array(name, args, ref_name = '')
78
+ return args["import_#{name}".to_sym].collect{|v| _import(v) } if args.key? "import_#{name}".to_sym
65
79
  return _array(args[name.to_sym]) || [] unless args.key? "ref_#{name}".to_sym
66
80
 
67
81
  array = []
@@ -69,7 +83,7 @@ def _ref_array(name, args, ref_name = '')
69
83
  array << _ref_string(name, args, ref_name)
70
84
  else
71
85
  args["ref_#{name}".to_sym].collect{|v|
72
- array << _{ Ref _resource_name(v, ref_name) }
86
+ array << _ref(_resource_name(v, ref_name))
73
87
  }
74
88
  end
75
89
  array
@@ -77,9 +91,7 @@ end
77
91
 
78
92
  def _ref_attr_string(name, attr, args, ref_name = '')
79
93
  if args.key? "ref_#{name}".to_sym
80
- _{
81
- Fn__GetAtt [ _resource_name(args["ref_#{name}".to_sym], ref_name), attr ]
82
- }
94
+ _attr_string(args["ref_#{name}".to_sym], attr, ref_name)
83
95
  elsif args.key? name.to_sym
84
96
  args[name.to_sym]
85
97
  else
@@ -88,32 +100,98 @@ def _ref_attr_string(name, attr, args, ref_name = '')
88
100
  end
89
101
 
90
102
  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
103
+ return _ref(_resource_name(args["ref_raw_#{name}".to_sym], ref_name)) if args.key? "ref_raw_#{name}".to_sym
92
104
  return args["raw_#{name}".to_sym] if args.key? "raw_#{name}".to_sym
105
+ return _import(args["import_#{name}".to_sym]) if args.key? "import_#{name}".to_sym
106
+
93
107
  name = _ref_string(name, args, ref_name)
94
108
  if name.empty?
95
- _{ Fn__Join "-", [ _{ Ref _resource_name("service") }, _{ Ref _resource_name("name") } ] }
109
+ _join([ _ref(_resource_name("service")), _ref(_resource_name("name")) ], "-")
96
110
  elsif name.is_a? Hash
97
- _{ Fn__Join "-", [ _{ Ref _resource_name("service") }, name ] }
111
+ _join([ _ref(_resource_name("service")), name ], "-")
98
112
  else
99
- name.gsub(' ', '-')
113
+ name.gsub(" ", "-")
100
114
  end
101
115
  end
102
116
 
103
117
  def _ref_name_default(name, args, ref_name = '')
104
118
  return args["raw_#{name}".to_sym] if args.key? "raw_#{name}".to_sym
105
119
  name = _ref_string(name, args, ref_name)
106
- name.empty? ? args[:name] : name.gsub(' ', '-')
120
+ name.empty? ? args[:name] : name.gsub(" ", "-")
107
121
  end
108
122
 
109
123
  def _ref_resource_name(args, ref_name = '')
110
- _{ Ref _resource_name(args[:name], ref_name) }
124
+ _ref(_resource_name(args[:name], ref_name))
125
+ end
126
+
127
+ def _ref_arn(service, name)
128
+ _join([ "arn:aws:#{service}:::", _ref(_resource_name(name)) ], ",")
129
+ end
130
+
131
+ def _ref_pseudo(type)
132
+ pseudo =
133
+ case type
134
+ when "account"
135
+ "AccountId"
136
+ when "notification arns"
137
+ "NotificationARNs"
138
+ when "no value"
139
+ "NoValue"
140
+ when "region"
141
+ "Region"
142
+ when "stack id"
143
+ "StackId"
144
+ when "stack name"
145
+ "StackName"
146
+ end
147
+ _ref("AWS::#{pseudo}")
148
+ end
149
+
150
+ def _ref(name)
151
+ _{ Ref name }
152
+ end
153
+
154
+ def _azs(region)
155
+ _{ Fn__GetAZs region }
111
156
  end
112
157
 
113
158
  def _attr_string(name, attr, ref_name = '')
114
159
  _{ Fn__GetAtt [ _resource_name(name, ref_name), attr ] }
115
160
  end
116
161
 
162
+ def _and(conditions)
163
+ _{ Fn__And conditions }
164
+ end
165
+
166
+ def _equals(value1, value2)
167
+ _{ Fn__Equals [ value1, value2 ] }
168
+ end
169
+
170
+ def _if(name, value_if_true, value_if_false)
171
+ _{ Fn__If [ name, value_if_true, value_if_false ] }
172
+ end
173
+
174
+ def _not(conditions)
175
+ _{ Fn__Not conditions }
176
+ end
177
+
178
+ def _or(conditions)
179
+ _{ Fn__Or conditions }
180
+ end
181
+
182
+ def _condition(condition)
183
+ _{ Condition condition }
184
+ end
185
+
186
+ def _base64(data)
187
+ data = data.undent if data.is_a? String
188
+ _{ Fn__Base64 data }
189
+ end
190
+
191
+ def _base64_shell(data, shell = "/bin/bash")
192
+ _base64("#!#{shell}\n#{data}")
193
+ end
194
+
117
195
  def _find_in_map(name, top_level, secondary_level)
118
196
  _{ Fn__FindInMap [ name, top_level, secondary_level ] }
119
197
  end
@@ -122,12 +200,53 @@ def _select(index, list)
122
200
  _{ Fn__Select [ index.to_s, list ] }
123
201
  end
124
202
 
203
+ def _split(name, delimiter = ",")
204
+ _{
205
+ Fn__Split [ delimiter, name ]
206
+ }
207
+ end
208
+
209
+ def _sub(name)
210
+ _{ Fn__Sub name }
211
+ end
212
+
213
+ def _export_string(args, prefix)
214
+ if args.key? :export and args[:export] == true
215
+ "#{args[:name]}-#{prefix}"
216
+ else
217
+ ""
218
+ end
219
+ end
220
+
221
+ def _export(args)
222
+ export = args[:export] || ''
223
+ return '' if export.empty?
224
+
225
+ _{
226
+ Name _sub("${AWS::StackName}-#{export.gsub(" ", "-")}")
227
+ }
228
+ end
229
+
230
+ def _join(args, delimiter = ",")
231
+ _{ Fn__Join delimiter, args }
232
+ end
233
+
234
+ def _import(name)
235
+ _{
236
+ Fn__ImportValue _sub(name)
237
+ }
238
+ end
239
+
240
+ def _region
241
+ _ref("AWS::Region")
242
+ end
243
+
125
244
  def _tag(args)
126
245
  key = args[:key].to_s || ''
127
246
  value = args[:value] || ''
128
247
  if key =~ /^ref_.*/
129
248
  key.gsub!(/^ref_/, '')
130
- value = _{ Ref _resource_name(value) }
249
+ value = _ref(_resource_name(value))
131
250
  end
132
251
 
133
252
  _{
@@ -144,11 +263,11 @@ def _tags(args)
144
263
  },
145
264
  _{
146
265
  Key "Service"
147
- Value { Ref _resource_name("service") }
266
+ Value _ref(_resource_name("service"))
148
267
  },
149
268
  _{
150
269
  Key "Version"
151
- Value { Ref _resource_name("version") }
270
+ Value _ref(_resource_name("version"))
152
271
  },
153
272
  ]
154
273
  args[:tags_append].collect{|k, v| tags << _tag(key: k, value: v) } if args.key? :tags_append
@@ -156,15 +275,15 @@ def _tags(args)
156
275
  end
157
276
 
158
277
  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
278
+ return _ref(_resource_name(args["ref_raw_tag_name".to_sym])) if args.key? "ref_raw_tag_name".to_sym
160
279
  return args["raw_tag_name".to_sym] if args.key? "raw_tag_name".to_sym
161
280
 
162
281
  tag_name = _ref_string("tag_name", args)
163
282
  return tag_name unless tag_name.empty?
164
283
 
165
284
  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 ] ] }
285
+ tag_name = tag_name.gsub(" ", "-") if tag_name.is_a? String
286
+ _join([ _ref(_resource_name(args[:tag_service] || "service")), tag_name ], "-")
168
287
  end
169
288
 
170
289
  def _availability_zone(args, use_subnet = true)
@@ -196,7 +315,7 @@ def _availability_zones(args, use_subnet = true)
196
315
  elsif args.key? :ref_az
197
316
  [ _ref_string("az", zone, "zone") ]
198
317
  else
199
- _{ Fn__GetAZs _{ Ref "AWS::Region" } }
318
+ _azs(_region)
200
319
  end
201
320
  end
202
321
 
@@ -215,6 +334,14 @@ def _timestamp_utc_from_string(time, type= nil)
215
334
  _timestamp_utc(Time.strptime(time, "%Y-%m-%d %H:%M"), type)
216
335
  end
217
336
 
337
+ def _timestamp_utc_duration(minute, hour = nil, second = nil)
338
+ duration = "PT"
339
+ duration += "#{hour}H" unless hour.nil?
340
+ duration += "#{minute}M"
341
+ duration += "#{second}S" unless second.nil?
342
+ duration
343
+ end
344
+
218
345
  def _maintenance_window(service, start_time)
219
346
  start_time = start_time.utc
220
347
  format = "%a:%H:%M"
@@ -47,7 +47,6 @@ def _iam_to_policy_condition(args)
47
47
  end
48
48
  condition[key] = value
49
49
  end
50
-
51
50
  condition
52
51
  end
53
52
 
@@ -212,7 +211,7 @@ def _iam_arn(service, resource)
212
211
  "#{arn_prefix_s3}#{resource}"
213
212
 
214
213
  elsif resource.is_a? Hash
215
- _{ Fn__Join "", [ arn_prefix_s3, _convert(resource) ] }
214
+ _join([ arn_prefix_s3, _convert(resource) ], "")
216
215
 
217
216
  else
218
217
  array, array_map = [], []
@@ -232,7 +231,7 @@ def _iam_arn(service, resource)
232
231
  if array.select{|v| v.is_a? Hash }.empty?
233
232
  array.collect{|v| "#{arn_prefix_s3}#{v}" }
234
233
  else
235
- _{ Fn__Join "", array.insert(0, arn_prefix_s3) }
234
+ _join(array.insert(0, arn_prefix_s3), "")
236
235
  end
237
236
  end
238
237
 
@@ -23,7 +23,7 @@ def _lambda_function_code(args)
23
23
  S3Bucket s3_bucket if is_s3
24
24
  S3Key s3_key if is_s3
25
25
  S3ObjectVersion s3_object_version if is_s3 and !s3_object_version.empty?
26
- ZipFile _{ Fn__Join '\n', zip_file_code } unless is_s3
26
+ ZipFile _join(zip_file_code, '\n') unless is_s3
27
27
  }
28
28
  end
29
29
 
@@ -45,3 +45,12 @@ def _lambda_vpc_config(args)
45
45
  SubnetIds subnet_ids unless subnet_ids.empty?
46
46
  }
47
47
  end
48
+
49
+ def _lambda_dead_letter(args)
50
+ return "" unless args.key? :dead_latter
51
+
52
+ dead_letter = _ref_string("dead_letter", args)
53
+ _{
54
+ TargetArn dead_letter
55
+ }
56
+ end
@@ -1 +1 @@
1
- KUMOGATA_TEMPLATE_VERSION = '0.0.29'
1
+ KUMOGATA_TEMPLATE_VERSION = '0.0.30'
@@ -1,25 +1,42 @@
1
+ require 'aws-sdk'
2
+
1
3
  AWSTemplateFormatVersion "2010-09-09"
2
4
 
3
5
  Description (<<-EOS).undent
4
6
  Kumogata Template - #{NAME} stack
5
7
  EOS
6
8
 
9
+ Metadata do
10
+ end
11
+
7
12
  Parameters do
13
+ _parameter "stack name", default: "",
14
+ description: "the name of this stack"
8
15
  _parameter "name", default: "#{NAME}",
9
16
  description: "name of this stack"
10
17
  _parameter "service", default: "service",
11
18
  description: "#{NAME} service"
12
- _parameter "version", default: "1.0.0",
19
+ _parameter "version", default: "0.0.1",
13
20
  description: "#{NAME} version"
14
21
  end
15
22
 
16
23
  Mappings do
17
24
  end
18
25
 
26
+ Conditions do
27
+ end
28
+
29
+ Transform do
30
+ end
31
+
19
32
  Resources do
20
- _s3_bucket "#{NAME}"
33
+ # And more kumogata-template examples at examples/
34
+
35
+ # Create a S3 Bucket
36
+ #_s3_bucket "#{NAME}"
21
37
  end
22
38
 
23
39
  Outputs do
24
- _output_s3 "#{NAME}"
40
+ # Output S3 Bucket Information
41
+ #_output_s3 "#{NAME}"
25
42
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # ALB(ElasticLoadBalancingV2) LoadBalancer resource
2
+ # ALB(ElasticLoadBalancingV2) loadbalancer resource
3
3
  # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-loadbalancer.html
4
4
  #
5
5
  require 'kumogata/template/helper'
@@ -13,6 +13,12 @@ scheme = _valid_values("scheme", %w( internal internal-facing ), "")
13
13
  security_groups = _ref_array("security_groups", args, "security group")
14
14
  subnets = _ref_array("subnets", args, "subnet")
15
15
  tags = _tags(args)
16
+ ip_address =
17
+ if args.key? :ip_address
18
+ _valid_values("ip_address", %w( ipv4 dualstack ), "ipv4")
19
+ else
20
+ ""
21
+ end
16
22
 
17
23
  _(name) do
18
24
  Type "AWS::ElasticLoadBalancingV2::LoadBalancer"
@@ -23,5 +29,6 @@ _(name) do
23
29
  SecurityGroups security_groups
24
30
  Subnets subnets unless subnets.empty?
25
31
  Tags tags
32
+ IpAddressType ip_address unless ip_address.empty?
26
33
  end
27
34
  end
@@ -19,7 +19,7 @@ placement = _ref_string("placement", args)
19
19
  ram = args[:ram] || ""
20
20
  security_groups = _ref_array("security_groups", args, "security group")
21
21
  spot = args[:spot] || ""
22
- user_data = _ref_string("user_data", args, "user data")
22
+ user_data = _ec2_user_data(args)
23
23
 
24
24
  _(name) do
25
25
  Type "AWS::AutoScaling::LaunchConfiguration"
@@ -40,15 +40,6 @@ _(name) do
40
40
  RamDiskId ram unless ram.empty?
41
41
  SecurityGroups security_groups unless security_groups.empty?
42
42
  SpotPrice spot unless spot.empty?
43
- UserData do
44
- if user_data.is_a? Hash
45
- Fn__Base64 user_data
46
- else
47
- Fn__Base64 (<<-EOS).undent
48
- #!/bin/bash
49
- #{user_data}
50
- EOS
51
- end
52
- end
43
+ UserData user_data unless user_data.empty?
53
44
  end
54
45
  end
@@ -3,6 +3,7 @@
3
3
  # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-as-scheduledaction.html
4
4
  #
5
5
  require 'kumogata/template/helper'
6
+ require 'kumogata/template/autoscaling'
6
7
 
7
8
  name = _resource_name(args[:name], "autoscaling scheduled action")
8
9
  autoscaling = _ref_string("autoscaling", args, "autoscaling group")
@@ -18,25 +19,9 @@ max = _integer("max", args, -1)
18
19
  max = desired if max < desired
19
20
  min = _integer("min", args, -1)
20
21
  min = desired if min < desired
21
-
22
22
  recurrence =
23
23
  if args.key? :recurrence
24
- case args[:recurrence]
25
- when "every 5 min"
26
- "*/5 * * * *"
27
- when "every 30 min"
28
- "0,30 * * * *"
29
- when "every 1 hour"
30
- "0 * * * *"
31
- when "every day"
32
- "0 0 * * *"
33
- when "every week"
34
- "0 0 * * Tue"
35
- when /\*/
36
- args[:recurrence]
37
- else
38
- _timestamp_utc(args[:recurrence], "cron")
39
- end
24
+ _autoscaling_to_schedued_recurrence(args[:recurrence])
40
25
  else
41
26
  ""
42
27
  end
@@ -15,6 +15,7 @@ host_id = args[:host_id] || ""
15
15
  iam_instance = _ref_string("iam_instance", args, "iam instance profile")
16
16
  image =_ec2_image(instance_type, args)
17
17
  instance_initiated = args[:instance_initiated] || "stop"
18
+ ipv6_addresses = args[:ipv6_addresses] || []
18
19
  kernel = args[:kernel] || ""
19
20
  key_name = _ref_string("key_name", args, "key name")
20
21
  monitoring = _bool("monitoring", args, true)
@@ -28,7 +29,7 @@ ssm = args[:ssm] || []
28
29
  subnet = _ref_string("subnet", args, "subnet")
29
30
  tags = _ec2_tags(args)
30
31
  tenancy = args[:tenancy] || "default"
31
- user_data = _ref_string("user_data", args, "user data")
32
+ user_data = _ec2_user_data(args)##_ref_string("user_data", args, "user data")
32
33
  volumes = args[:volumes] || ""
33
34
 
34
35
  _(name) do
@@ -44,6 +45,8 @@ _(name) do
44
45
  ImageId image
45
46
  InstanceInitiatedShutdownBehavior instance_initiated
46
47
  InstanceType instance_type
48
+ Ipv6AddressCount ipv6_addresses.size unless ipv6_addresses.empty?
49
+ Ipv6Addresses ipv6_addresses unless ipv6_addresses.empty?
47
50
  KernelId kernel unless kernel.empty?
48
51
  KeyName key_name
49
52
  Monitoring monitoring
@@ -58,12 +61,7 @@ _(name) do
58
61
  SubnetId subnet unless subnet.empty?
59
62
  Tags tags
60
63
  Tenancy tenancy unless tenancy.empty?
61
- UserData do
62
- Fn__Base64 (<<-EOS).undent
63
- #!/bin/bash
64
- #{user_data}
65
- EOS
66
- end
64
+ UserData user_data unless user_data.empty?
67
65
  Volumes volumes unless volumes.empty?
68
66
  end
69
67
  end
@@ -7,6 +7,7 @@ require 'kumogata/template/ec2'
7
7
 
8
8
  name = _resource_name(args[:name], "network acl entry")
9
9
  cidr = args[:cidr] || "0.0.0.0/0"
10
+ cidr_ipv6 = args[:cidr_ipv6] || ""
10
11
  egress = _bool("egress", args, false)
11
12
  icmp = args[:icmp] || ""
12
13
  network_acl = _ref_attr_string("vpc_network_acl", "DefaultNetworkAcl", args, "vpc")
@@ -19,7 +20,8 @@ rule_number = _valid_numbers(args[:number], 1, 32766, 100)
19
20
  _(name) do
20
21
  Type "AWS::EC2::NetworkAclEntry"
21
22
  Properties do
22
- CidrBlock cidr
23
+ CidrBlock cidr if cidr_ipv6.empty?
24
+ Ipv6CidrBlock ipv6_cidr if cidr.empty?
23
25
  Egress egress
24
26
  Icmp _{
25
27
  Code -1
@@ -6,6 +6,7 @@ require 'kumogata/template/helper'
6
6
 
7
7
  name = _resource_name(args[:name], "route")
8
8
  destination_cidr = args[:destination_cidr] || "0.0.0.0/0"
9
+ destination_cidr_ipv6 = args[:destination_cidr_ipv6] || ""
9
10
  gateway = _ref_string("gateway", args, "internet gateway")
10
11
  instance = _ref_string("instance", args, "intance")
11
12
  nat_gateway = _ref_string("nat_gateway", args, "nat gateway")
@@ -16,7 +17,8 @@ vpc_peering_connection = _ref_string("vpc_peering_connection", args)
16
17
  _(name) do
17
18
  Type "AWS::EC2::Route"
18
19
  Properties do
19
- DestinationCidrBlock destination_cidr
20
+ DestinationCidrBlock destination_cidr if destination_cidr_ipv6.empty?
21
+ DestinationIpv6CidrBlock destination_cidr_ipv6 if destination_cidr.empty?
20
22
  GatewayId gateway unless gateway.empty?
21
23
  InstanceId instance unless instance.empty?
22
24
  NatGatewayId nat_gateway unless nat_gateway.empty?
@@ -6,6 +6,7 @@ require 'kumogata/template/helper'
6
6
  require 'kumogata/template/ec2'
7
7
 
8
8
  name = _resource_name(args[:name], "security group")
9
+ group_name = _real_name(args[:group_name] || "")
9
10
  description = args[:description] || "#{args[:name]} security group description"
10
11
  egress = _ec2_security_group_egresses("egress", args)
11
12
  ingress = _ec2_security_group_ingresses("ingress", args)
@@ -15,6 +16,7 @@ vpc = _ref_string("vpc", args, "vpc")
15
16
  _(name) do
16
17
  Type "AWS::EC2::SecurityGroup"
17
18
  Properties do
19
+ GroupName group_name unless group_name.empty?
18
20
  GroupDescription description
19
21
  SecurityGroupEgress egress unless egress.empty?
20
22
  SecurityGroupIngress ingress unless ingress.empty?
@@ -6,7 +6,8 @@ require 'kumogata/template/helper'
6
6
 
7
7
  name = _resource_name(args[:name], "subnet")
8
8
  az = _availability_zone(args, false)
9
- cidr = args[:cidr] || "10.1.0.0/24"
9
+ cidr = _ref_string("cidr", args)
10
+ cidr = "10.1.0.0/24" if cidr.empty?
10
11
  map_public_ip_on_launch = _bool("map_public_ip_on_launch", args, true)
11
12
  tags = _tags(args)
12
13
  vpc = _ref_string("vpc", args, "vpc")
data/template/ec2-vpc.rb CHANGED
@@ -5,7 +5,8 @@
5
5
  require 'kumogata/template/helper'
6
6
 
7
7
  name = _resource_name(args[:name], "vpc")
8
- cidr = args[:cidr] || "191.168.1.0/16"
8
+ cidr = _ref_string("cidr", args)
9
+ cidr = "10.1.1.0/28" if cidr.empty?
9
10
  dns_support = _bool("dns_support", args, true)
10
11
  dns_hostnames = args[:dns_hostnames] || dns_support
11
12
  instance_tenancy = _valid_values(args[:instance_tenancy],