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
data/test/iam_test.rb CHANGED
@@ -2,57 +2,6 @@ require 'abstract_unit'
2
2
  require 'kumogata/template/iam'
3
3
 
4
4
  class IamTest < Minitest::Test
5
- def test_iam_to_policy_condition
6
- template = <<-EOS
7
- condition = { "=": [ "s3:x-amz-acl", "bucket-owner-full-control" ] }
8
- Test _iam_to_policy_condition(condition)
9
- EOS
10
- act_template = run_client_as_json(template)
11
- exp_template = <<-EOS
12
- {
13
- "Test": {
14
- "StringEquals": {
15
- "s3:x-amz-acl": "bucket-owner-full-control"
16
- }
17
- }
18
- }
19
- EOS
20
- assert_equal exp_template.chomp, act_template
21
-
22
- template = <<-EOS
23
- condition = {
24
- "=": [ "aws:UserAgent", "Example Corp Java Client" ],
25
- "date greater than": [ "aws:CurrentTime", "2013-08-16T12:00:00Z" ],
26
- "numeric less than equals": [ "s3:max-keys", "10" ],
27
- "ip address": [ "aws:SourceIp", ["192.0.2.0/24", "203.0.113.0/24"] ],
28
- }
29
- Test _iam_to_policy_condition(condition)
30
- EOS
31
- act_template = run_client_as_json(template)
32
- exp_template = <<-EOS
33
- {
34
- "Test": {
35
- "StringEquals": {
36
- "aws:UserAgent": "Example Corp Java Client"
37
- },
38
- "DateGreaterThan": {
39
- "aws:CurrentTime": "2013-08-16T12:00:00Z"
40
- },
41
- "NumericLessThanEquals": {
42
- "s3:max-keys": "10"
43
- },
44
- "IpAddress": {
45
- "aws:SourceIp": [
46
- "192.0.2.0/24",
47
- "203.0.113.0/24"
48
- ]
49
- }
50
- }
51
- }
52
- EOS
53
- assert_equal exp_template.chomp, act_template
54
- end
55
-
56
5
  def test_iam_policies
57
6
  template = <<-EOS
58
7
  Policies _iam_policies "test", test: [ { document: [ { service: "s3" } ] } ]
@@ -76,7 +25,17 @@ Policies _iam_policies "test", test: [ { document: [ { service: "s3" } ] } ]
76
25
  }
77
26
  ]
78
27
  },
79
- "PolicyName": "Policy0"
28
+ "PolicyName": {
29
+ "Fn::Join": [
30
+ "-",
31
+ [
32
+ {
33
+ "Ref": "Service"
34
+ },
35
+ "policy-1"
36
+ ]
37
+ ]
38
+ }
80
39
  }
81
40
  ]
82
41
  }
@@ -188,6 +147,114 @@ PolicyDocument _iam_policy_document "test", test: [ { service: "s3" } ]
188
147
  EOS
189
148
  assert_equal exp_template.chomp, act_template
190
149
 
