kumogata-template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +54 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +75 -0
  6. data/README.md +204 -0
  7. data/Rakefile +23 -0
  8. data/bin/kumogata-template +9 -0
  9. data/kumogata-template.gemspec +26 -0
  10. data/lib/kumogata/template.rb +17 -0
  11. data/lib/kumogata/template/autoscaling.rb +77 -0
  12. data/lib/kumogata/template/cloudwatch.rb +28 -0
  13. data/lib/kumogata/template/codedeploy.rb +85 -0
  14. data/lib/kumogata/template/const.rb +175 -0
  15. data/lib/kumogata/template/datapipeline.rb +90 -0
  16. data/lib/kumogata/template/dynamodb.rb +111 -0
  17. data/lib/kumogata/template/ec2.rb +165 -0
  18. data/lib/kumogata/template/ecs.rb +119 -0
  19. data/lib/kumogata/template/elasticbeanstalk.rb +33 -0
  20. data/lib/kumogata/template/elb.rb +132 -0
  21. data/lib/kumogata/template/emr.rb +166 -0
  22. data/lib/kumogata/template/events.rb +25 -0
  23. data/lib/kumogata/template/ext/argument_parser.rb +8 -0
  24. data/lib/kumogata/template/ext/kumogata.rb +103 -0
  25. data/lib/kumogata/template/helper.rb +211 -0
  26. data/lib/kumogata/template/iam.rb +96 -0
  27. data/lib/kumogata/template/lambda.rb +34 -0
  28. data/lib/kumogata/template/s3.rb +223 -0
  29. data/lib/kumogata/template/sns.rb +25 -0
  30. data/lib/kumogata/template/version.rb +1 -0
  31. data/template/_template.rb +25 -0
  32. data/template/autoscaling-group.rb +47 -0
  33. data/template/autoscaling-launch-configuration.rb +54 -0
  34. data/template/autoscaling-lifecycle-hook.rb +27 -0
  35. data/template/autoscaling-scaling-policy.rb +33 -0
  36. data/template/autoscaling-scheduled-action.rb +37 -0
  37. data/template/cloudtrail.rb +39 -0
  38. data/template/cloudwatch-alarm.rb +45 -0
  39. data/template/codedeploy-application.rb +15 -0
  40. data/template/codedeploy-deployment-config.rb +23 -0
  41. data/template/codedeploy-deployment-group.rb +35 -0
  42. data/template/datapipeline-pipeline.rb +28 -0
  43. data/template/dynamodb-table.rb +33 -0
  44. data/template/ec2-eip-association.rb +23 -0
  45. data/template/ec2-eip.rb +17 -0
  46. data/template/ec2-instance.rb +65 -0
  47. data/template/ec2-internet-gateway.rb +15 -0
  48. data/template/ec2-nat-gateway.rb +17 -0
  49. data/template/ec2-network-acl-entry.rb +30 -0
  50. data/template/ec2-network-acl.rb +17 -0
  51. data/template/ec2-route-table.rb +17 -0
  52. data/template/ec2-route.rb +27 -0
  53. data/template/ec2-security-group.rb +24 -0
  54. data/template/ec2-subnet-network-acl-association.rb +17 -0
  55. data/template/ec2-subnet-route-table-association.rb +17 -0
  56. data/template/ec2-subnet.rb +23 -0
  57. data/template/ec2-volume-attachment.rb +19 -0
  58. data/template/ec2-volume.rb +31 -0
  59. data/template/ec2-vpc-endpoint.rb +23 -0
  60. data/template/ec2-vpc-gateway-attachment.rb +19 -0
  61. data/template/ec2-vpc.rb +24 -0
  62. data/template/ecs-cluster.rb +11 -0
  63. data/template/ecs-service.rb +24 -0
  64. data/template/ecs-task-definition.rb +18 -0
  65. data/template/elasticache-cache-cluster.rb +63 -0
  66. data/template/elasticache-parameter-group.rb +20 -0
  67. data/template/elasticache-replication-group.rb +58 -0
  68. data/template/elasticache-subnet-group.rb +17 -0
  69. data/template/elasticbeanstalk-application-version.rb +24 -0
  70. data/template/elasticbeanstalk-application.rb +17 -0
  71. data/template/elasticbeanstalk-configuration-template.rb +31 -0
  72. data/template/elasticbeanstalk-environment.rb +44 -0
  73. data/template/elb-loadbalancer.rb +46 -0
  74. data/template/emr-cluster.rb +39 -0
  75. data/template/emr-instance-group-config.rb +33 -0
  76. data/template/emr-step.rb +22 -0
  77. data/template/events-rule.rb +28 -0
  78. data/template/iam-access-key.rb +19 -0
  79. data/template/iam-group.rb +20 -0
  80. data/template/iam-instance-profile.rb +17 -0
  81. data/template/iam-managed-policy.rb +28 -0
  82. data/template/iam-policy.rb +26 -0
  83. data/template/iam-role.rb +21 -0
  84. data/template/iam-user-to-group-addition.rb +17 -0
  85. data/template/iam-user.rb +24 -0
  86. data/template/lambda-alias.rb +21 -0
  87. data/template/lambda-event-source-mapping.rb +24 -0
  88. data/template/lambda-function.rb +34 -0
  89. data/template/lambda-permission.rb +26 -0
  90. data/template/lambda-version.rb +19 -0
  91. data/template/mappings-ec2.rb +85 -0
  92. data/template/output-access-key.rb +6 -0
  93. data/template/output-arn.rb +6 -0
  94. data/template/output-autoscaling.rb +6 -0
  95. data/template/output-az.rb +6 -0
  96. data/template/output-dynamodb.rb +6 -0
  97. data/template/output-ec2.rb +8 -0
  98. data/template/output-elasticache.rb +30 -0
  99. data/template/output-elb.rb +12 -0
  100. data/template/output-emr.rb +6 -0
  101. data/template/output-rds.rb +10 -0
  102. data/template/output-redshift.rb +10 -0
  103. data/template/output-s3.rb +8 -0
  104. data/template/output-security-group.rb +5 -0
  105. data/template/output-sqs.rb +5 -0
  106. data/template/output-topic.rb +6 -0
  107. data/template/output-vpc.rb +10 -0
  108. data/template/output.rb +29 -0
  109. data/template/parameter-ec2.rb +22 -0
  110. data/template/parameter-elasticache.rb +9 -0
  111. data/template/parameter-rds.rb +9 -0
  112. data/template/parameter-redshift.rb +9 -0
  113. data/template/parameter.rb +20 -0
  114. data/template/rds-db-cluster-parameter-group.rb +22 -0
  115. data/template/rds-db-cluster.rb +47 -0
  116. data/template/rds-db-instance.rb +82 -0
  117. data/template/rds-db-parameter-group.rb +21 -0
  118. data/template/rds-db-subnet-group.rb +19 -0
  119. data/template/rds-event-subscription.rb +42 -0
  120. data/template/rds-option-group.rb +23 -0
  121. data/template/redshift-cluster-parameter-group.rb +19 -0
  122. data/template/redshift-cluster-subnet-group.rb +17 -0
  123. data/template/redshift-cluster.rb +60 -0
  124. data/template/s3-bucket-policy.rb +20 -0
  125. data/template/s3-bucket.rb +42 -0
  126. data/template/sns-topic.rb +20 -0
  127. data/template/sqs-queue.rb +27 -0
  128. data/test/_template.rb +26 -0
  129. data/test/abstract_unit.rb +101 -0
  130. data/test/autoscaling_test.rb +109 -0
  131. data/test/codedeploy_test.rb +117 -0
  132. data/test/datapipeline_test.rb +142 -0
  133. data/test/dynamodb_test.rb +184 -0
  134. data/test/ec2_test.rb +286 -0
  135. data/test/ecs_test.rb +135 -0
  136. data/test/elasticbeanstalk_test.rb +56 -0
  137. data/test/elb_test.rb +147 -0
  138. data/test/emr_test.rb +193 -0
  139. data/test/events_test.rb +22 -0
  140. data/test/helper_test.rb +547 -0
  141. data/test/iam_test.rb +93 -0
  142. data/test/lambda_test.rb +41 -0
  143. data/test/s3_test.rb +195 -0
  144. data/test/sns_test.rb +27 -0
  145. data/test/template/autoscaling-group_test.rb +177 -0
  146. data/test/template/autoscaling-launch-configuration_test.rb +117 -0
  147. data/test/template/autoscaling-lifecycle-hook_test.rb +33 -0
  148. data/test/template/autoscaling-scaling-policy_test.rb +26 -0
  149. data/test/template/autoscaling-scheduled-action_test.rb +26 -0
  150. data/test/template/cloudtrail_test.rb +55 -0
  151. data/test/template/cloudwatch-alarm_test.rb +38 -0
  152. data/test/template/codedeploy-application_test.rb +21 -0
  153. data/test/template/codedeploy-deployment-config_test.rb +26 -0
  154. data/test/template/codedeploy-deployment-group_test.rb +48 -0
  155. data/test/template/datapipeline-pipeline_test.rb +358 -0
  156. data/test/template/dynamodb-table_test.rb +94 -0
  157. data/test/template/ec2-eip-association_test.rb +22 -0
  158. data/test/template/ec2-eip_test.rb +21 -0
  159. data/test/template/ec2-instance_test.rb +95 -0
  160. data/test/template/ec2-internet-gateway_test.rb +48 -0
  161. data/test/template/ec2-nat-gateway_test.rb +22 -0
  162. data/test/template/ec2-network-acl-entry_test.rb +61 -0
  163. data/test/template/ec2-network-acl_test.rb +51 -0
  164. data/test/template/ec2-route-table_test.rb +49 -0
  165. data/test/template/ec2-route_test.rb +21 -0
  166. data/test/template/ec2-security-group_test.rb +50 -0
  167. data/test/template/ec2-subnet-netwokr-acl-association_test.rb +26 -0
  168. data/test/template/ec2-subnet-route-table-association_test.rb +22 -0
  169. data/test/template/ec2-subnet_test.rb +51 -0
  170. data/test/template/ec2-volume-attachment_test.rb +24 -0
  171. data/test/template/ec2-volume_test.rb +52 -0
  172. data/test/template/ec2-vpc-gateway-attachment_test.rb +23 -0
  173. data/test/template/ec2-vpc_test.rb +102 -0
  174. data/test/template/ecs-cluster_test.rb +18 -0
  175. data/test/template/ecs-service_test.rb +29 -0
  176. data/test/template/ecs-task-definition_test.rb +143 -0
  177. data/test/template/elasticache-cache-cluster_test.rb +77 -0
  178. data/test/template/elasticache-parameter-group_test.rb +25 -0
  179. data/test/template/elasticache-replication-group_test.rb +45 -0
  180. data/test/template/elasticache-subnet-group_test.rb +26 -0
  181. data/test/template/elasticbeanstalk-application-version_test.rb +27 -0
  182. data/test/template/elasticbeanstalk-application_test.rb +21 -0
  183. data/test/template/elasticbeanstalk-configuration-template_test.rb +23 -0
  184. data/test/template/elasticbeanstalk-environment_test.rb +56 -0
  185. data/test/template/elasticbeanstalk-template_test.rb +33 -0
  186. data/test/template/elb-loadbalancer_test.rb +94 -0
  187. data/test/template/emr-cluster_test.rb +147 -0
  188. data/test/template/emr-instance-group-config_test.rb +65 -0
  189. data/test/template/emr-step_test.rb +82 -0
  190. data/test/template/events-rule_test.rb +34 -0
  191. data/test/template/iam-access-key_test.rb +22 -0
  192. data/test/template/iam-group_test.rb +21 -0
  193. data/test/template/iam-instance-profile_test.rb +24 -0
  194. data/test/template/iam-managed-policy_test.rb +35 -0
  195. data/test/template/iam-policy_test.rb +52 -0
  196. data/test/template/iam-role_test.rb +37 -0
  197. data/test/template/iam-user-to-group-addition_test.rb +24 -0
  198. data/test/template/iam-user_test.rb +21 -0
  199. data/test/template/lambda-alias_test.rb +46 -0
  200. data/test/template/lambda-event-source-mapping_test.rb +36 -0
  201. data/test/template/lambda-function_test.rb +34 -0
  202. data/test/template/lambda-permission_test.rb +32 -0
  203. data/test/template/lambda-version_test.rb +27 -0
  204. data/test/template/mappings-ec2_test.rb +92 -0
  205. data/test/template/output-access-key_test.rb +30 -0
  206. data/test/template/output-arn_test.rb +30 -0
  207. data/test/template/output-autoscaling_test.rb +27 -0
  208. data/test/template/output-az_test.rb +31 -0
  209. data/test/template/output-dynamodb_test.rb +21 -0
  210. data/test/template/output-ec2_test.rb +82 -0
  211. data/test/template/output-elasticache_test.rb +107 -0
  212. data/test/template/output-elb_test.rb +48 -0
  213. data/test/template/output-emr_test.rb +30 -0
  214. data/test/template/output-rds_test.rb +39 -0
  215. data/test/template/output-redshift_test.rb +39 -0
  216. data/test/template/output-s3_test.rb +52 -0
  217. data/test/template/output-security-group_test.rb +21 -0
  218. data/test/template/output-sqs_test.rb +21 -0
  219. data/test/template/output-topic_test.rb +30 -0
  220. data/test/template/output-vpc_test.rb +48 -0
  221. data/test/template/output_test.rb +87 -0
  222. data/test/template/parameter-ec2_test.rb +44 -0
  223. data/test/template/parameter-elasticache_test.rb +30 -0
  224. data/test/template/parameter-rds_test.rb +30 -0
  225. data/test/template/parameter-redshift_test.rb +30 -0
  226. data/test/template/parameter_test.rb +40 -0
  227. data/test/template/rds-db-cluster-parameter-group_test.rb +53 -0
  228. data/test/template/rds-db-cluster_test.rb +84 -0
  229. data/test/template/rds-db-instance_test.rb +93 -0
  230. data/test/template/rds-db-parameter-group_test.rb +53 -0
  231. data/test/template/rds-db-subnet-group.rb +54 -0
  232. data/test/template/rds-event-subscription_test.rb +48 -0
  233. data/test/template/rds-option-group_test.rb +56 -0
  234. data/test/template/redshift-cluster-parameter-group_test.rb +28 -0
  235. data/test/template/redshift-cluster-subnet-group_test.rb +26 -0
  236. data/test/template/redshift-cluster_test.rb +47 -0
  237. data/test/template/s3-bucket-policy_test.rb +40 -0
  238. data/test/template/s3-bucket_test.rb +127 -0
  239. data/test/template/sns-topic_test.rb +42 -0
  240. data/test/template/sqs-queue_test.rb +25 -0
  241. metadata +468 -0
