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,96 @@
1
+ #
2
+ # Helper - IAM
3
+ #
4
+ require 'kumogata/template/helper'
5
+
6
+ def _iam_policies(name, args)
7
+ array = []
8
+ policies = args["#{name}".to_sym] || []
9
+ policies.each_with_index do |v, i|
10
+ array << _{
11
+ PolicyDocument _iam_policy_document("document", v)
12
+ PolicyName v[:name] || _resource_name("policy", i)
13
+ }
14
+ end
15
+ array
16
+ end
17
+
18
+ def _iam_policy_document(name, args)
19
+ array = []
20
+ documents = args["#{name}".to_sym] || []
21
+
22
+ documents.each do |v|
23
+ service = v[:service] || ""
24
+ action = v[:action] || [ "*" ]
25
+ next if service.empty? or action.empty?
26
+
27
+ actions = action.collect{|v| "#{service}:#{v}" }
28
+ if v.key? :resource
29
+ if v[:resource].is_a? String
30
+ resource = _iam_arn(service, v[:resource])
31
+ else
32
+ resource = v[:resource].collect{|v| _iam_arn(service, v) }
33
+ end
34
+ else
35
+ resource = [ "*" ]
36
+ end
37
+
38
+ array << _{
39
+ Effect v[:effect] || "Allow"
40
+ Action actions
41
+ Resource resource
42
+ Principal v[:principal] if v.key? :principal
43
+ }
44
+ end
45
+ array
46
+ end
47
+
48
+ def _iam_assume_role_policy_document(service)
49
+ [
50
+ _{
51
+ Effect "Allow"
52
+ Principal _{ Service [ "#{service}.amazonaws.com" ] }
53
+ Action [ "sts:AssumeRole" ]
54
+ }
55
+ ]
56
+ end
57
+
58
+ # Amazon Resource Names (ARNs) and AWS Service Namespaces
59
+ # https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
60
+ def _iam_arn(service, resource)
61
+ arn_prefix = "arn:aws:#{service}"
62
+
63
+ case service
64
+ when "s3"
65
+ if resource.is_a? String
66
+ "#{arn_prefix}:::#{resource}"
67
+ else
68
+ resources = [ "#{arn_prefix}:::" ]
69
+ resource.each do |v|
70
+ if v =~ /^Ref_(.*)/
71
+ resources << _{ Ref _resource_name($1) }
72
+ else
73
+ resources << v
74
+ end
75
+ end
76
+ _{ Fn__Join "", resources }
77
+ end
78
+
79
+ when "cloudformation"
80
+ if resource == "*"
81
+ resource
82
+ else
83
+ "#{arn_prefix}:#{resource[:region]}:#{resource[:account_id]}:stack/#{resource[:stack]}"
84
+ end
85
+
86
+ when "iam"
87
+ if resource.key? :sts
88
+ "arn:aws:sts::#{account_id}:#{resource[:type]}/#{resource[:user]}"
89
+ else
90
+ "#{arn_prefix}::#{account_id}:#{resource[:type]}/#{resource[:user]}"
91
+ end
92
+
93
+ when "elasticloadbalancing"
94
+ "#{arn_prefix}:*:*:loadbalancer/#{resource}"
95
+ end
96
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # Helper - Lambda
3
+ #
4
+ require 'kumogata/template/helper'
5
+
6
+ def _lambda_function_code(args)
7
+ return "" unless args.key? :code
8
+
9
+ code = args[:code]
10
+ s3_bucket = code[:s3_bucket]
11
+ s3_key = code[:s3_key]
12
+ s3_object_version = code[:s3_object_version] || ""
13
+
14
+ _{
15
+ S3Bucket s3_bucket
16
+ S3Key s3_key
17
+ S3ObjectVersion s3_object_version unless s3_object_version.empty?
18
+ #ZipFile
19
+ }
20
+ end
21
+
22
+ def _lambda_vpc_config(args)
23
+ return "" unless args.key? :vpc
24
+
25
+ vpc = args[:vpc]
26
+ security_group_ids = _ref_array("security_groups", vpc, "security group")
27
+ subnet_ids = _ref_array("subnets", vpc, "subnet")
28
+ return {} if security_group_ids.empty? and subnet_ids.empty?
29
+
30
+ _{
31
+ SecurityGroupIds security_group_ids unless security_group_ids.empty?
32
+ SubnetIds subnet_ids unless subnet_ids.empty?
33
+ }
34
+ end
@@ -0,0 +1,223 @@
1
+ #
2
+ # Helper - S3
3
+ #
4
+ require 'kumogata/template/helper'
5
+
6
+ def _s3_cors(args)
7
+ rules = args[:cors] || []
8
+
9
+ array = []
10
+ rules.each do |rule|
11
+ array << _{
12
+ AllowedHeaders _array(rule[:headers]) if rule.key? :headers
13
+ AllowedMethods _array(rule[:methods])
14
+ AllowedOrigins _array(rule[:origins])
15
+ ExposedHeaders _array(rule[:exposed_headers]) if rule.key? :exposed_headers
16
+ Id rule[:id] if rule.key? :id
17
+ MaxAge rule[:max_age] if rule.key? :max_age
18
+ }
19
+ end
20
+ return [] if array.empty?
21
+
22
+ _{
23
+ CorsRules array
24
+ }
25
+ end
26
+
27
+ def _s3_lifecycle(args)
28
+ rules = args[:lifecycle] || []
29
+ expiration_values = %w( ExpirationDate
30
+ NoncurrentVersionExpirationInDays
31
+ NoncurrentVersionTransition NoncurrentVersionTransitions
32
+ Transition Transitions )
33
+ status_values = %w( Enabled Disabled )
34
+
35
+ array = []
36
+ rules.each do |rule|
37
+ expiration_date = _valid_values(rule[:expiration_date],
38
+ expiration_values, "ExpirationInDays")
39
+ noncurrent_transitions = _s3_lifecycle_noncurrent_version_transition(rule)
40
+ status = _valid_values(rule[:status], status_values, "Enabled")
41
+ transitions = _s3_lifecycle_transition(rule)
42
+ array << _{
43
+ ExpirationDate expiration_date if rule.key? :expiration_date
44
+ ExpirationInDays rule[:expiration_in_days] if rule.key? :expiration_in_days
45
+ Id rule[:id] if rule.key? :id
46
+ NoncurrentVersionExpirationInDays rule[:non_expiration_in_days] if rule.key? :non_expiration_in_days
47
+ NoncurrentVersionTransitions noncurrent_transitions unless noncurrent_transitions.empty?
48
+ Prefix rule[:prefix] if rule.key? :prefix
49
+ Status status
50
+ Transitions transitions unless transitions.empty?
51
+ }
52
+ end
53
+ return [] if array.empty?
54
+
55
+ _{
56
+ Rules array
57
+ }
58
+ end
59
+
60
+ def _s3_lifecycle_noncurrent_version_transition(args)
61
+ transitions = args[:noncurrent_version_transitions] || []
62
+
63
+ array = []
64
+ transitions.each do |transition|
65
+ array << _{
66
+ StorageClass transition[:storage]
67
+ TransitionInDays transition[:transition]
68
+ }
69
+ end
70
+ array
71
+ end
72
+
73
+ def _s3_lifecycle_transition(args)
74
+ transitions = args[:transitions] || []
75
+
76
+ array = []
77
+ transitions.each do |transition|
78
+ array << _{
79
+ StorageClass transition[:storage]
80
+ TransitionDate transition[:date] if transition.key? :date
81
+ TransitionInDays transition[:in_days] if transition.key? :in_days
82
+ }
83
+ end
84
+ array
85
+ end
86
+
87
+ def _s3_logging(args)
88
+ return "" unless args.key? :logging
89
+ logging = args[:logging]
90
+
91
+ _{
92
+ DestinationBucketName logging[:destination]
93
+ LogFilePrefix logging[:prefix] || ""
94
+ }
95
+ end
96
+
97
+ def _s3_notification(args)
98
+ return "" unless args.key? :notification
99
+ notification = args[:notification]
100
+ lambda = _s3_notification_configuration(notification, :lambda)
101
+ queue = _s3_notification_configuration(notification, :queue)
102
+ topic = _s3_notification_configuration(notification, :topic)
103
+
104
+ _{
105
+ LambdaConfigurations lambda unless lambda.empty?
106
+ QueueConfigurations queue unless queue.empty?
107
+ TopicConfigurations topic unless topic.empty?
108
+ }
109
+ end
110
+
111
+ def _s3_notification_configuration(args, key)
112
+ values = args[key] || []
113
+
114
+ array = []
115
+ values.each do |value|
116
+ array << _{
117
+ Event value[:event]
118
+ Filter _{ S3Key value[:filter] } if value.key? :filter
119
+ case key
120
+ when :lambda
121
+ Function value[:function]
122
+ when :queue
123
+ Queue value[:queue]
124
+ when :topic
125
+ Topic value[:topic]
126
+ end
127
+ }
128
+ end
129
+ array
130
+ end
131
+
132
+ def _s3_replication(args)
133
+ return "" unless args.key? :replication
134
+ replication = args[:replication]
135
+ rules = _s3_replication_rules(replication)
136
+
137
+ _{
138
+ Role replication[:role]
139
+ Rules rules
140
+ }
141
+ end
142
+
143
+ def _s3_replication_rules(args)
144
+ rules = args[:rules] || []
145
+
146
+ array = []
147
+ rules.each do |rule|
148
+ destination = _s3_replication_rules_destination(rule[:destination])
149
+ array << _{
150
+ Destination destination
151
+ Id rule[:id]
152
+ Prefix rule[:prefix]
153
+ Status rule[:status]
154
+ }
155
+ end
156
+ array
157
+ end
158
+
159
+ def _s3_replication_rules_destination(args)
160
+ _{
161
+ Bucket args[:bucket]
162
+ StorageClass args[:storage]
163
+ }
164
+ end
165
+
166
+ def _s3_versioning(args)
167
+ return "" unless args.key? :versioning
168
+ versioning = args[:versioning]
169
+ status_values = %w( Enabled Disabled )
170
+ status = _valid_values(versioning[:status], status_values, "Enabled")
171
+
172
+ _{
173
+ Status status
174
+ }
175
+ end
176
+
177
+ def _s3_website(args)
178
+ return "" unless args.key? :website
179
+ website = args[:website]
180
+ redirect = _s3_website_redirect_all_request(website)
181
+ routing = _s3_website_routing_rules(website)
182
+
183
+ _{
184
+ ErrorDocument website[:error] || "404.html"
185
+ IndexDocument website[:index] || "index.html"
186
+ RedirectAllRequestsTo redirect unless redirect.empty?
187
+ RoutingRules routing unless routing.empty?
188
+ }
189
+ end
190
+
191
+ def _s3_website_redirect_all_request(args)
192
+ return "" unless args.key? :redirect
193
+ redirect = args[:redirect] || {}
194
+
195
+ _{
196
+ HostName redirect[:hostname]
197
+ Protocol _valid_values(redirect[:protocol], %w( http https ), "http")
198
+ }
199
+ end
200
+
201
+ def _s3_website_routing_rules(args)
202
+ routing = args[:routing] || []
203
+
204
+ array = []
205
+ routing.each do |route|
206
+ array << _{
207
+ RedirectRule do
208
+ redirect = route[:redirect] || {}
209
+ HostName redirect[:host] if redirect.key? :host
210
+ HttpRedirectCode redirect[:http] if redirect.key? :http
211
+ Protocol redirect[:protocol] if redirect.key? :protocol
212
+ ReplaceKeyPrefixWith redirect[:replace_key_prefix] if redirect.key? :replace_key_prefix
213
+ ReplaceKeyWith redirect[:replace_key_with] if redirect.key? :replace_key_with
214
+ end
215
+ RoutingRuleCondition do
216
+ routing = route[:routing] || {}
217
+ HttpErrorCodeReturnedEquals routing[:http]
218
+ KeyPrefixEquals routing[:key_prefix]
219
+ end
220
+ }
221
+ end
222
+ array
223
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # Helper - SNS
3
+ #
4
+ require 'kumogata/template/helper'
5
+
6
+ def _sns_subscription(args)
7
+ array = []
8
+ types = args[:subscription] || []
9
+ types.each do |v|
10
+ protocol = _valid_values(v[:protocol],
11
+ [ "http", "https", "email", "email-json", "sms", "sqs", "application", "lambda" ],
12
+ "email")
13
+ case protocol
14
+ when "lambda", "sqs"
15
+ endpoint = _attr_string(v[:endpoint], "Arn")
16
+ else
17
+ endpoint = v[:endpoint]
18
+ end
19
+ array << _{
20
+ Endpoint endpoint
21
+ Protocol protocol
22
+ }
23
+ end
24
+ array
25
+ end
@@ -0,0 +1 @@
1
+ KUMOGATA_TEMPLATE_VERSION = '0.0.1'
@@ -0,0 +1,25 @@
1
+ AWSTemplateFormatVersion "2010-09-09"
2
+
3
+ Description (<<-EOS).undent
4
+ Kumogata Template - #{NAME} stack
5
+ EOS
6
+
7
+ Parameters do
8
+ _parameter "name", default: "#{NAME}",
9
+ description: "name of this stack"
10
+ _parameter "service", default: "service",
11
+ description: "#{NAME} service"
12
+ _parameter "version", default: "1.0.0",
13
+ description: "#{NAME} version"
14
+ end
15
+
16
+ Mappings do
17
+ end
18
+
19
+ Resources do
20
+ _s3_bucket "#{NAME}"
21
+ end
22
+
23
+ Outputs do
24
+ _output_s3 "#{NAME}"
25
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ # Autoscaling AutoScalingGroup resource
3
+ # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html
4
+ #
5
+ require 'kumogata/template/helper'
6
+ require 'kumogata/template/autoscaling'
7
+
8
+ name = _resource_name(args[:name], "autoscaling group")
9
+ azs = _availability_zones(args)
10
+ cooldown = args[:cooldown] || -1
11
+ desired = args[:desired] || ""
12
+ health_check_grace = args[:health_check_grace] || -1
13
+ health_check_type = _valid_values(args[:helath_check_type], %w( ec2 elb ), "ec2")
14
+ instance = _ref_string("instance", args)
15
+ launch = _ref_string("launch", args, "autoscaling launch configuration")
16
+ load_balancers = _ref_array("load_balancers", args)
17
+ max = args[:max] || 1
18
+ metrics = [ _autoscaling_metrics ]
19
+ min = args[:min] || 0
20
+ max = min if max < min
21
+ notifications = (args[:notifications] || []).collect{|v| _autoscaling_notification(v) }
22
+ placement = args[:placement] || ""
23
+ tags = _autoscaling_tags(args)
24
+ termination = args[:termination] || []
25
+ vpc_zones = _ref_array("vpc_zones", args, "subnet")
26
+
27
+ _(name) do
28
+ Type "AWS::AutoScaling::AutoScalingGroup"
29
+ Properties do
30
+ AvailabilityZones azs if vpc_zones.empty?
31
+ Cooldown cooldown unless cooldown == -1
32
+ DesiredCapacity desired unless desired.empty?
33
+ HealthCheckGracePeriod health_check_grace unless health_check_grace == -1
34
+ HealthCheckType health_check_type.upcase
35
+ InstanceId instance unless instance.empty?
36
+ LaunchConfigurationName launch if instance.empty?
37
+ LoadBalancerNames load_balancers unless load_balancers.empty?
38
+ MaxSize max
39
+ MetricsCollection metrics
40
+ MinSize min
41
+ NotificationConfigurations notifications
42
+ PlacementGroup placement unless placement.empty?
43
+ Tags tags
44
+ TerminationPolicies termination unless termination.empty?
45
+ VPCZoneIdentifier vpc_zones unless vpc_zones.empty?
46
+ end
47
+ end