150
+ template = <<-EOS
151
+ PolicyDocument _iam_policy_document "test", test: [ { service: "s3", action: "put object" } ]
152
+ EOS
153
+ act_template = run_client_as_json(template)
154
+ exp_template = <<-EOS
155
+ {
156
+ "PolicyDocument": [
157
+ {
158
+ "Effect": "Allow",
159
+ "Action": [
160
+ "s3:PutObject"
161
+ ],
162
+ "Resource": [
163
+ "*"
164
+ ]
165
+ }
166
+ ]
167
+ }
168
+ EOS
169
+ assert_equal exp_template.chomp, act_template
170
+
171
+ template = <<-EOS
172
+ PolicyDocument _iam_policy_document "test", test: [ { service: "s3", action: "PutObject" } ]
173
+ EOS
174
+ act_template = run_client_as_json(template)
175
+ exp_template = <<-EOS
176
+ {
177
+ "PolicyDocument": [
178
+ {
179
+ "Effect": "Allow",
180
+ "Action": [
181
+ "s3:PutObject"
182
+ ],
183
+ "Resource": [
184
+ "*"
185
+ ]
186
+ }
187
+ ]
188
+ }
189
+ EOS
190
+ assert_equal exp_template.chomp, act_template
191
+
192
+ template = <<-EOS
193
+ PolicyDocument _iam_policy_document "test", test: [ { services: [ "s3", "ec2" ] } ]
194
+ EOS
195
+ act_template = run_client_as_json(template)
196
+ exp_template = <<-EOS
197
+ {
198
+ "PolicyDocument": [
199
+ {
200
+ "Effect": "Allow",
201
+ "Action": [
202
+ "s3:*",
203
+ "ec2:*"
204
+ ],
205
+ "Resource": [
206
+ "*"
207
+ ]
208
+ }
209
+ ]
210
+ }
211
+ EOS
212
+ assert_equal exp_template.chomp, act_template
213
+
214
+ template = <<-EOS
215
+ PolicyDocument _iam_policy_document "test", test: [ { service: "s3", actions: [ "get object *", "put object" ] } ]
216
+ EOS
217
+ act_template = run_client_as_json(template)
218
+ exp_template = <<-EOS
219
+ {
220
+ "PolicyDocument": [
221
+ {
222
+ "Effect": "Allow",
223
+ "Action": [
224
+ "s3:GetObject*",
225
+ "s3:PutObject"
226
+ ],
227
+ "Resource": [
228
+ "*"
229
+ ]
230
+ }
231
+ ]
232
+ }
233
+ EOS
234
+ assert_equal exp_template.chomp, act_template
235
+
236
+ template = <<-EOS
237
+ PolicyDocument _iam_policy_document "test", test: [ { service: "s3", actions: [ "GetObject*", "PutObject" ] } ]
238
+ EOS
239
+ act_template = run_client_as_json(template)
240
+ exp_template = <<-EOS
241
+ {
242
+ "PolicyDocument": [
243
+ {
244
+ "Effect": "Allow",
245
+ "Action": [
246
+ "s3:GetObject*",
247
+ "s3:PutObject"
248
+ ],
249
+ "Resource": [
250
+ "*"
251
+ ]
252
+ }
253
+ ]
254
+ }
255
+ EOS
256
+ assert_equal exp_template.chomp, act_template
257
+
191
258
  template = <<-EOS
192
259
  PolicyDocument _iam_policy_document "test", test: [ { service: "s3", sid: "test" } ]
193
260
  EOS