@@ -0,0 +1,117 @@
1
+ require 'abstract_unit'
2
+ require 'kumogata/template/codedeploy'
3
+
4
+ class CodedeployTest < Minitest::Test
5
+ def test_codedeploy_minimum
6
+ template = <<-EOS
7
+ Test _codedeploy_minimum(type: "fleet_percent", value: "75")
8
+ EOS
9
+ act_template = run_client_as_json(template)
10
+ exp_template = <<-EOS
11
+ {
12
+ "Test": {
13
+ "Type": "FLEET_PERCENT",
14
+ "Value": "75"
15
+ }
16
+ }
17
+ EOS
18
+ assert_equal exp_template.chomp, act_template
19
+ end
20
+
21
+ def test_codedeploy_deployment
22
+ template = <<-EOS
23
+ Test _codedeploy_deployment(description: "test", revision: { s3: { bucket: "test", key: "test", version: "test" } })
24
+ EOS
25
+ act_template = run_client_as_json(template)
26
+ exp_template = <<-EOS
27
+ {
28
+ "Test": {
29
+ "Description": "test",
30
+ "IgnoreApplicationStopFailures": "true",
31
+ "Revision": {
32
+ "RevisionType": "S3",
33
+ "S3Location": {
34
+ "Bucket": "test",
35
+ "Key": "test",
36
+ "BundleType": "Zip",
37
+ "Version": "test"
38
+ }
39
+ }
40
+ }
41
+ }
42
+ EOS
43
+ assert_equal exp_template.chomp, act_template
44
+ end
45
+
46
+ def test_codedeploy_revision
47
+ template = <<-EOS
48
+ Test _codedeploy_revision(s3: { bucket: "test", key: "test", version: "test" })
49
+ EOS
50
+ act_template = run_client_as_json(template)
51
+ exp_template = <<-EOS
52
+ {
53
+ "Test": {
54
+ "RevisionType": "S3",
55
+ "S3Location": {
56
+ "Bucket": "test",
57
+ "Key": "test",
58
+ "BundleType": "Zip",
59
+ "Version": "test"
60
+ }
61
+ }
62
+ }
63
+ EOS
64
+ assert_equal exp_template.chomp, act_template
65
+ end
66
+
67
+ def test_codedeploy_github
68
+ template = <<-EOS
69
+ Test _codedeploy_github(commit: "test", repository: "test")
70
+ EOS
71
+ act_template = run_client_as_json(template)
72
+ exp_template = <<-EOS
73
+ {
74
+ "Test": {
75
+ "CommitId": "test",
76
+ "Repository": "test"
77
+ }
78
+ }
79
+ EOS
80
+ assert_equal exp_template.chomp, act_template
81
+ end
82
+
83
+ def test_codedeploy_s3
84
+ template = <<-EOS
85
+ Test _codedeploy_s3(bucket: "test", key: "test", version: "test")
86
+ EOS
87
+ act_template = run_client_as_json(template)
88
+ exp_template = <<-EOS
89
+ {
90
+ "Test": {
91
+ "Bucket": "test",
92
+ "Key": "test",
93
+ "BundleType": "Zip",
94
+ "Version": "test"
95
+ }
96
+ }
97
+ EOS
98
+ assert_equal exp_template.chomp, act_template
99
+ end
100
+
101
+ def test_codedeploy_tag_filters
102
+ template = <<-EOS
103
+ Test _codedeploy_tag_filters(key: "test", value: "test")
104
+ EOS
105
+ act_template = run_client_as_json(template)
106
+ exp_template = <<-EOS
107
+ {
108
+ "Test": {
109
+ "Key": "test",
110
+ "Type": "KEY_AND_VALUE",
111
+ "Value": "test"
112
+ }
113
+ }
114
+ EOS
115
+ assert_equal exp_template.chomp, act_template
116
+ end
117
+ end
@@ -0,0 +1,142 @@
1
+ require 'abstract_unit'
2
+ require 'kumogata/template/datapipeline'
3
+
4
+ class DatapipelineTest < Minitest::Test
5
+ def test_datapipeline_parameter_objects
6
+ template = <<-EOS
7
+ Test _datapipeline_parameter_objects(parameter_objects: [ { test: { attributes: { test: "test" } } } ])
8
+ EOS
9
+ act_template = run_client_as_json(template)
10
+ exp_template = <<-EOS
11
+ {
12
+ "Test": [
13
+ {
14
+ "Attributes": [
15
+ {
16
+ "Key": "test",
17
+ "StringValue": "test"
18
+ }
19
+ ],
20
+ "Id": "test"
21
+ }
22
+ ]
23
+ }
24
+ EOS
25
+ assert_equal exp_template.chomp, act_template
26
+ end
27
+
28
+ def test_datapipeline_parameter_objects_attributes
29
+ template = <<-EOS
30
+ Test _datapipeline_parameter_objects_attributes(attributes: { test: "test" })
31
+
32
+ EOS
33
+ act_template = run_client_as_json(template)
34
+ exp_template = <<-EOS
35
+ {
36
+ "Test": [
37
+ {
38
+ "Key": "test",
39
+ "StringValue": "test"
40
+ }
41
+ ]
42
+ }
43
+ EOS
44
+ assert_equal exp_template.chomp, act_template
45
+ end
46
+
47
+ def test_datapipeline_parameter_values
48
+ template = <<-EOS
49
+ Test _datapipeline_parameter_values(parameter_values: { test: "test" })
50
+ EOS
51
+ act_template = run_client_as_json(template)
52
+ exp_template = <<-EOS
53
+ {
54
+ "Test": [
55
+ {
56
+ "Id": "test",
57
+ "StringValue": "test"
58
+ }
59
+ ]
60
+ }
61
+ EOS
62
+ assert_equal exp_template.chomp, act_template
63
+ end
64
+
65
+ def test_datapipeline_pipeline_objects
66
+ template = <<-EOS
67
+ fields = { test: { ref: "test", string: "test" }, test1: { ref: "test1", string: "test1" } }
68
+ Test _datapipeline_pipeline_objects(objects: [ { test: { name: "test", fields: fields } } ])
69
+ EOS
70
+ act_template = run_client_as_json(template)
71
+ exp_template = <<-EOS
72
+ {
73
+ "Test": [
74
+ {
75
+ "Fields": [
76
+ {
77
+ "Key": "test",
78
+ "RefValue": "test",
79
+ "StringValue": "test"
80
+ },
81
+ {
82
+ "Key": "test1",
83
+ "RefValue": "test1",
84
+ "StringValue": "test1"
85
+ }
86
+ ],
87
+ "Id": "test",
88
+ "Name": "test"
89
+ }
90
+ ]
91
+ }
92
+ EOS
93
+ assert_equal exp_template.chomp, act_template
94
+ end
95
+
96
+ def test_datapipeline_pipeline_object_fields
97
+ template = <<-EOS
98
+ fields = { test: { ref: "test", string: "test" }, test1: { ref: "test1", string: "test1"} }
99
+ Test _datapipeline_pipeline_object_fields(fields: fields)
100
+ EOS
101
+ act_template = run_client_as_json(template)
102
+ exp_template = <<-EOS
103
+ {
104
+ "Test": [
105
+ {
106
+ "Key": "test",
107
+ "RefValue": "test",
108
+ "StringValue": "test"
109
+ },
110
+ {
111
+ "Key": "test1",
112
+ "RefValue": "test1",
113
+ "StringValue": "test1"
114
+ }
115
+ ]
116
+ }
117
+ EOS
118
+ assert_equal exp_template.chomp, act_template
119
+ end
120
+
121
+ def test_datapipeline_pipeline_tags
122
+ template = <<-EOS
123
+ Test _datapipeline_pipeline_tags(tags: { test: "test", test1: "test1" })
124
+ EOS
125
+ act_template = run_client_as_json(template)
126
+ exp_template = <<-EOS
127
+ {
128
+ "Test": [
129
+ {
130
+ "Key": "test",
131
+ "Value": "test"
132
+ },
133
+ {
134
+ "Key": "test1",
135
+ "Value": "test1"
136
+ }
137
+ ]
138
+ }
139
+ EOS
140
+ assert_equal exp_template.chomp, act_template
141
+ end
142
+ end
@@ -0,0 +1,184 @@
1
+ require 'abstract_unit'
2
+ require 'kumogata/template/dynamodb'
3
+
4
+ class DynamodbTest < Minitest::Test
5
+ def test_dynamodb_attribute
6
+ template = <<-EOS
7
+ Test _dynamodb_attribute([ { integer: "test1" }, { binary: "test2" }, "test3" ])
8
+ EOS
9
+ act_template = run_client_as_json(template)
10
+ exp_template = <<-EOS
11
+ {
12
+ "Test": [
13
+ {
14
+ "AttributeName": "test1",
15
+ "AttributeType": "N"
16
+ },
17
+ {
18
+ "AttributeName": "test2",
19
+ "AttributeType": "B"
20
+ },
21
+ {
22
+ "AttributeName": "test3",
23
+ "AttributeType": "S"
24
+ }
25
+ ]
26
+ }
27
+ EOS
28
+ assert_equal exp_template.chomp, act_template
29
+ end
30
+
31
+ def test_dynamodb_key_schema
32
+ template = <<-EOS
33
+ Test _dynamodb_key_schema([ { hash: "test1" }, { range: "test2" }, "test3" ])
34
+ EOS
35
+ act_template = run_client_as_json(template)
36
+ exp_template = <<-EOS
37
+ {
38
+ "Test": [
39
+ {
40
+ "AttributeName": "test1",
41
+ "KeyType": "HASH"
42
+ },
43
+ {
44
+ "AttributeName": "test2",
45
+ "KeyType": "RANGE"
46
+ },
47
+ {
48
+ "AttributeName": "test3",
49
+ "KeyType": "HASH"
50
+ }
51
+ ]
52
+ }
53
+ EOS
54
+ assert_equal exp_template.chomp, act_template
55
+ end
56
+
57
+ def test_dynamodb_projection
58
+ template = <<-EOS
59
+ Test _dynamodb_projection(non_key: [ "test1" ], type: "include")
60
+ EOS
61
+ act_template = run_client_as_json(template)
62
+ exp_template = <<-EOS
63
+ {
64
+ "Test": {
65
+ "NonKeyAttributes": [
66
+ "test1"
67
+ ],
68
+ "ProjectionType": "INCLUDE"
69
+ }
70
+ }
71
+ EOS
72
+ assert_equal exp_template.chomp, act_template
73
+ end
74
+
75
+ def test_dynamodb_provisioned
76
+ template = <<-EOS
77
+ Test _dynamodb_provisioned(read: 100, write: 1000)
78
+ EOS
79
+ act_template = run_client_as_json(template)
80
+ exp_template = <<-EOS
81
+ {
82
+ "Test": {
83
+ "ReadCapacityUnits": "100",
84
+ "WriteCapacityUnits": "1000"
85
+ }
86
+ }
87
+ EOS
88
+ assert_equal exp_template.chomp, act_template
89
+ end
90
+
91
+ def test_dynamodb_stream
92
+ template = <<-EOS
93
+ Test _dynamodb_stream(stream: "test")
94
+ EOS
95
+ act_template = run_client_as_json(template)
96
+ exp_template = <<-EOS
97
+ {
98
+ "Test": {
99
+ "StreamViewType": "test"
100
+ }
101
+ }
102
+ EOS
103
+ assert_equal exp_template.chomp, act_template
104
+ end
105
+
106
+ def test_dynamodb_global
107
+ template = <<-EOS
108
+ Test _dynamodb_global(index: "test",
109
+ key_schema: [ { hash: "test1" }, { range: "test2" }, "test3" ],
110
+ projection: { non_key: [ "test1" ], type: "include" },
111
+ provisioned: { read: 100, write: 1000 })
112
+ EOS
113
+ act_template = run_client_as_json(template)
114
+ exp_template = <<-EOS
115
+ {
116
+ "Test": {
117
+ "IndexName": "test",
118
+ "KeySchema": [
119
+ {
120
+ "AttributeName": "test1",
121
+ "KeyType": "HASH"
122
+ },
123
+ {
124
+ "AttributeName": "test2",
125
+ "KeyType": "RANGE"
126
+ },
127
+ {
128
+ "AttributeName": "test3",
129
+ "KeyType": "HASH"
130
+ }
131
+ ],
132
+ "Projection": {
133
+ "NonKeyAttributes": [
134
+ "test1"
135
+ ],
136
+ "ProjectionType": "INCLUDE"
137
+ },
138
+ "ProvisionedThroughput": {
139
+ "ReadCapacityUnits": "100",
140
+ "WriteCapacityUnits": "1000"
141
+ }
142
+ }
143
+ }
144
+ EOS
145
+ assert_equal exp_template.chomp, act_template
146
+ end
147
+
148
+ def test_dynamodb_local
149
+ template = <<-EOS
150
+ Test _dynamodb_local(index: "test",
151
+ key_schema: [ { hash: "test1" }, { range: "test2" }, "test3" ],
152
+ projection: { non_key: [ "test1" ], type: "include" })
153
+ EOS
154
+ act_template = run_client_as_json(template)
155
+ exp_template = <<-EOS
156
+ {
157
+ "Test": {
158
+ "IndexName": "test",
159
+ "KeySchema": [
160
+ {
161
+ "AttributeName": "test1",
162
+ "KeyType": "HASH"
163
+ },
164
+ {
165
+ "AttributeName": "test2",
166
+ "KeyType": "RANGE"
167
+ },
168
+ {
169
+ "AttributeName": "test3",
170
+ "KeyType": "HASH"
171
+ }
172
+ ],
173
+ "Projection": {
174
+ "NonKeyAttributes": [
175
+ "test1"
176
+ ],
177
+ "ProjectionType": "INCLUDE"
178
+ }
179
+ }
180
+ }
181
+ EOS
182
+ assert_equal exp_template.chomp, act_template
183
+ end
184
+ end
data/test/ec2_test.rb ADDED
@@ -0,0 +1,286 @@
1
+ require 'abstract_unit'
2
+ require 'kumogata/template/ec2'
3
+
4
+ class Ec2Test < Minitest::Test
5
+ def test_ec2_tags
6
+ template = <<-EOS
7
+ Test _ec2_tags(name: "test")
8
+ EOS
9
+ act_template = run_client_as_json(template)
10
+ exp_template = <<-EOS
11
+ {
12
+ "Test": [
13
+ {
14
+ "Key": "Name",
15
+ "Value": {
16
+ "Fn::Join": [
17
+ "-",
18
+ [
19
+ {
20
+ "Ref": "Service"
21
+ },
22
+ "test"
23
+ ]
24
+ ]
25
+ }
26
+ },
27
+ {
28
+ "Key": "Service",
29
+ "Value": {
30
+ "Ref": "Service"
31
+ }
32
+ },
33
+ {
34
+ "Key": "Version",
35
+ "Value": {
36
+ "Ref": "Version"
37
+ }
38
+ },
39
+ {
40
+ "Key": "Domain",
41
+ "Value": {
42
+ "Ref": "Domain"
43
+ }
44
+ },
45
+ {
46
+ "Key": "Role",
47
+ "Value": {
48
+ "Ref": "Role"
49
+ }
50
+ }
51
+ ]
52
+ }
53
+ EOS
54
+ assert_equal exp_template.chomp, act_template
55
+
56
+ template = <<-EOS
57
+ Test _ec2_tags(name: "test", tags_append: { ref_test: "test" })
58
+ EOS
59
+ act_template = run_client_as_json(template)
60
+ exp_template = <<-EOS
61
+ {
62
+ "Test": [
63
+ {
64
+ "Key": "Name",
65
+ "Value": {
66
+ "Fn::Join": [
67
+ "-",
68
+ [
69
+ {
70
+ "Ref": "Service"
71
+ },
72
+ "test"
73
+ ]
74
+ ]
75
+ }
76
+ },
77
+ {
78
+ "Key": "Service",
79
+ "Value": {
80
+ "Ref": "Service"
81
+ }
82
+ },
83
+ {
84
+ "Key": "Version",
85
+ "Value": {
86
+ "Ref": "Version"
87
+ }
88
+ },
89
+ {
90
+ "Key": "Domain",
91
+ "Value": {
92
+ "Ref": "Domain"
93
+ }
94
+ },
95
+ {
96
+ "Key": "Role",
97
+ "Value": {
98
+ "Ref": "Role"
99
+ }
100
+ },
101
+ {
102
+ "Key": "Test",
103
+ "Value": {
104
+ "Ref": "Test"
105
+ }
106
+ }
107
+ ]
108
+ }
109
+ EOS
110
+ assert_equal exp_template.chomp, act_template
111
+ end
112
+
113
+ def test_ec2_security_group_egresses
114
+ template = <<-EOS
115
+ args = { egress: [ to: 80, group: "test" ] }
116
+ Test _ec2_security_group_egresses("egress", args)
117
+ EOS
118
+ act_template = run_client_as_json(template)
119
+ exp_template = <<-EOS
120
+ {
121
+ "Test": [
122
+ {
123
+ "CidrIp": "0.0.0.0/0",
124
+ "FromPort": "80",
125
+ "GroupId": "test",
126
+ "IpProtocol": "tcp",
127
+ "ToPort": "80"
128
+ }
129
+ ]
130
+ }
131
+ EOS
132
+ assert_equal exp_template.chomp, act_template
133
+ end
134
+
135
+ def test_ec2_security_group_eggress
136
+ template = <<-EOS
137
+ Test _ec2_security_group_egress(to: 80, group: "test")
138
+ EOS
139
+ act_template = run_client_as_json(template)
140
+ exp_template = <<-EOS
141
+ {
142
+ "Test": {
143
+ "CidrIp": "0.0.0.0/0",
144
+ "FromPort": "80",
145
+ "GroupId": "test",
146
+ "IpProtocol": "tcp",
147
+ "ToPort": "80"
148
+ }
149
+ }
150
+ EOS
151
+ assert_equal exp_template.chomp, act_template
152
+ end
153
+
154
+ def test_ec2_securiry_group_ingresses
155
+ template = <<-EOS
156
+ args = { ingress: [ from: 80 ] }
157
+ Test _ec2_security_group_ingresses("ingress", args)
158
+ EOS
159
+ act_template = run_client_as_json(template)
160
+ exp_template = <<-EOS
161
+ {
162
+ "Test": [
163
+ {
164
+ "CidrIp": "0.0.0.0/0",
165
+ "FromPort": "80",
166
+ "IpProtocol": "tcp",
167
+ "ToPort": "80"
168
+ }
169
+ ]
170
+ }
171
+ EOS
172
+ assert_equal exp_template.chomp, act_template
173
+ end
174
+
175
+ def test_ec2_security_group_ingress
176
+ template = <<-EOS
177
+ Test _ec2_security_group_ingress(from: 80)
178
+ EOS
179
+ act_template = run_client_as_json(template)
180
+ exp_template = <<-EOS
181
+ {
182
+ "Test": {
183
+ "CidrIp": "0.0.0.0/0",
184
+ "FromPort": "80",
185
+ "IpProtocol": "tcp",
186
+ "ToPort": "80"
187
+ }
188
+ }
189
+ EOS
190
+ assert_equal exp_template.chomp, act_template
191
+ end
192
+
193
+ def test_ec2_block_device
194
+ template = <<-EOS
195
+ Test _ec2_block_device(ref_size: "test")
196
+ EOS
197
+ act_template = run_client_as_json(template)
198
+ exp_template = <<-EOS
199
+ {
200
+ "Test": {
201
+ "DeviceName": "/dev/sda1",
202
+ "Ebs": {
203
+ "DeleteOnTermination": "true",
204
+ "VolumeSize": {
205
+ "Ref": "TestVolumeSize"
206
+ },
207
+ "VolumeType": "gp2"
208
+ }
209
+ }
210
+ }
211
+ EOS
212
+ assert_equal exp_template.chomp, act_template
213
+ end
214
+
215
+ def test_ec2_network_interface
216
+ template = <<-EOS
217
+ Test _ec2_network_interface(ref_subnet_id: "test")
218
+ EOS
219
+ act_template = run_client_as_json(template)
220
+ exp_template = <<-EOS
221
+ {
222
+ "Test": {
223
+ "AssociatePublicIpAddress": "true",
224
+ "DeleteOnTermination": "true",
225
+ "DeviceIndex": "0",
226
+ "SubnetId": ""
227
+ }
228
+ }
229
+ EOS
230
+ assert_equal exp_template.chomp, act_template
231
+ end
232
+
233
+ def test_ec2_image
234
+ template = <<-EOS
235
+ Test _ec2_image("test", {})
236
+ EOS
237
+ act_template = run_client_as_json(template)
238
+ exp_template = <<-EOS
239
+ {
240
+ "Test": {
241
+ "Fn::FindInMap": [
242
+ "AWSRegionArch2AMIAmazonLinuxOfficial",
243
+ {
244
+ "Ref": "AWS::Region"
245
+ },
246
+ {
247
+ "Fn::FindInMap": [
248
+ "AWSInstanceType2Arch",
249
+ "test",
250
+ "Arch"
251
+ ]
252
+ }
253
+ ]
254
+ }
255
+ }
256
+ EOS
257
+ assert_equal exp_template.chomp, act_template
258
+
259
+ template = <<-EOS
260
+ Test _ec2_image("test", { image_id: "test" })
261
+ EOS
262
+ act_template = run_client_as_json(template)
263
+ exp_template = <<-EOS
264
+ {
265
+ "Test": "test"
266
+ }
267
+ EOS
268
+ assert_equal exp_template.chomp, act_template
269
+ end
270
+
271
+ def test_ec2_port_range
272
+ template = <<-EOS
273
+ Test _ec2_port_range({})
274
+ EOS
275
+ act_template = run_client_as_json(template)
276
+ exp_template = <<-EOS
277
+ {
278
+ "Test": {
279
+ "From": "0",
280
+ "To": "65535"
281
+ }
282
+ }
283
+ EOS
284
+ assert_equal exp_template.chomp, act_template
285
+ end
286
+ end