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
@@ -2,7 +2,7 @@
2
2
  # Helper - EMR
3
3
  #
4
4
  require 'kumogata/template/helper'
5
-
5
+ require 'kumogata/template/cloudwatch'
6
6
 
7
7
  def _emr_to_configurations_default_hadoop_spark(max_age: 14)
8
8
  _emr_to_configurations_default_hadoop | _emr_to_configurations_default_spark(max_age: max_age)
@@ -45,25 +45,22 @@ end
45
45
  def _emr_applications(args)
46
46
  applications = args[:applications] || []
47
47
 
48
- array = []
49
- applications.each do |application|
48
+ applications.collect do |application|
50
49
  args = application[:args] || []
51
- array << _{
50
+ _{
52
51
  #AdditionalInfo
53
52
  Args args unless args.empty?
54
53
  Name application[:name].capitalize
55
54
  Version application[:version] if application.key? :version
56
55
  }
57
56
  end
58
- array
59
57
  end
60
58
 
61
59
  def _emr_bootstraps(args)
62
60
  actions = args[:bootstraps] || []
63
61
 
64
- array = []
65
- actions.each do |action|
66
- array << _{
62
+ actions.collect do |action|
63
+ _{
67
64
  Name action[:name]
68
65
  ScriptBootstrapAction _{
69
66
  Args action[:script_args] if action.key? :script_args
@@ -71,50 +68,31 @@ def _emr_bootstraps(args)
71
68
  }
72
69
  }
73
70
  end
74
- array
75
71
  end
76
72
 
77
73
  def _emr_configurations(args)
78
74
  configurations = args[:configurations] || []
79
75
 
80
- array = []
81
- configurations.each do |configuration|
76
+ configurations.collect do |configuration|
82
77
  classification = configuration[:classification] || ""
83
78
  properties = configuration[:properties] || {}
84
- configuring = _emr_configuring(configuration)
85
- array << _{
79
+ configurations = _emr_configurations(configuration)
80
+ _{
86
81
  Classification classification unless classification.empty?
87
82
  ConfigurationProperties properties
88
- Configurations configuring
83
+ Configurations configurations
89
84
  }
90
85
  end
91
- array
92
- end
93
-
94
- def _emr_configuring(args)
95
- configurations = args[:configurations] || []
96
-
97
- array = []
98
- configurations.each do |configuration|
99
- classification = configuration[:classification] || ""
100
- properties = configuration[:properties] || {}
101
- array << _{
102
- Classification classification unless classification.empty?
103
- ConfigurationProperties properties
104
- Configurations []
105
- }
106
- end
107
- array
108
86
  end
109
87
 
110
88
  def _emr_ebs(args)
111
89
  ebs = args[:ebs] || []
112
90
  return '' if ebs.empty?
113
- ebs_block_devices = ebs.collect{|v| _emr_ebs_block_device(v) }
91
+ block_devices = ebs.collect{|v| _emr_ebs_block_device(v) }
114
92
 
115
93
  _{
116
- EbsBlockDeviceConfigs ebs_block_devices unless ebs_block_devices.empty?
117
- #EbsOptimized
94
+ EbsBlockDeviceConfig block_devices
95
+ EbsOptimized true if args.key? :ebs_optimized
118
96
  }
119
97
  end
120
98
 
@@ -145,13 +123,15 @@ def _emr_job_flow(args)
145
123
 
146
124
  add_master_security_groups = _ref_array("add_master_security_groups", job, "security group")
147
125
  add_slave_security_groups = _ref_array("add_slave_security_groups", job, "security group")
126
+ core_instance_fleet = _emr_instance_fleet(job[:core])
148
127
  core_instance_group = _emr_instance_group(job[:core])
149
128
  key_name = _ref_string("key_name", job, "key name")
150
129
  subnet = _ref_string("subnet", job, "subnet")
151
130
  emr_master_security_group = _ref_string("emr_master_security_group", job, "security group")
152
131
  emr_slave_security_group = _ref_string("emr_slave_security_group", job, "security group")
153
132
  hadoop_version = _valid_values("hadoop", %w( 1.0.3 2.2.0 2.4.0 ))
154
- master = _emr_instance_group(job[:master])
133
+ master_instance_fleet = _emr_instance_fleet(job[:master])
134
+ master_instance_group = _emr_instance_group(job[:master])
155
135
  placement = job[:placement] || ""
156
136
  service_access_security_group = _ref_string("service_access_security_group", job, "security group")
157
137
  termination = _bool("termination", job, false)
@@ -159,13 +139,15 @@ def _emr_job_flow(args)
159
139
  _{
160
140
  AdditionalMasterSecurityGroups add_master_security_groups unless add_master_security_groups.empty?
161
141
  AdditionalSlaveSecurityGroups add_slave_security_groups unless add_slave_security_groups.empty?
162
- CoreInstanceGroup core_instance_group
142
+ CoreInstanceFleet core_instance_fleet unless core_instance_fleet.empty?
143
+ CoreInstanceGroup core_instance_group if core_instance_fleet.empty?
163
144
  Ec2KeyName key_name unless key_name.empty?
164
145
  Ec2SubnetId subnet unless subnet.empty?
165
146
  EmrManagedMasterSecurityGroup emr_master_security_group unless emr_master_security_group.empty?
166
147
  EmrManagedSlaveSecurityGroup emr_slave_security_group unless emr_slave_security_group.empty?
167
148
  HadoopVersion hadoop_version unless hadoop_version.nil?
168
- MasterInstanceGroup master
149
+ MasterInstanceFleet master_instance_fleet unless master_instance_fleet.empty?
150
+ MasterInstanceGroup master_instance_group if master_instance_fleet.empty?
169
151
  Placement _{
170
152
  AvailabilityZone placement
171
153
  } unless placement.empty?
@@ -174,20 +156,81 @@ def _emr_job_flow(args)
174
156
  }
175
157
  end
176
158
 
159
+ def _emr_instance_fleet(args)
160
+ fleet = args[:fleet] || ""
161
+ return fleet if fleet.empty?
162
+
163
+ configs = _emr_instance_fleet_type_config(fleet)
164
+ launch = _emr_instance_fleet_launch(fleet)
165
+ name = _name("fleet", fleet)
166
+ on_demand = fleet[:on_demand] || 1
167
+ spot = fleet[:spot] || 1
168
+
169
+ _{
170
+ InstanceTypeConfigs configs
171
+ LaunchSpecifications do
172
+ SpotSpecification launch
173
+ end unless launch.empty?
174
+ Name name
175
+ TargetOnDemandCapacity on_demand
176
+ TargetSpotCapacity spot
177
+ }
178
+ end
179
+
180
+ def _emr_instance_fleet_type_config(args)
181
+ (args[:configs] || []).collect do |config|
182
+ bid = config[:bid] || 0
183
+ bid_percent = config[:bid_percent] || ""
184
+ configurations = _emr_configurations(config)
185
+ ebs = _emr_ebs(config)
186
+ instance_type = _ref_string_default("instance_type", args, "instance type", EMR_DEFAULT_INSTANCE_TYPE)
187
+ weighted = config[:weighted] || 1
188
+
189
+ _{
190
+ BidPrice bid if 0 < bid
191
+ BidPriceAsPercentageOfOnDemandPrice bid_percent unless bid_percent.empty?
192
+ Configurations configurations unless configurations.empty?
193
+ EbsConfiguration ebs unless ebs.empty?
194
+ InstanceType instance_type
195
+ WeightedCapacity weighted
196
+ }
197
+ end
198
+ end
199
+
200
+ def _emr_instance_fleet_launch(args)
201
+ launch = args[:launch] || ""
202
+ return launch if launch.empty?
203
+
204
+ block = _valid_values(launch[:block], %w( 60 120 180 240 300 360 ), "")
205
+ timeout_action =
206
+ case launch[:timeout_action]
207
+ when "switch"
208
+ "SWITCH_TO_ON_DEMAND"
209
+ when "terminate"
210
+ "TERMINATE_CLUSTER"
211
+ else
212
+ "SWITCH_TO_ON_DEMAND"
213
+ end
214
+ timeout_duration = launch[:timeout_duration] || 5
215
+
216
+ _{
217
+ BlockDurationMinutes block unless block.empty?
218
+ TimeoutAction timeout_action.upcase
219
+ TimeoutDurationMinutes timeout_duration
220
+ }
221
+ end
222
+
177
223
  def _emr_instance_group(args)
178
224
  bid = args[:bid] || ""
179
225
  configurations = _emr_configurations(args)
180
- ebs_configuration = _emr_ebs(args)
181
226
  instance_count = args[:instance_count] || 1
182
- instance_type = _ref_string("instance_type", args, "instance type")
183
- instance_type = EMR_DEFAULT_INSTANCE_TYPE if instance_type.empty?
227
+ instance_type = _ref_string_default("instance_type", args, "instance type", EMR_DEFAULT_INSTANCE_TYPE)
184
228
  market = _valid_values("market", %w( on_demand, spot), "on_demand")
185
- name = _ref_name("name", args)
229
+ name = _ref_string("name", args)
186
230
 
187
231
  _{
188
232
  BidPrice bid unless bid.empty?
189
233
  Configurations configurations unless configurations.empty?
190
- EbsConfiguration ebs_configuration unless ebs_configuration.empty?
191
234
  InstanceCount instance_count
192
235
  InstanceType instance_type
193
236
  Market market.upcase
@@ -199,7 +242,7 @@ def _emr_hadoop_jar_step_config(args)
199
242
  config_args = args[:args] || []
200
243
  jar = args[:jar]
201
244
  main_class = args[:main_class] || ""
202
- step_properties = _emr_step_properties(args)
245
+ step_properties = _pair_value(args, "step")
203
246
 
204
247
  _{
205
248
  Args config_args unless config_args.empty?
@@ -209,15 +252,105 @@ def _emr_hadoop_jar_step_config(args)
209
252
  }
210
253
  end
211
254
 
212
- def _emr_step_properties(args)
213
- properties = args[:step_properties] || []
255
+ def _emr_instance_autoscaling(args)
256
+ autoscaling = args[:autoscaling] || ""
257
+ return "" if autoscaling.empty?
214
258
 
215
- array = []
216
- properties.each do |property|
217
- array << _{
218
- Key property[:key]
219
- Value property[:value]
259
+ rules = _emr_instance_autoscaling_rules(autoscaling)
260
+
261
+ _{
262
+ Constraints do
263
+ MaxCapacity autoscaling[:max]
264
+ MinCapacity autoscaling[:min]
265
+ end
266
+ Rules rules
267
+ }
268
+ end
269
+
270
+ def _emr_instance_autoscaling_rules(args)
271
+ rules = args[:rules] || []
272
+
273
+ rules.collect do |rule|
274
+ action = _emr_instance_autoscaling_rule_action(rule)
275
+ name = _name("rule", rule)
276
+ description = _ref_string_default("description", rule, '', "#{name} instance autoscaling rules description")
277
+ trigger = _emr_instance_autoscaling_rule_trigger(rule)
278
+ _{
279
+ Action action
280
+ Description description
281
+ Name name
282
+ Trigger trigger
220
283
  }
221
284
  end
222
- array
285
+ end
286
+
287
+ def _emr_instance_autoscaling_rule_action(args)
288
+ market = _valid_values(args[:market] || "", %w( on_demand, spot), "on_demand")
289
+ simple = _emr_instance_autoscaling_rule_action_simple(args)
290
+
291
+ _{
292
+ Market market.upcase
293
+ SimpleScalingPolicyConfiguration simple
294
+ }
295
+ end
296
+
297
+ def _emr_instance_autoscaling_rule_action_simple(args)
298
+ adjustment =
299
+ case args[:type]
300
+ when "change"
301
+ "CHANGE_IN_CAPACITY"
302
+ when "percent"
303
+ "PERCENT_CHANGE_IN_CAPACITY"
304
+ when "exact"
305
+ "EXACT_CAPACITY"
306
+ else
307
+ "CHANGE_IN_CAPACITY"
308
+ end
309
+ cool = args[:cool] || 0
310
+ scaling = args[:scaling]
311
+
312
+ _{
313
+ AdjustmentType adjustment
314
+ CoolDown cool
315
+ ScalingAdjustment scaling
316
+ }
317
+ end
318
+
319
+ def _emr_instance_autoscaling_rule_trigger(args)
320
+ operator =
321
+ case args[:operator]
322
+ when ">="
323
+ "GREATER_THAN_OR_EQUAL"
324
+ when ">"
325
+ "GREATER_THAN"
326
+ when "<"
327
+ "LESS_THAN"
328
+ when "<="
329
+ "LESS_THAN_OR_EQUAL"
330
+ else
331
+ "GREATER_THAN_OR_EQUAL"
332
+ end
333
+ dimensions = _pair_value(args, "dimensions")
334
+ evaluation = args[:evaluation] || 1
335
+ name = _name("definition", args)
336
+ ns = args[:ns] || "AWS/ElasticMapReduce"
337
+ period = args[:period] || 300
338
+ statistic = _valid_values(args[:statistic],
339
+ %w( sample_count average sum minimum maximum ), "average")
340
+ threshold = args[:threshold]
341
+ unit = _cloudwatch_to_unit(args[:unit])
342
+
343
+ _{
344
+ CloudWatchAlarmDefinition do
345
+ ComparisonOperator operator
346
+ Dimensions dimensions unless dimensions.empty?
347
+ EvaluationPeriods evaluation
348
+ MetricName name
349
+ Namespace ns
350
+ Period period
351
+ Statistic statistic.upcase
352
+ Threshold threshold
353
+ Unit unit
354
+ end
355
+ }
223
356
  end
@@ -3,23 +3,35 @@
3
3
  #
4
4
  require 'kumogata/template/helper'
5
5
 
6
- def _events_pattern(args)
7
- pattern = args[:pattern] || ""
8
- return "" if pattern.empty?
6
+ def _events_to_schedule_expression(args)
7
+ schedule = args || '5 minutes'
8
+ if schedule =~ /^(\d+) (minute|minutes|hour|hours|day|days)/
9
+ "rate(#{$1} #{$2})"
10
+ else
11
+ "cron(#{schedule})"
12
+ end
13
+ end
9
14
 
15
+ def _events_pattern(args)
16
+ # http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html#CloudWatchEventsPatterns
17
+ args[:pattern] || {}
10
18
  end
11
19
 
12
20
  def _events_targets(args)
13
- targets = args[:targets] || []
14
-
15
- array = []
16
- targets.each do |target|
17
- array << _{
18
- Arn target[:arn]
21
+ ## FIXME
22
+ ## https://docs.aws.amazon.com/AmazonCloudWatchEvents/latest/APIReference/API_PutTargets.html
23
+ (args[:targets] || []).collect do |target|
24
+ role = _ref_attr_string("role", "Arn", target, "role")
25
+ _{
26
+ Arn _ref_attr_string("arn", "Arn", target)
19
27
  Id target[:id]
20
28
  Input target[:input] if target.key? :input
21
29
  InputPath target[:path] if target.key? :path
30
+ RoleArn role unless role.empty?
31
+ EcsParameters _{
32
+ TaskCount target[:ecs_parameters][:task_count] if target[:ecs_parameters].key? :task_count
33
+ TaskDefinitionArn _ref_string("task_definition", target[:ecs_parameters], "ecs task definition", "arn")
34
+ } if target.key? :ecs_parameters
22
35
  }
23
36
  end
24
- array
25
37
  end
@@ -54,13 +54,13 @@ end
54
54
 
55
55
  class Kumogata2::Plugin::Ruby::Context
56
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
57
+ key_converter = proc do |k|
58
+ k = k.to_s
59
+ k.gsub!('____', '-')
60
+ k.gsub!('___', '.')
61
+ k.gsub!('__', '::')
62
+ k.gsub!('_', ':')
63
+ k
64
64
  end
65
65
 
66
66
  value_converter = proc do |v|