kumogata-template 0.0.35 → 0.0.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +4 -2
  3. data/Gemfile +1 -1
  4. data/Rakefile +1 -1
  5. data/kumogata-template.gemspec +4 -4
  6. data/lib/kumogata/template/alb.rb +48 -34
  7. data/lib/kumogata/template/api-gateway.rb +262 -0
  8. data/lib/kumogata/template/autoscaling.rb +17 -44
  9. data/lib/kumogata/template/certificate.rb +11 -8
  10. data/lib/kumogata/template/cloudfront.rb +67 -60
  11. data/lib/kumogata/template/cloudwatch.rb +7 -12
  12. data/lib/kumogata/template/codebuild.rb +4 -8
  13. data/lib/kumogata/template/codecommit.rb +2 -6
  14. data/lib/kumogata/template/codedeploy.rb +15 -0
  15. data/lib/kumogata/template/cognito.rb +203 -0
  16. data/lib/kumogata/template/const.rb +109 -47
  17. data/lib/kumogata/template/datapipeline.rb +16 -47
  18. data/lib/kumogata/template/dynamodb.rb +17 -8
  19. data/lib/kumogata/template/ec2.rb +61 -10
  20. data/lib/kumogata/template/ecr.rb +11 -9
  21. data/lib/kumogata/template/ecs.rb +256 -91
  22. data/lib/kumogata/template/elasticbeanstalk.rb +6 -9
  23. data/lib/kumogata/template/elb.rb +9 -24
  24. data/lib/kumogata/template/emr.rb +184 -51
  25. data/lib/kumogata/template/events.rb +22 -10
  26. data/lib/kumogata/template/ext/kumogata.rb +7 -7
  27. data/lib/kumogata/template/helper.rb +189 -130
  28. data/lib/kumogata/template/iam.rb +556 -146
  29. data/lib/kumogata/template/kinesis.rb +282 -0
  30. data/lib/kumogata/template/lambda.rb +43 -2
  31. data/lib/kumogata/template/logs.rb +2 -6
  32. data/lib/kumogata/template/nlb.rb +10 -0
  33. data/lib/kumogata/template/pinpoint.rb +83 -0
  34. data/lib/kumogata/template/rds.rb +52 -0
  35. data/lib/kumogata/template/redshift.rb +15 -6
  36. data/lib/kumogata/template/role.rb +425 -0
  37. data/lib/kumogata/template/s3.rb +120 -80
  38. data/lib/kumogata/template/sns.rb +2 -6
  39. data/lib/kumogata/template/version.rb +1 -1
  40. data/lib/kumogata/template.rb +9 -1
  41. data/template/_template.rb +2 -2
  42. data/template/alb-load-balancer.rb +5 -4
  43. data/template/alb-target-group.rb +8 -9
  44. data/template/api-gateway-account.rb +15 -0
  45. data/template/api-gateway-api-key.rb +22 -0
  46. data/template/api-gateway-authorizer.rb +38 -0
  47. data/template/api-gateway-base-path-mapping.rb +23 -0
  48. data/template/api-gateway-client-certificate.rb +16 -0
  49. data/template/api-gateway-deployment.rb +24 -0
  50. data/template/api-gateway-domain-name.rb +17 -0
  51. data/template/api-gateway-method.rb +71 -0
  52. data/template/api-gateway-model.rb +23 -0
  53. data/template/api-gateway-resource.rb +32 -0
  54. data/template/api-gateway-rest-api.rb +29 -0
  55. data/template/api-gateway-stage.rb +33 -0
  56. data/template/api-gateway-usage-plan-key.rb +19 -0
  57. data/template/api-gateway-usage-plan.rb +24 -0
  58. data/template/autoscaling-group.rb +2 -2
  59. data/template/autoscaling-launch-configuration.rb +7 -4
  60. data/template/autoscaling-scheduled-action.rb +0 -1
  61. data/template/certificate.rb +2 -2
  62. data/template/cloudfront-distribution.rb +4 -0
  63. data/template/cloudfront-origin-access-identity.rb +19 -0
  64. data/template/cloudtrail.rb +6 -4
  65. data/template/cloudwatch-alarm.rb +9 -3
  66. data/template/codebuild-project.rb +3 -3
  67. data/template/codecommit-repository.rb +2 -2
  68. data/template/codedeploy-application.rb +1 -1
  69. data/template/codedeploy-deployment-config.rb +1 -1
  70. data/template/codedeploy-deployment-group.rb +2 -0
  71. data/template/cognito-identity-pool.rb +34 -0
  72. data/template/cognito-identity-role-attachment.rb +22 -0
  73. data/template/cognito-user-pool-client.rb +28 -0
  74. data/template/cognito-user-pool-group.rb +24 -0
  75. data/template/cognito-user-pool-user-to-group-attachment.rb +20 -0
  76. data/template/cognito-user-pool-user.rb +28 -0
  77. data/template/cognito-user-pool.rb +45 -0
  78. data/template/datapipeline-pipeline.rb +4 -4
  79. data/template/dynamodb-table.rb +5 -1
  80. data/template/ec2-eip-association.rb +1 -1
  81. data/template/ec2-instance.rb +4 -1
  82. data/template/ec2-nat-gateway.rb +4 -0
  83. data/template/ec2-route.rb +4 -0
  84. data/template/ec2-security-group-ingress.rb +1 -1
  85. data/template/ec2-security-group.rb +2 -2
  86. data/template/ec2-subnet.rb +8 -4
  87. data/template/ec2-volume.rb +1 -2
  88. data/template/ec2-vpc-cidr-block.rb +4 -2
  89. data/template/ec2-vpc-endpoint.rb +5 -2
  90. data/template/ecr-repository.rb +2 -2
  91. data/template/ecs-cluster.rb +1 -1
  92. data/template/ecs-service.rb +19 -7
  93. data/template/ecs-task-definition.rb +4 -4
  94. data/template/elasticache-cache-cluster.rb +1 -1
  95. data/template/elasticache-parameter-group.rb +1 -1
  96. data/template/elasticache-replication-group.rb +1 -1
  97. data/template/elasticache-subnet-group.rb +1 -1
  98. data/template/elasticbeanstalk-application-version.rb +1 -1
  99. data/template/elasticbeanstalk-application.rb +1 -1
  100. data/template/elasticbeanstalk-configuration-template.rb +1 -1
  101. data/template/elasticbeanstalk-environment.rb +1 -1
  102. data/template/elb-load-balancer.rb +2 -2
  103. data/template/emr-cluster.rb +3 -3
  104. data/template/emr-instance-group-config.rb +4 -2
  105. data/template/emr-security-configuration.rb +17 -0
  106. data/template/emr-step.rb +2 -2
  107. data/template/events-rule.rb +8 -8
  108. data/template/iam-group.rb +2 -2
  109. data/template/iam-instance-profile.rb +2 -2
  110. data/template/iam-managed-policy.rb +1 -1
  111. data/template/iam-policy.rb +1 -1
  112. data/template/iam-role.rb +17 -2
  113. data/template/iam-user.rb +4 -4
  114. data/template/kinesis-firehose-delivery-stream.rb +36 -0
  115. data/template/kinesis-stream.rb +21 -0
  116. data/template/kms-alias.rb +2 -2
  117. data/template/kms-key.rb +1 -1
  118. data/template/lambda-alias.rb +2 -2
  119. data/template/lambda-event-source-mapping.rb +4 -4
  120. data/template/lambda-function.rb +17 -17
  121. data/template/lambda-permission.rb +31 -10
  122. data/template/lambda-version.rb +4 -2
  123. data/template/logs-destination.rb +1 -1
  124. data/template/logs-log-group.rb +1 -1
  125. data/template/logs-log-stream.rb +4 -2
  126. data/template/logs-metric-filter.rb +1 -1
  127. data/template/logs-subscription_filter.rb +1 -1
  128. data/template/mappings-ec2.rb +114 -52
  129. data/template/output-arn.rb +12 -4
  130. data/template/output-certificate.rb +11 -0
  131. data/template/output-distribution.rb +11 -0
  132. data/template/output-domain-name.rb +11 -0
  133. data/template/output-ecr-repository.rb +16 -0
  134. data/template/output-eip.rb +11 -0
  135. data/template/output-lambda-function.rb +6 -0
  136. data/template/output-name.rb +7 -2
  137. data/template/output-origin-access-identity.rb +13 -0
  138. data/template/output-rds-cluster.rb +17 -0
  139. data/template/{output-rds.rb → output-rds-instance.rb} +1 -1
  140. data/template/output-redshift.rb +11 -0
  141. data/template/output-rest-api.rb +11 -0
  142. data/template/output-s3.rb +3 -0
  143. data/template/output-stage.rb +19 -0
  144. data/template/output-subnet.rb +6 -3
  145. data/template/output-trail.rb +14 -0
  146. data/template/output-user-pool-client.rb +14 -0
  147. data/template/output-user-pool.rb +17 -0
  148. data/template/output-vpc.rb +13 -3
  149. data/template/output.rb +3 -2
  150. data/template/parameter-ec2.rb +10 -4
  151. data/template/parameter-elasticache.rb +1 -1
  152. data/template/parameter-rds.rb +51 -4
  153. data/template/parameter-redshift.rb +31 -1
  154. data/template/parameter.rb +87 -7
  155. data/template/rds-db-cluster-parameter-group.rb +18 -4
  156. data/template/rds-db-cluster.rb +19 -7
  157. data/template/rds-db-instance.rb +55 -131
  158. data/template/rds-db-parameter-group.rb +29 -3
  159. data/template/rds-db-subnet-group.rb +1 -1
  160. data/template/rds-event-subscription.rb +2 -4
  161. data/template/rds-option-group.rb +28 -5
  162. data/template/redshift-cluster-parameter-group.rb +3 -1
  163. data/template/redshift-cluster-security-group.rb +17 -0
  164. data/template/redshift-cluster-subnet-group.rb +3 -1
  165. data/template/redshift-cluster.rb +15 -12
  166. data/template/s3-bucket.rb +10 -5
  167. data/template/sns-topic.rb +2 -2
  168. data/template/sqs-queue.rb +1 -1
  169. data/test/abstract_unit.rb +2 -9
  170. data/test/cloudfront_test.rb +57 -28
  171. data/test/codedeploy_test.rb +21 -0
  172. data/test/datapipeline_test.rb +0 -22
  173. data/test/ec2_test.rb +12 -52
  174. data/test/ecs_test.rb +30 -26
  175. data/test/emr_test.rb +101 -20
  176. data/test/events_test.rb +47 -0
  177. data/test/helper_test.rb +251 -281
  178. data/test/iam_test.rb +572 -57
  179. data/test/lambda_test.rb +1 -1
  180. data/test/s3_test.rb +49 -14
  181. data/test/template/alb-load-balancer_test.rb +4 -5
  182. data/test/template/alb-target-group_test.rb +1 -3
  183. data/test/template/api-gateway-account_test.rb +26 -0
  184. data/test/template/api-gateway-api-key_test.rb +33 -0
  185. data/test/template/api-gateway-authorizer_test.rb +62 -0
  186. data/test/template/api-gateway-base-path-mapping_test.rb +27 -0
  187. data/test/template/api-gateway-client-certificate_test.rb +21 -0
  188. data/test/template/api-gateway-deployment_test.rb +27 -0
  189. data/test/template/api-gateway-domain-name_test.rb +26 -0
  190. data/test/template/api-gateway-method_test.rb +29 -0
  191. data/test/template/api-gateway-model_test.rb +37 -0
  192. data/test/template/api-gateway-resource_test.rb +82 -0
  193. data/test/template/api-gateway-rest-api_test.rb +33 -0
  194. data/test/template/api-gateway-stage_test.rb +39 -0
  195. data/test/template/api-gateway-usage-plan-key_test.rb +25 -0
  196. data/test/template/api-gateway-usage-plan_test.rb +42 -0
  197. data/test/template/cloudfront-distribution_test.rb +41 -3
  198. data/test/template/cloudtrail_test.rb +13 -5
  199. data/test/template/cloudwatch-alarm_test.rb +14 -2
  200. data/test/template/codebuild-project_test.rb +2 -11
  201. data/test/template/codecommit-repository_test.rb +12 -1
  202. data/test/template/cognito-identity-pool_test.rb +32 -0
  203. data/test/template/cognito-identity-role-attachment_test.rb +38 -0
  204. data/test/template/cognito-user-pool-client_test.rb +36 -0
  205. data/test/template/cognito-user-pool-group_test.rb +36 -0
  206. data/test/template/cognito-user-pool-user-to-group-attachment_test.rb +29 -0
  207. data/test/template/cognito-user-pool-user_test.rb +38 -0
  208. data/test/template/cognito-user-pool_test.rb +99 -0
  209. data/test/template/datapipeline-pipeline_test.rb +45 -6
  210. data/test/template/dynamodb-table_test.rb +19 -1
  211. data/test/template/ec2-instance_test.rb +9 -1
  212. data/test/template/ec2-nat-gateway_test.rb +29 -1
  213. data/test/template/ec2-security-group-egress_test.rb +1 -0
  214. data/test/template/ec2-security-group-ingress_test.rb +1 -0
  215. data/test/template/ec2-security-group_test.rb +11 -1
  216. data/test/template/ec2-spot-fleet_test.rb +1 -1
  217. data/test/template/ec2-subnet_test.rb +62 -1
  218. data/test/template/ec2-vpc-cidr-block_test.rb +1 -1
  219. data/test/template/ec2-vpc-endpoint_test.rb +56 -0
  220. data/test/template/ecr-repository_test.rb +63 -11
  221. data/test/template/ecs-service_test.rb +13 -2
  222. data/test/template/ecs-task-definition_test.rb +86 -13
  223. data/test/template/elasticache-cache-cluster_test.rb +4 -6
  224. data/test/template/elasticache-replication-group_test.rb +1 -1
  225. data/test/template/elasticbeanstalk-application-version_test.rb +1 -0
  226. data/test/template/elasticbeanstalk-application_test.rb +2 -1
  227. data/test/template/elasticbeanstalk-configuration-template_test.rb +2 -1
  228. data/test/template/elasticbeanstalk-template_test.rb +1 -0
  229. data/test/template/elb-load-balancer_test.rb +1 -3
  230. data/test/template/emr-cluster_test.rb +2 -14
  231. data/test/template/emr-instance-group-config_test.rb +2 -4
  232. data/test/template/emr-security-configuration_test.rb +34 -0
  233. data/test/template/emr-step_test.rb +2 -6
  234. data/test/template/events-rule_test.rb +3 -3
  235. data/test/template/iam-group_test.rb +11 -1
  236. data/test/template/iam-instance-profile_test.rb +11 -1
  237. data/test/template/iam-managed-policy_test.rb +1 -0
  238. data/test/template/iam-policy_test.rb +1 -3
  239. data/test/template/iam-role_test.rb +12 -2
  240. data/test/template/iam-user_test.rb +11 -17
  241. data/test/template/kinesis-firehorse-delivery-stream_test.rb +68 -0
  242. data/test/template/kinesis-stream_test.rb +61 -0
  243. data/test/template/kms-key_test.rb +1 -0
  244. data/test/template/lambda-alias_test.rb +2 -3
  245. data/test/template/lambda-event-source-mapping_test.rb +1 -1
  246. data/test/template/lambda-function_test.rb +20 -32
  247. data/test/template/lambda-permission_test.rb +7 -4
  248. data/test/template/lambda-version_test.rb +5 -2
  249. data/test/template/logs-log-group_test.rb +1 -3
  250. data/test/template/logs-log-stream_test.rb +2 -6
  251. data/test/template/logs-metric-filter_test.rb +1 -3
  252. data/test/template/logs-subscription-filter_test.rb +1 -3
  253. data/test/template/mappings-ec2_test.rb +10 -3
  254. data/test/template/output-domain-name_test.rb +30 -0
  255. data/test/template/output-name_test.rb +9 -0
  256. data/test/template/{output-rds_test.rb → output-rds-instance_test.rb} +2 -2
  257. data/test/template/output-rest-api_test.rb +30 -0
  258. data/test/template/output-s3_test.rb +9 -0
  259. data/test/template/output-stage_test.rb +43 -0
  260. data/test/template/output-user-pool-client_test.rb +39 -0
  261. data/test/template/output-user-pool_test.rb +48 -0
  262. data/test/template/output_test.rb +3 -1
  263. data/test/template/parameter-ec2_test.rb +22 -24
  264. data/test/template/parameter-elasticache_test.rb +2 -1
  265. data/test/template/parameter-rds_test.rb +32 -3
  266. data/test/template/parameter-redshift_test.rb +31 -2
  267. data/test/template/parameter_test.rb +37 -4
  268. data/test/template/rds-db-cluster-parameter-group_test.rb +1 -1
  269. data/test/template/rds-db-cluster_test.rb +4 -20
  270. data/test/template/rds-db-instance_test.rb +3 -373
  271. data/test/template/rds-db-parameter-group_test.rb +1 -1
  272. data/test/template/rds-option-group_test.rb +2 -2
  273. data/test/template/redshift-cluster-parameter-group_test.rb +28 -0
  274. data/test/template/redshift-cluster-security-group_test.rb +49 -0
  275. data/test/template/redshift-cluster-subnet-group_test.rb +28 -0
  276. data/test/template/redshift-cluster_test.rb +33 -5
  277. data/test/template/s3-bucket_test.rb +6 -20
  278. metadata +130 -22