@@ -211,7 +278,28 @@ PolicyDocument _iam_policy_document "test", test: [ { service: "s3", sid: "test"
211
278
  assert_equal exp_template.chomp, act_template
212
279
 
213
280
  template = <<-EOS
214
- condition = { "=": [ "s3:x-amz-acl", "bucket-owner-full-control" ] }
281
+ PolicyDocument _iam_policy_document "test", test: [ { service: "s3", resource: "test" } ]
282
+ EOS
283
+ act_template = run_client_as_json(template)
284
+ exp_template = <<-EOS
285
+ {
286
+ "PolicyDocument": [
287
+ {
288
+ "Effect": "Allow",
289
+ "Action": [
290
+ "s3:*"
291
+ ],
292
+ "Resource": [
293
+ "arn:aws:s3:::test"
294
+ ]
295
+ }
296
+ ]
297
+ }
298
+ EOS
299
+ assert_equal exp_template.chomp, act_template
300
+
301
+ template = <<-EOS
302
+ condition = { '=': { 's3:x-amz-acl': "bucket-owner-full-control" } }
215
303
  PolicyDocument _iam_policy_document "test", test: [ { service: "s3", sid: "test", condition: condition } ]
216
304
  EOS
217
305
  act_template = run_client_as_json(template)
@@ -240,6 +328,48 @@ PolicyDocument _iam_policy_document "test", test: [ { service: "s3", sid: "test"
240
328
  end
241
329
 
242
330
  def test_iam_assume_role_policy_document
331
+ template = <<-EOS
332
+ Statement _iam_assume_role_policy_document({ aws: [ { account_id: 123, root: true } ] })
333
+ EOS
334
+ act_template = run_client_as_json(template)
335
+ exp_template = <<-EOS
336
+ {
337
+ "Statement": [
338
+ {
339
+ "Effect": "Allow",
340
+ "Principal": {
341
+ "AWS": "arn:aws:iam::123:root"
342
+ },
343
+ "Action": [
344
+ "sts:AssumeRole"
345
+ ]
346
+ }
347
+ ]
348
+ }
349
+ EOS
350
+ assert_equal exp_template.chomp, act_template
351
+
352
+ template = <<-EOS
353
+ Statement _iam_assume_role_policy_document({ federated: "test" })
354
+ EOS
355
+ act_template = run_client_as_json(template)
356
+ exp_template = <<-EOS
357
+ {
358
+ "Statement": [
359
+ {
360
+ "Effect": "Allow",
361
+ "Principal": {
362
+ "Federated": "test"
363
+ },
364
+ "Action": [
365
+ "sts:AssumeRole"
366
+ ]
367
+ }
368
+ ]
369
+ }
370
+ EOS
371
+ assert_equal exp_template.chomp, act_template
372
+
243
373
  template = <<-EOS
244
374
  Statement _iam_assume_role_policy_document({ service: "ec2" })
245
375
  EOS
@@ -251,7 +381,7 @@ Statement _iam_assume_role_policy_document({ service: "ec2" })
251
381
  "Effect": "Allow",
252
382
  "Principal": {
253
383
  "Service": [
254
- "ec2.amazonaws.com"
384
+ "ec2.#{DOMAIN}"
255
385
  ]
256
386
  },
257
387
  "Action": [
@@ -259,6 +389,35 @@ Statement _iam_assume_role_policy_document({ service: "ec2" })
259
389
  ]
260
390
  }
261
391
  ]
392
+ }
393
+ EOS
394
+ assert_equal exp_template.chomp, act_template
395
+
396
+ template = <<-EOS
397
+ Statement _iam_assume_role_policy_document({ cognito: true, cond_auds: "test", cond_amr: "test" })
398
+ EOS
399
+ act_template = run_client_as_json(template)
400
+ exp_template = <<-EOS
401
+ {
402
+ "Statement": [
403
+ {
404
+ "Effect": "Allow",
405
+ "Principal": {
406
+ "Federated": "cognito-identity.#{DOMAIN}"
407
+ },
408
+ "Action": [
409
+ "sts:AssumeRoleWithWebIdentity"
410
+ ],
411
+ "Condition": {
412
+ "StringEquals": {
413
+ "cognito-identity.#{DOMAIN}:aud": "test"
414
+ },
415
+ "ForAnyValue:StringLike": {
416
+ "cognito-identity.#{DOMAIN}:amr": "test"
417
+ }
418
+ }
419
+ }
420
+ ]
262
421
  }
263
422
  EOS
264
423
  assert_equal exp_template.chomp, act_template
@@ -312,7 +471,7 @@ arn _iam_arn("s3", [ "test1", "test2" ])
312
471
  assert_equal exp_template.chomp, act_template
313
472
 
314
473
  template = <<-EOS
315
- arn _iam_arn("s3", [ { ref: "test" }, { ref_account: true }, "/*" ])
474
+ arn _iam_arn("s3", [ { ref: "test" }, { ref_account_id: true }, "/*" ])
316
475
  EOS
317
476
  act_template = run_client_as_json(template)
318
477
  exp_template = <<-EOS
@@ -337,8 +496,8 @@ arn _iam_arn("s3", [ { ref: "test" }, { ref_account: true }, "/*" ])
337
496
  assert_equal exp_template.chomp, act_template
338
497
 
339
498
  template = <<-EOS
340
- test1 = [ { ref: "test1" }, { ref_account: true }, "/*" ]
341
- test2 = [ { ref: "test2" }, { ref_account: true }, "/*" ]
499
+ test1 = [ { ref: "test1" }, { ref_account_id: true }, "/*" ]
500
+ test2 = [ { ref: "test2" }, { ref_account_id: true }, "/*" ]
342
501
  arn _iam_arn("s3", [ test1, test2 ])
343
502
  EOS
344
503
  act_template = run_client_as_json(template)
@@ -376,6 +535,129 @@ arn _iam_arn("s3", [ test1, test2 ])
376
535
  ]
377
536
  }
378
537
  ]
538
+ }
539
+ EOS
540
+ assert_equal exp_template.chomp, act_template
541
+
542
+ template = <<-EOS
543
+ arn _iam_arn("apigateway", { path: "teste:testp/tests" })
544
+ EOS
545
+ act_template = run_client_as_json(template)
546
+ exp_template = <<-EOS
547
+ {
548
+ "arn": {
549
+ "Fn::Sub": "arn:aws:apigateway:${AWS::Region}::teste:testp/tests"
550
+ }
551
+ }
552
+ EOS
553
+ assert_equal exp_template.chomp, act_template
554
+
555
+ template = <<-EOS
556
+ arn _iam_arn("execute-api", { id: "test" })
557
+ EOS
558
+ act_template = run_client_as_json(template)
559
+ exp_template = <<-EOS
560
+ {
561
+ "arn": {
562
+ "Fn::Sub": "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:test/*/*/*"
563
+ }
564
+ }
565
+ EOS
566
+ assert_equal exp_template.chomp, act_template
567
+
568
+ template = <<-EOS
569
+ arn _iam_arn("execute-api", { id: "test", region: "testr", account_id: "testa" })
570
+ EOS
571
+ act_template = run_client_as_json(template)
572
+ exp_template = <<-EOS
573
+ {
574
+ "arn": "arn:aws:execute-api:testr:testa:test/*/*/*"
575
+ }
576
+ EOS
577
+ assert_equal exp_template.chomp, act_template
578
+ end
579
+
580
+ def test_iam_arn_resource
581
+ template = <<-EOS
582
+ arn _iam_arn_resource("arn:aws:s3", [ "test" ])
583
+ EOS
584
+ act_template = run_client_as_json(template)
585
+ exp_template = <<-EOS
586
+ {
587
+ "arn": {
588
+ "Fn::Sub": "arn:aws:s3:${AWS::Region}:${AWS::AccountId}:test"
589
+ }
590
+ }
591
+ EOS
592
+ assert_equal exp_template.chomp, act_template
593
+
594
+ template = <<-EOS
595
+ arn _iam_arn_resource("arn:aws:s3", { account_id: "testa", region: "testr", value: "test" })
596
+ EOS
597
+ act_template = run_client_as_json(template)
598
+ exp_template = <<-EOS
599
+ {
600
+ "arn": "arn:aws:s3:testr:testa:test"
601
+ }
602
+ EOS
603
+ assert_equal exp_template.chomp, act_template
604
+
605
+ template = <<-EOS
606
+ arn _iam_arn_resource("arn:aws:s3", { account_id: "testa", region: false, value: "test" })
607
+ EOS
608
+ act_template = run_client_as_json(template)
609
+ exp_template = <<-EOS
610
+ {
611
+ "arn": "arn:aws:s3::testa:test"
612
+ }
613
+ EOS
614
+ assert_equal exp_template.chomp, act_template
615
+
616
+ template = <<-EOS
617
+ values = [ "*/", { ref_: "test" }, "/*" ]
618
+ arn _iam_arn_resource("arn:aws:s3", { account_id: false, region: "testr", values: values })
619
+ EOS
620
+ act_template = run_client_as_json(template)
621
+ exp_template = <<-EOS
622
+ {
623
+ "arn": {
624
+ "Fn::Join": [
625
+ "",
626
+ [
627
+ "arn:aws:s3:testr::",
628
+ "*/",
629
+ {
630
+ "Ref": "Test"
631
+ },
632
+ "/*"
633
+ ]
634
+ ]
635
+ }
636
+ }
637
+ EOS
638
+ assert_equal exp_template.chomp, act_template
639
+
640
+ template = <<-EOS
641
+ values = [ { import_: "test" }, "/*/*" ]
642
+ arn _iam_arn_resource("arn:aws:s3", { account_id: false, region: "testr", values: values })
643
+ EOS
644
+ act_template = run_client_as_json(template)
645
+ exp_template = <<-EOS
646
+ {
647
+ "arn": {
648
+ "Fn::Join": [
649
+ "",
650
+ [
651
+ "arn:aws:s3:testr::",
652
+ {
653
+ "Fn::ImportValue": {
654
+ "Fn::Sub": "test"
655
+ }
656
+ },
657
+ "/*/*"
658
+ ]
659
+ ]
660
+ }
379
661
  }
380
662
  EOS
381
663
  assert_equal exp_template.chomp, act_template
@@ -407,6 +689,239 @@ managed _iam_managed_policies(managed_policies: %w( admin ))
407
689
  "managed": [
408
690
  "arn:aws:iam::aws:policy/AdministratorAccess"
409
691
  ]