@@ -3,134 +3,299 @@
3
3
  #
4
4
  require 'kumogata/template/helper'
5
5
 
6
+ def _ecs_to_log_option(args)
7
+ option =
8
+ case args[:driver]
9
+ when "awslogs"
10
+ _ecs_to_log_option_awslogs(args)
11
+ when "fluentd"
12
+ _ecs_to_log_option_fluentd(args)
13
+ when "syslog"
14
+ _ecs_to_log_option_syslog(args)
15
+ when "json"
16
+ _ecs_to_log_option_syslog(args)
17
+ when "splunk"
18
+ _ecs_to_log_option_splunk(args)
19
+ when "gelf"
20
+ _ecs_to_log_option_gelf(args)
21
+ else
22
+ {}
23
+ end
24
+ option.merge(_ecs_to_log_option_common(args))
25
+ end
26
+
27
+ def _ecs_to_log_option_awslogs(args)
28
+ {
29
+ "awslogs-group": args[:group],
30
+ "awslogs-region": args[:region] || _region,
31
+ "awslogs-stream-prefix": args[:prefix] || "",
32
+ }
33
+ end
34
+
35
+ def _ecs_to_log_option_fluentd(args)
36
+ option = {
37
+ "fluentd-address": args[:address] || "localhost:24224",
38
+ "fluentd-retry-wait": args[:retry_wait] || 1,
39
+ "fluentd-max-retries": args[:max_retries] || 10,
40
+ }
41
+ option["fluentd-async-connect"] = true if args.key? :async
42
+ option["fluentd-buffer-limit"] = args[:buffer_limit] if args.key? :buffer_limit
43
+ option
44
+ end
45
+
46
+ def _ecs_to_log_option_syslog(args)
47
+ option = {
48
+ "syslog-address": args[:address],
49
+ }
50
+ option["syslog-facility"] = args[:facility] if args.key? :facility
51
+ option["syslog-tls-ca-cert"] = args[:ca_cert] if args.key? :ca_cert
52
+ option["syslog-tls-cert"] = args[:cert] if args.key? :cert
53
+ option["syslog-tls-key"] = args[:key] if args.key? :key
54
+ option["syslog-tls-skip-verify"] = true if args.key? :skip_verify
55
+ option["syslog-format"] = args[:format] if args.key? :format
56
+ option
57
+ end
58
+
59
+ def _ecs_to_log_option_json(args)
60
+ option = {
61
+ "max-size": args[:max_size] || "10m",
62
+ "max-file": args[:max_file] || 1,
63
+ }
64
+ option
65
+ end
66
+
67
+ def _ecs_to_log_option_splunk(args)
68
+ option = {
69
+ "splunk-token": args[:token],
70
+ "splunk-url": args[:url],
71
+ "splunk-verify-connection": _bool("veriy_connection", args, true),
72
+ "splunk-gzip": _bool("gzip", args, false),
73
+ }
74
+ option["splunk-source"] = args[:source] if args.key? :source
75
+ option["splunk-sourcetype"] = args[:source_type] if args.key? :source_type
76
+ option["splunk-index"] = args[:index] if args.key? :index
77
+ option["splunk-capath"] = args[:capath] if args.key? :capath
78
+ option["splunk-caname"] = args[:caname] if args.key? :caname
79
+ option["splunk-insecureskipverify"] = true if args.key? :skip_verify
80
+ option["splunk-format"] = args[:format] if args.key? :format
81
+ option["splunk-gzip-level"] = args[:gzip_level] if args.key? :gzip_label
82
+ option
83
+ end
84
+
85
+ def _ecs_to_log_option_gelf(args)
86
+ option = {
87
+ "gelf-address": args[:address],
88
+ "gelf-compression-type": args[:type] || "gzip",
89
+ }
90
+ option["gelf-compression-level"] = args[:level] if args.key? :level
91
+ option
92
+ end
93
+
94
+ def _ecs_to_log_option_common(args)
95
+ option = {}
96
+ option[:labels] = args[:labels].join(',') if args.key? :labels
97
+ option[:env] = args[:envs].join(',') if args.key? :envs
98
+ option["env-regex"] = args[:env_regex] if args.key? :env_regex
99
+ option[:tag] = args[:tag] if args.key? :tag
100
+ option
101
+ end
102
+
103
+ def _ecs_volumes(args)
104
+ (args[:volumes] || []).collect do |volume|
105
+ volume = { volume: "" } if volume.is_a? String
106
+ volume.map.collect do |name, source|
107
+ _{
108
+ Name name
109
+ Host do
110
+ SourcePath source
111
+ end unless source.empty?
112
+ }
113
+ end
114
+ end.flatten
115
+ end
116
+
6
117
  def _ecs_load_balancers(args)