692
+ }
693
+ EOS
694
+ assert_equal exp_template.chomp, act_template
695
+ end
696
+
697
+ def test_iam_policy_conditions
698
+ # {"StringEquals": {"aws:UserAgent": "Example Corp Java Client"}}
699
+ template = <<-EOS
700
+ conds = [
701
+ { '=': { 'aws:UserAgent': 'Example Corp Java Client' } },
702
+ ]
703
+ Condition _iam_policy_conditions(conds)
704
+ EOS
705
+ act_template = run_client_as_json(template)
706
+ exp_template = <<-EOS
707
+ {
708
+ "Condition": {
709
+ "StringEquals": {
710
+ "aws:UserAgent": "Example Corp Java Client"
711
+ }
712
+ }
713
+ }
714
+ EOS
715
+ assert_equal exp_template.chomp, act_template
716
+
717
+ # {"StringLike": {"s3:prefix": [
718
+ # "",
719
+ # "home/",
720
+ # "home/${aws:username}/"
721
+ # ]}}
722
+ template = <<-EOS
723
+ conds = [
724
+ { '=~': { 's3:prefix': [ "", "home/", "home/${aws:username}/" ] } }
725
+ ]
726
+ Condition _iam_policy_conditions(conds)
727
+ EOS
728
+ act_template = run_client_as_json(template)
729
+ exp_template = <<-EOS
730
+ {
731
+ "Condition": {
732
+ "StringLike": {
733
+ "s3:prefix": [
734
+ "",
735
+ "home/",
736
+ "home/${aws:username}/"
737
+ ]
738
+ }
739
+ }
740
+ }
741
+ EOS
742
+ assert_equal exp_template.chomp, act_template
743
+
744
+ # {"NumericLessThanEquals": {"s3:max-keys": "10"}}
745
+ template = <<-EOS
746
+ conds = [
747
+ { '<=': { 's3:max-keys': 10 } }
748
+ ]
749
+ Condition _iam_policy_conditions(conds)
750
+ EOS
751
+ act_template = run_client_as_json(template)
752
+ exp_template = <<-EOS
753
+ {
754
+ "Condition": {
755
+ "NumericLessThanEquals": {
756
+ "s3:max-keys": "10"
757
+ }
758
+ }
759
+ }
760
+ EOS
761
+ assert_equal exp_template.chomp, act_template
762
+
763
+ # {"DateLessThan": {"aws:CurrentTime": "2013-06-30T00:00:00Z"}}
764
+ template = <<-EOS
765
+ conds = [
766
+ { '<': { type: 'date', 'aws:CurrentTime': '2013-06-30T00:00:00Z' } }
767
+ ]
768
+ Condition _iam_policy_conditions(conds)
769
+ EOS
770
+ act_template = run_client_as_json(template)
771
+ exp_template = <<-EOS
772
+ {
773
+ "Condition": {
774
+ "DateLessThan": {
775
+ "aws:CurrentTime": "2013-06-30T00:00:00Z"
776
+ }
777
+ }
778
+ }
779
+ EOS
780
+ assert_equal exp_template.chomp, act_template
781
+
782
+ # {"Bool": {"aws:SecureTransport": "true"}}
783
+ template = <<-EOS
784
+ conds = [
785
+ { '=': { 'aws:SecureTransport': true } }
786
+ ]
787
+ Condition _iam_policy_conditions(conds)
788
+ EOS
789
+ act_template = run_client_as_json(template)
790
+ exp_template = <<-EOS
791
+ {
792
+ "Condition": {
793
+ "Bool": {
794
+ "aws:SecureTransport": "true"
795
+ }
796
+ }
797
+ }
798
+ EOS
799
+ assert_equal exp_template.chomp, act_template
800
+
801
+ # "BinaryEquals": { "key" : "QmluYXJ5VmFsdWVJbkJhc2U2NA==" }
802
+ template = <<-EOS
803
+ conds = [
804
+ { '=': { type: 'bin', 'key': 'QmluYXJ5VmFsdWVJbkJhc2U2NA==' } }
805
+ ]
806
+ Condition _iam_policy_conditions(conds)
807
+ EOS
808
+ act_template = run_client_as_json(template)
809
+ exp_template = <<-EOS
810
+ {
811
+ "Condition": {
812
+ "BinaryEquals": {
813
+ "key": "QmluYXJ5VmFsdWVJbkJhc2U2NA=="
814
+ }
815
+ }
816
+ }
817
+ EOS
818
+ assert_equal exp_template.chomp, act_template
819
+
820
+ # {"IpAddress": {"aws:SourceIp": "203.0.113.0/24"}}
821
+ template = <<-EOS
822
+ conds = [
823
+ { '=': { type: 'ip', 'aws:SourceType': '203.0.113.0/24' } }
824
+ ]
825
+ Condition _iam_policy_conditions(conds)
826
+ EOS
827
+ act_template = run_client_as_json(template)
828
+ exp_template = <<-EOS
829
+ {
830
+ "Condition": {
831
+ "IpAddress": {
832
+ "aws:SourceType": "203.0.113.0/24"
833
+ }
834
+ }
835
+ }
836
+ EOS
837
+ assert_equal exp_template.chomp, act_template
838
+
839
+ # {"ArnEquals": {"aws:SourceArn": "arn:aws:sns:REGION:123456789012:TOPIC-ID"}}
840
+ template = <<-EOS
841
+ conds = [
842
+ { '=': { type: 'arn', 'aws:SourceArn': 'arn:aws:sns:REGION:123456789012:TOPIC-ID' } }
843
+ ]
844
+ Condition _iam_policy_conditions(conds)
845
+ EOS
846
+ act_template = run_client_as_json(template)
847
+ exp_template = <<-EOS
848
+ {
849
+ "Condition": {
850
+ "ArnEquals": {
851
+ "aws:SourceArn": "arn:aws:sns:REGION:123456789012:TOPIC-ID"
852
+ }
853
+ }
854
+ }
855
+ EOS
856
+ assert_equal exp_template.chomp, act_template
857
+
858
+ # {"StringLikeIfExists": {"ec2:InstanceType": [
859
+ # "t1.*",
860
+ # "t2.*",
861
+ # "m3.*"
862
+ # ]}}
863
+ template = <<-EOS
864
+ conds = [
865
+ { '=~': { exists: true, 'ec2:InstanceType': [ 't1.*', 't2.*', 'm3.*' ] } }
866
+ ]
867
+ Condition _iam_policy_conditions(conds)
868
+ EOS
869
+ act_template = run_client_as_json(template)
870
+ exp_template = <<-EOS
871
+ {
872
+ "Condition": {
873
+ "StringLikeIfExists": {
874
+ "ec2:InstanceType": [
875
+ "t1.*",
876
+ "t2.*",
877
+ "m3.*"
878
+ ]
879
+ }
880
+ }
881
+ }
882
+ EOS
883
+ assert_equal exp_template.chomp, act_template
884
+
885
+ # {"Null":{"aws:TokenIssueTime":"true"}}
886
+ template = <<-EOS
887
+ conds = [
888
+ { '=': { type: 'nil', 'aws:TokenIssueTime': 'true' } }
889
+ ]
890
+ Condition _iam_policy_conditions(conds)
891
+ EOS
892
+ act_template = run_client_as_json(template)
893
+ exp_template = <<-EOS
894
+ {
895
+ "Condition": {
896
+ "Null": {
897
+ "aws:TokenIssueTime": "true"
898
+ }
899
+ }
900
+ }
901
+ EOS
902
+ assert_equal exp_template.chomp, act_template
903
+
904
+ # "StringEquals": {
905
+ # "kms:EncryptionContext:aws:kinesis:arn":
906
+ # "arn:aws:kinesis:%REGION_NAME%:12345:stream/%FIREHOSE_STREAM_NAME%"
907
+ # }
908
+ template = <<-EOS
909
+ iam = _iam_arn('kinesis', [ { name: '%FIREHOSE_STREAM_NAME%' } ])
910
+ conds = [
911
+ { '=': { 'kms:EncryptionContext:aws:kinesis:arn': iam } },
912
+ ]
913
+ Condition _iam_policy_conditions(conds)
914
+ EOS
915
+ act_template = run_client_as_json(template)
916
+ exp_template = <<-EOS
917
+ {
918
+ "Condition": {
919
+ "StringEquals": {
920
+ "kms:EncryptionContext:aws:kinesis:arn": {
921
+ "Fn::Sub": "arn:aws:kinesis:${AWS::Region}:${AWS::AccountId}:stream/%FIREHOSE_STREAM_NAME%"
922
+ }
923
+ }
924
+ }
410
925
  }
411
926
  EOS
412
927
  assert_equal exp_template.chomp, act_template
data/test/lambda_test.rb CHANGED
@@ -26,7 +26,7 @@ Test _lambda_function_code(code: { zip_file: "test/data/lambda_function.py" })
26
26
  "Test": {
27
27
  "ZipFile": {
28
28
  "Fn::Join": [
29
- "\\\\n",
29
+ "\\n",
30
30
  [
31
31
  "import boto3",
32
32
  "",