7
- balancers = args[:load_balancers] || []
8
-
9
- array = []
10
- balancers.each do |balancer|
11
- array << _{
12
- ContainerName balancer[:container_name] || 80
13
- ContainerPort balancer[:container_port] || 80
14
- LoadBalancerName balancer[:lb_name] || ""
118
+ (args[:load_balancers] || []).collect do |balancer|
119
+ target = _ref_string('target', balancer, 'target group')
120
+
121
+ _{
122
+ ContainerName _name("name", balancer)
123
+ ContainerPort balancer[:port] || 80
124
+ LoadBalancerName _name("lb_name", balancer) if target.empty?
125
+ TargetGroupArn target unless target.empty?
15
126
  }
16
127
  end
17
- array
18
- end
19
-
20
- def _ecs_container_definitions(args)
21
- definitions = args[:container_definitions] || []
22
-
23
- array = []
24
- definitions.each do |definition|
25
- command = definition[:command] || []
26
- entry_point = definition[:entry_point] || []
27
- environment = definition[:environment] || []
28
- links = definition[:link] || []
29
- mount_points = _ecs_mount_points(definition)
30
- port_mappings =
31
- if definition.key? :port_mappings
32
- if definition[:port_mappings].nil?
33
- []
34
- else
35
- _ecs_port_mappings(definition)
36
- end
128
+ end
129
+
130
+ def _ecs_network(args)
131
+ vpc = args[:vpc] || []
132
+ return vpc if vpc.empty?
133
+
134
+ vpc = _ecs_vpc(vpc)
135
+
136
+ _{
137
+ AwsvpcConfiguration vpc
138
+ }
139
+ end
140
+
141
+ def _ecs_vpc(args)
142
+ assign_public = _bool('assign_public', args, false)
143
+ security_groups = _ref_array('security_groups', args, 'security group')
144
+ subnets = _ref_array('subnets', args, 'subnets')
145
+
146
+ _{
147
+ AssignPublicIp assign_public ? 'ENABLED' : 'DISABLED'
148
+ SecurityGroups security_groups unless security_groups.empty?
149
+ Subnets subnets
150
+ }
151
+ end
152
+
153
+ def _ecs_containers(args)
154
+ (args[:containers] || []).collect.with_index do |container, i|
155
+ container[:name] = "container-#{i + 1}" unless container.key? :name
156
+
157
+ command = _array(container[:command] || [])
158
+ cpu = container[:cpu] || 1
159
+ search_domains = _ref_array("search_domains", args)
160
+ servers = _ref_array("servers", args)
161
+ label = container[:label] || {}
162
+ security_options = _array(container[:security_options] || [])
163
+ entry_point = _array(container[:entry_point] || [])
164
+ environment = _pair_name_value(container, "environment")
165
+ extra_hosts = _ecs_extra_hosts(container)
166
+ host = _name("host", container)
167
+ image =
168
+ if container.key? :my_image
169
+ _join([ _account_id,
170
+ ".dkr.ecr.",
171
+ _region,
172
+ ".#{DOMAIN}/",
173
+ container[:my_image],
174
+ ":",
175
+ container[:my_image_tag] || "latest"
176
+ ], "")
37
177
  else
38
- _ecs_port_mappings({ port_mappings: [ { container_port: 80 } ] })
178
+ container[:image] || "nginx:latest"
39
179
  end
40
- volumes_from = _ecs_volumes_from(definition)
41
- array << _{
180
+ links = _array(container[:links] || [])
181
+ log_config = _ecs_log_configuration(container)
182
+ memory = container[:memory] || 300
183
+ memory_reservation = container[:memory_reservation] || 0
184
+ mount_points = _ecs_mount_points(container)
185
+ port_mappings = _ecs_port_mappings(container)
186
+ ulimits = _ecs_ulimits(container)
187
+ user = container[:user] || ""
188
+ volumes = _ecs_volumes_from(container)
189
+ working = container[:working] || ""
190
+
191
+ _{
42
192
  Command command unless command.empty?
43
- Cpu definition[:cpu] || 10
193
+ Cpu cpu
194
+ DisableNetworking _bool("networking", container, false)
195
+ DnsSearchDomains search_domains unless search_domains.empty?
196
+ DnsServers servers unless servers.empty?
197
+ DockerLabels label unless label.empty?
198
+ DockerSecurityOptions security_options unless security_options.empty?
44
199
  EntryPoint entry_point unless entry_point.empty?
45
200
  Environment environment unless environment.empty?
46
- Essential _bool("essential", definition, true)
47
- Image definition[:image] # repository-url/image:tag
201
+ Essential _bool("essential", container, true)
202
+ ExtraHosts extra_hosts unless extra_hosts.empty?
203
+ Hostname host
204
+ Image image
48
205
  Links links unless links.empty?
49
- Memory definition[:memory] || 300 # MiB
206
+ LogConfiguration log_config unless log_config.empty?
207
+ Memory memory
208
+ MemoryReservation memory_reservation if 0 < memory_reservation
50
209
  MountPoints mount_points unless mount_points.empty?
51
- Name _ref_string("name", definition)
210
+ Name _ref_string("name", container)
52
211
  PortMappings port_mappings unless port_mappings.empty?
53
- VolumesFrom volumes_from unless volumes_from.empty?
212
+ Privileged _bool("privileged", container, false)
213
+ ReadonlyRootFilesystem _bool("read_only", container, false)
214
+ Ulimits ulimits unless ulimits.empty?
215
+ User user unless user.empty?
216
+ VolumesFrom volumes unless volumes.empty?
217
+ WorkingDirectory working unless working.empty?
218
+ }
219
+ end
220
+ end
221
+
222
+ def _ecs_extra_hosts(args)
223
+ (args[:extra_hosts] || []).collect do |host|
224
+ _{
225
+ HostName host[:name]
226
+ IpAddress host[:ip]
54
227
  }
55
228
  end
56
- array
229
+ end
230
+
231
+ def _ecs_log_configuration(args)
232
+ configuration = args[:log] || []
233
+ return configuration if configuration.empty?
234
+
235
+ driver = _valid_values(configuration[:driver],
236
+ %w( json-file syslog journald gelf fluentd awslogs splunk), "awslogs")
237
+ option = _ecs_to_log_option(configuration)
238
+ _{
239
+ LogDriver driver
240
+ Options option unless option.empty?
241
+ }
57
242
  end
58
243
 
59
244
  def _ecs_mount_points(args)
60
- mount_points = args[:mount_points] || []
61
- array = []
62
- mount_points.each do |point|
63
- array << _{
64
- ContainerPath point[:container_path]
65
- SourceVolume point[:source_volume]
245
+ (args[:mount_points] || args[:mounts] || []).collect do |point|
246
+ _{
247
+ ContainerPath point[:path]
248
+ SourceVolume point[:source]
66
249
  ReadOnly _bool("read_only", point, false)
67
250
  }
68
251
  end
69
- array
70
252
  end
71
253
 
72
254
  def _ecs_port_mappings(args)
73
- port_mappings = args[:port_mappings] || []
74
-
75
- array = []
76
- port_mappings.each do |point|
77
- host_port = _ref_string("host_port", point, "host port")
78
- array << _{
79
- ContainerPort _ref_string("container_port", point, "container port")
80
- HostPort host_port unless host_port.empty?
255
+ (args[:port_mappings] || args[:ports] || []).collect do |port|
256
+ host = _ref_string("host", port, 'host port')
257
+ _{
258
+ ContainerPort _ref_string("port", port, 'container port')
259
+ HostPort host unless host.empty?
260
+ Protocol _valid_values(port[:protocol], %w( tcp udp ), 'tcp')
81
261
  }
82
262
  end
83
- array
84
263
  end
85
264
 
86
- def _ecs_volumes_from(args)
87
- volumes_from = args[:volumes_from] || []
88
-
89
- array = []
90
- volumes_from.each do |volume|
91
- array << _{
92
- SourceContainer _ref_string("source", volume)
93
- ReadOnly _bool("read_only", volume, false)
265
+ def _ecs_ulimits(args)
266
+ (args[:ulimits] || []).collect do |ulimit|
267
+ _{
268
+ HardLimit ulimit[:hard]
269
+ Name _name("name", ulimit)
270
+ SoftLimit ulimit[:hard] || ulimit[:soft]
94
271
  }
95
272
  end
96
- array
97
273
  end
98
274
 
99
- def _ecs_volumes(args)
100
- volumes = args[:volumes] || []
101
-
102
- array = []
103
- volumes.each do |volume|
104
- host = _ecs_volumes_host(volume[:host])
105
- array << _{
106
- Name volume[:name]
107
- Host host unless host.empty?
275
+ def _ecs_volumes_from(args)
276
+ (args[:volumes_from] || args[:volumes] || []).collect do |volume|
277
+ _{
278
+ SourceContainer _ref_string("source", volume)
279
+ ReadOnly _bool("read_only", volume, false)
108
280
  }
109
281
  end
110
- array
111
- end
112
-
113
- def _ecs_volumes_host(args)
114
- return {} if args.nil? or !args.key? :source_path
115
-
116
- _{
117
- SourcePath args[:source_path]
118
- }
119
282
  end
120
283
 
121
284
  def _ecs_deployment(args)
122
- return "" unless args.key? :max or args.key? :min
285
+ return "" unless args.key? :deployment
286
+
287
+ deployment = args[:deployment]
123
288
 
124
289
  _{
125
- MaximumPercent args[:max]
126
- MinimumHealthyPercent args[:min]
290
+ MaximumPercent deployment[:max] || 200
291
+ MinimumHealthyPercent deployment[:min] || 50
127
292
  }
128
293
  end
129
294
 
130
- def _ecs_placement_definition(args)
131
- return "" unless args.key? :placement
295
+ def _ecs_placement_definition(args, key = 'placement')
296
+ placement = args[key.to_sym] || []
297
+ return placement if placement.empty?
132
298
 
133
- placement = args[:placement]
134
299
  type = _valid_values(placement[:type], %w( distinctInstance memberOf), "distinctInstance")
135
300
  expression = placement[:expression] || ""
136
301
 
@@ -140,15 +305,15 @@ def _ecs_placement_definition(args)
140
305
  }
141
306
  end
142
307
 
143
- def _ecs_placement_service(args)
144
- return "" unless args.key? :placement
308
+ def _ecs_placement_strategies(args, key = 'placement')
309
+ placement = args[key.to_sym] || []
310
+ return placement if placement.empty?
145
311
 
146
- placement = args[:placement]
147
312
  type = _valid_values(placement[:type], %w( random spread binpack ), "random")
148
313
  field =
149
314
  case type
150
315
  when "binpack"
151
- _valid_values(args[:field], %w( cpu memory ), "cpu")
316
+ _valid_values(placement[:field], %w( cpu memory ), "cpu")
152
317
  when "spread"
153
318
  args[:field] || ""
154
319
  else
@@ -241,7 +241,7 @@ def _elasticbeanstalk_to_option_vpc(args)
241
241
  array << {
242
242
  name: "aws:ec2:vpc",
243
243
  option: "VpcId",
244
- value: _ref_name("vpc", args),
244
+ value: _ref_string("vpc", args, "vpc"),
245
245
  }
246
246
  array << {
247
247
  name: "aws:ec2:vpc",
@@ -282,15 +282,13 @@ def _elasticbeanstalk_to_option_application(args)
282
282
  end
283
283
 
284
284
  def _elasticbeanstalk_to_option_application_environment(args)
285
- array = []
286
- args.each do |k, v|
287
- array << {
285
+ args.collect do |k, v|
286
+ {
288
287
  name: "aws:elasticbeanstalk:application:environment",
289
288
  option: k,
290
289
  value: v,
291
290
  }
292
291
  end
293
- array
294
292
  end
295
293
 
296
294
  def _elasticbeanstalk_to_option_logs(args)
@@ -927,15 +925,13 @@ def _elasticbeanstalk_to_option_rds_db_instance(args)
927
925
  end
928
926
 
929
927
  def _elasticbeanstalk_options(options)
930
- array = []
931
- options.each do |option|
932
- array << _{
928
+ options.collect do |option|
929
+ _{
933
930
  Namespace option[:name]
934
931
  OptionName option[:option]
935
932
  Value option[:value]
936
933
  }
937
934
  end
938
- array
939
935
  end
940
936
 
941
937
  def _elasticbeanstalk_configuration(configuration)
@@ -959,6 +955,7 @@ def _elasticbeanstalk_tier(tier)
959
955
  end
960
956
 
961
957
  name = _valid_values(tier[:name], %w( WebServer Worker ), "WebServer")
958
+
962
959
  _{
963
960
  Name name
964
961
  Type (name == "WebServer") ? "Standard" : "SQS/HTTP"
@@ -16,16 +16,12 @@ def _elb_access_logging_policy(args)
16
16
  end
17
17
 
18
18
  def _elb_app_cookie_stickiness_policy(args)
19
- array = []
20
- apps = args[:app_cookie] || []
21
-
22
- apps.each do |app|
23
- array << _{
19
+ (args[:app_cookie] || []).collect do |app|
20
+ _{
24
21
  CookieName app[:cookie]
25
22
  PolicyName app[:policy]
26
- }
23
+ }
27
24
  end
28
- array
29
25
  end
30
26
 
31
27
  def _elb_connection_draining_policy(args)
@@ -65,24 +61,19 @@ def _elb_health_check(args)
65
61
  end
66
62
 
67
63
  def _elb_cookie_stickiness_policy(args)
68
- cookies = args[:cookie_stickiness] || []
69
-
70
- array = []
71
- cookies.each do |cookie|
72
- array << _{
64
+ (args[:cookie_stickiness] || []).collect do |cookie|
65
+ _{
73
66
  CookieExpirationPeriod cookie[:expiration]
74
67
  PolicyName cookie[:policy]
75
68
  }
76
69
  end
77
- array
78
70
  end
79
71
 
80
72
  def _elb_listeners(args)
81
73
  listeners = args[:listeners] || []
82
74
  listeners = [ { protocol: "http" } ] if listeners.empty?
83
75
 
84
- array = []
85
- listeners.each do |listener|
76
+ listeners.collect do |listener|
86
77
  proto = listener[:protocol] || "http"
87
78
  protocol = _valid_values(proto, %w( http https tcp ssl ), "http")
88
79
  lb_port =
@@ -108,7 +99,7 @@ def _elb_listeners(args)
108
99
  end
109
100
  ssl = _ref_string("ssl", listener)
110
101
 
111
- array << _{
102
+ _{
112
103
  InstancePort instance_port
113
104
  InstanceProtocol instance_protocol.upcase
114
105
  LoadBalancerPort lb_port
@@ -117,22 +108,17 @@ def _elb_listeners(args)
117
108
  SSLCertificateId ssl if protocol == "https"
118
109
  }
119
110
  end
120
- array
121
111
  end
122
112
 
123
113
  def _elb_policy_types(args)
124
- policies = args[:policy] || []
125
- return [] if policies.empty?
126
-
127
- array = []
128
- policies.each do |policy|
114
+ (args[:policy] || []).collect do |policy|
129
115
  attributes = []
130
116
  instance_ports = []
131
117
  lb_ports = []
132
118
  policy_name = policy[:name]
133
119
  policy_type = policy[:type]
134
120
 
135
- array << _{
121
+ _{
136
122
  Attributes attributes unless attributes.empty?
137
123
  InstancePorts instance_ports unless instance_ports.empty?
138
124
  LoadBalancerPorts lb_ports unless lb_ports.empty?
@@ -140,5 +126,4 @@ def _elb_policy_types(args)
140
126
  PolicyType policy_type
141
127
  }
142
128
  end
143
- array
144
129
  end