cumulus-aws 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +29 -0
  6. data/LICENSE +202 -0
  7. data/README.md +41 -0
  8. data/autocomplete +137 -0
  9. data/bin/cumulus +658 -0
  10. data/cumulus +2 -0
  11. data/cumulus-aws.gemspec +20 -0
  12. data/lib/autoscaling/AutoScaling.rb +40 -0
  13. data/lib/autoscaling/loader/Loader.rb +56 -0
  14. data/lib/autoscaling/manager/Manager.rb +360 -0
  15. data/lib/autoscaling/models/AlarmConfig.rb +165 -0
  16. data/lib/autoscaling/models/AlarmDiff.rb +172 -0
  17. data/lib/autoscaling/models/AutoScalingDiff.rb +178 -0
  18. data/lib/autoscaling/models/GroupConfig.rb +330 -0
  19. data/lib/autoscaling/models/PolicyConfig.rb +135 -0
  20. data/lib/autoscaling/models/PolicyDiff.rb +73 -0
  21. data/lib/autoscaling/models/ScheduledActionDiff.rb +53 -0
  22. data/lib/autoscaling/models/ScheduledConfig.rb +96 -0
  23. data/lib/aws_extensions/ec2/DhcpOptions.rb +41 -0
  24. data/lib/aws_extensions/ec2/Instance.rb +29 -0
  25. data/lib/aws_extensions/ec2/NetworkAcl.rb +25 -0
  26. data/lib/aws_extensions/ec2/NetworkInterface.rb +14 -0
  27. data/lib/aws_extensions/ec2/RouteTable.rb +26 -0
  28. data/lib/aws_extensions/ec2/SecurityGroup.rb +16 -0
  29. data/lib/aws_extensions/ec2/Subnet.rb +28 -0
  30. data/lib/aws_extensions/ec2/Volume.rb +24 -0
  31. data/lib/aws_extensions/ec2/Vpc.rb +14 -0
  32. data/lib/aws_extensions/ec2/VpcEndpoint.rb +11 -0
  33. data/lib/aws_extensions/elb/BackendServerDescription.rb +12 -0
  34. data/lib/aws_extensions/elb/PolicyDescription.rb +14 -0
  35. data/lib/aws_extensions/kinesis/StreamDescription.rb +12 -0
  36. data/lib/aws_extensions/route53/AliasTarget.rb +21 -0
  37. data/lib/aws_extensions/s3/Bucket.rb +33 -0
  38. data/lib/aws_extensions/s3/BucketAcl.rb +28 -0
  39. data/lib/aws_extensions/s3/BucketCors.rb +17 -0
  40. data/lib/aws_extensions/s3/BucketLifecycle.rb +21 -0
  41. data/lib/aws_extensions/s3/BucketLogging.rb +18 -0
  42. data/lib/aws_extensions/s3/BucketNotification.rb +23 -0
  43. data/lib/aws_extensions/s3/BucketPolicy.rb +18 -0
  44. data/lib/aws_extensions/s3/BucketTagging.rb +15 -0
  45. data/lib/aws_extensions/s3/BucketVersioning.rb +14 -0
  46. data/lib/aws_extensions/s3/BucketWebsite.rb +49 -0
  47. data/lib/aws_extensions/s3/CORSRule.rb +27 -0
  48. data/lib/aws_extensions/s3/ReplicationConfiguration.rb +22 -0
  49. data/lib/cloudfront/CloudFront.rb +83 -0
  50. data/lib/cloudfront/loader/Loader.rb +31 -0
  51. data/lib/cloudfront/manager/Manager.rb +183 -0
  52. data/lib/cloudfront/models/CacheBehaviorConfig.rb +237 -0
  53. data/lib/cloudfront/models/CacheBehaviorDiff.rb +211 -0
  54. data/lib/cloudfront/models/CustomOriginConfig.rb +51 -0
  55. data/lib/cloudfront/models/CustomOriginDiff.rb +74 -0
  56. data/lib/cloudfront/models/DistributionConfig.rb +183 -0
  57. data/lib/cloudfront/models/DistributionDiff.rb +131 -0
  58. data/lib/cloudfront/models/InvalidationConfig.rb +37 -0
  59. data/lib/cloudfront/models/OriginConfig.rb +144 -0
  60. data/lib/cloudfront/models/OriginDiff.rb +86 -0
  61. data/lib/cloudfront/models/OriginSslProtocols.rb +28 -0
  62. data/lib/cloudfront/models/OriginSslProtocolsDiff.rb +39 -0
  63. data/lib/common/BaseLoader.rb +80 -0
  64. data/lib/common/manager/Manager.rb +148 -0
  65. data/lib/common/models/Diff.rb +114 -0
  66. data/lib/common/models/ListChange.rb +21 -0
  67. data/lib/common/models/TagsDiff.rb +55 -0
  68. data/lib/common/models/UTCTimeSource.rb +17 -0
  69. data/lib/conf/Configuration.rb +365 -0
  70. data/lib/ec2/EC2.rb +503 -0
  71. data/lib/ec2/IPProtocolMapping.rb +165 -0
  72. data/lib/ec2/loaders/EbsLoader.rb +19 -0
  73. data/lib/ec2/loaders/InstanceLoader.rb +32 -0
  74. data/lib/ec2/managers/EbsManager.rb +176 -0
  75. data/lib/ec2/managers/InstanceManager.rb +509 -0
  76. data/lib/ec2/models/EbsGroupConfig.rb +133 -0
  77. data/lib/ec2/models/EbsGroupDiff.rb +48 -0
  78. data/lib/ec2/models/InstanceConfig.rb +202 -0
  79. data/lib/ec2/models/InstanceDiff.rb +95 -0
  80. data/lib/elb/ELB.rb +148 -0
  81. data/lib/elb/loader/Loader.rb +65 -0
  82. data/lib/elb/manager/Manager.rb +581 -0
  83. data/lib/elb/models/AccessLogConfig.rb +82 -0
  84. data/lib/elb/models/AccessLogDiff.rb +47 -0
  85. data/lib/elb/models/HealthCheckConfig.rb +91 -0
  86. data/lib/elb/models/HealthCheckDiff.rb +50 -0
  87. data/lib/elb/models/ListenerConfig.rb +99 -0
  88. data/lib/elb/models/ListenerDiff.rb +91 -0
  89. data/lib/elb/models/LoadBalancerConfig.rb +239 -0
  90. data/lib/elb/models/LoadBalancerDiff.rb +265 -0
  91. data/lib/iam/IAM.rb +36 -0
  92. data/lib/iam/loader/Loader.rb +117 -0
  93. data/lib/iam/manager/IamGroups.rb +98 -0
  94. data/lib/iam/manager/IamResource.rb +288 -0
  95. data/lib/iam/manager/IamRoles.rb +112 -0
  96. data/lib/iam/manager/IamUsers.rb +54 -0
  97. data/lib/iam/manager/Manager.rb +29 -0
  98. data/lib/iam/migration/AssumeRoleUnifier.rb +34 -0
  99. data/lib/iam/migration/PolicyUnifier.rb +90 -0
  100. data/lib/iam/models/GroupConfig.rb +40 -0
  101. data/lib/iam/models/IamDiff.rb +132 -0
  102. data/lib/iam/models/PolicyConfig.rb +67 -0
  103. data/lib/iam/models/ResourceWithPolicy.rb +208 -0
  104. data/lib/iam/models/RoleConfig.rb +53 -0
  105. data/lib/iam/models/StatementConfig.rb +35 -0
  106. data/lib/iam/models/UserConfig.rb +21 -0
  107. data/lib/kinesis/Kinesis.rb +94 -0
  108. data/lib/kinesis/loader/Loader.rb +19 -0
  109. data/lib/kinesis/manager/Manager.rb +206 -0
  110. data/lib/kinesis/models/StreamConfig.rb +75 -0
  111. data/lib/kinesis/models/StreamDiff.rb +58 -0
  112. data/lib/lambda/Lambda.rb +41 -0
  113. data/lib/route53/loader/Loader.rb +32 -0
  114. data/lib/route53/manager/Manager.rb +241 -0
  115. data/lib/route53/models/AliasTarget.rb +86 -0
  116. data/lib/route53/models/RecordConfig.rb +178 -0
  117. data/lib/route53/models/RecordDiff.rb +140 -0
  118. data/lib/route53/models/Vpc.rb +24 -0
  119. data/lib/route53/models/ZoneConfig.rb +156 -0
  120. data/lib/route53/models/ZoneDiff.rb +118 -0
  121. data/lib/s3/S3.rb +89 -0
  122. data/lib/s3/loader/Loader.rb +66 -0
  123. data/lib/s3/manager/Manager.rb +296 -0
  124. data/lib/s3/models/BucketConfig.rb +321 -0
  125. data/lib/s3/models/BucketDiff.rb +167 -0
  126. data/lib/s3/models/GrantConfig.rb +189 -0
  127. data/lib/s3/models/GrantDiff.rb +50 -0
  128. data/lib/s3/models/LifecycleConfig.rb +142 -0
  129. data/lib/s3/models/LifecycleDiff.rb +46 -0
  130. data/lib/s3/models/LoggingConfig.rb +81 -0
  131. data/lib/s3/models/NotificationConfig.rb +157 -0
  132. data/lib/s3/models/NotificationDiff.rb +62 -0
  133. data/lib/s3/models/ReplicationConfig.rb +133 -0
  134. data/lib/s3/models/ReplicationDiff.rb +60 -0
  135. data/lib/s3/models/WebsiteConfig.rb +107 -0
  136. data/lib/security/SecurityGroups.rb +39 -0
  137. data/lib/security/loader/Loader.rb +94 -0
  138. data/lib/security/manager/Manager.rb +246 -0
  139. data/lib/security/models/RuleConfig.rb +161 -0
  140. data/lib/security/models/RuleDiff.rb +72 -0
  141. data/lib/security/models/RuleMigration.rb +127 -0
  142. data/lib/security/models/SecurityGroupConfig.rb +172 -0
  143. data/lib/security/models/SecurityGroupDiff.rb +112 -0
  144. data/lib/sns/SNS.rb +40 -0
  145. data/lib/sqs/SQS.rb +62 -0
  146. data/lib/sqs/loader/Loader.rb +34 -0
  147. data/lib/sqs/manager/Manager.rb +128 -0
  148. data/lib/sqs/models/DeadLetterConfig.rb +70 -0
  149. data/lib/sqs/models/DeadLetterDiff.rb +35 -0
  150. data/lib/sqs/models/QueueConfig.rb +115 -0
  151. data/lib/sqs/models/QueueDiff.rb +89 -0
  152. data/lib/util/Colors.rb +111 -0
  153. data/lib/util/StatusCodes.rb +51 -0
  154. data/lib/vpc/loader/Loader.rb +73 -0
  155. data/lib/vpc/manager/Manager.rb +954 -0
  156. data/lib/vpc/models/AclEntryConfig.rb +150 -0
  157. data/lib/vpc/models/AclEntryDiff.rb +54 -0
  158. data/lib/vpc/models/DhcpConfig.rb +100 -0
  159. data/lib/vpc/models/DhcpDiff.rb +90 -0
  160. data/lib/vpc/models/EndpointConfig.rb +76 -0
  161. data/lib/vpc/models/EndpointDiff.rb +69 -0
  162. data/lib/vpc/models/NetworkAclConfig.rb +87 -0
  163. data/lib/vpc/models/NetworkAclDiff.rb +116 -0
  164. data/lib/vpc/models/RouteConfig.rb +82 -0
  165. data/lib/vpc/models/RouteDiff.rb +50 -0
  166. data/lib/vpc/models/RouteTableConfig.rb +92 -0
  167. data/lib/vpc/models/RouteTableDiff.rb +101 -0
  168. data/lib/vpc/models/SubnetConfig.rb +113 -0
  169. data/lib/vpc/models/SubnetDiff.rb +78 -0
  170. data/lib/vpc/models/VpcConfig.rb +173 -0
  171. data/lib/vpc/models/VpcDiff.rb +315 -0
  172. data/rakefile.rb +8 -0
  173. metadata +245 -0
@@ -0,0 +1,658 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+
5
+ module Modules
6
+ # Public: Run the IAM module
7
+ def self.iam
8
+ if ARGV.size < 2 or
9
+ (ARGV.size == 2 and ARGV[1] != "help") or
10
+ (ARGV.size >= 3 and ((ARGV[1] != "groups" and ARGV[1] != "roles" and ARGV[1] != "users") or (ARGV[2] != "diff" and ARGV[2] != "list" and ARGV[2] != "migrate" and ARGV[2] != "sync")))
11
+ puts "Usage: cumulus iam [help|groups|roles|users] [diff|list|migrate|sync] <asset>"
12
+ exit
13
+ end
14
+
15
+ if ARGV[1] == "help"
16
+ puts "iam: Manage IAMs."
17
+ puts "\tCompiles IAM assets and policies that are defined with configuration files and syncs the resulting IAM assets with AWS."
18
+ puts
19
+ puts "Usage: cumulus iam [groups|help|roles|users] [diff|list|migrate|sync] <asset>"
20
+ puts
21
+ puts "Commands"
22
+ puts "\tgroups - Manage IAM groups and users associated with those groups"
23
+ puts "\t\tdiff\t- get a list of groups that have different definitions locally than in AWS (supplying the name of the group will diff only that group)"
24
+ puts "\t\tlist\t- list the groups defined in configuration"
25
+ puts "\t\tmigrate\t- create group configuration files that match the definitions in AWS"
26
+ puts "\t\tsync\t- sync the local group definition with AWS (supplying the name of the group will sync only that group). Also adds and removes users from groups"
27
+ puts "\troles - Manage IAM roles"
28
+ puts "\t\tdiff\t- get a list of roles that have different definitions locally than in AWS (supplying the name of the role will diff only that role)"
29
+ puts "\t\tlist\t- list the roles defined in configuration"
30
+ puts "\t\tmigrate\t - create role configuration files that match the definitions in AWS"
31
+ puts "\t\tsync\t- sync the local role definition with AWS (supplying the name of the role will sync only that role)"
32
+ puts "\tusers - Manager IAM users"
33
+ puts "\t\tdiff\t- get a list of users that have different definitions locally than in AWS (supplying the name of the user will diff only that user)"
34
+ puts "\t\tlist\t- list the users defined in configuration"
35
+ puts "\t\tmigrate\t - create user configuration files that match the definitions in AWS"
36
+ puts "\t\tsync\t- sync the local user definition with AWS (supplying the name of the user will sync only that user)"
37
+ exit
38
+ end
39
+
40
+ # run the application with the desired command
41
+ require "iam/manager/Manager"
42
+ iam = Cumulus::IAM::Manager.new
43
+ resource = nil
44
+ if ARGV[1] == "roles"
45
+ resource = iam.roles
46
+ elsif ARGV[1] == "users"
47
+ resource = iam.users
48
+ elsif ARGV[1] == "groups"
49
+ resource = iam.groups
50
+ end
51
+ if ARGV[2] == "diff"
52
+ if ARGV.size < 4
53
+ resource.diff
54
+ else
55
+ resource.diff_one(ARGV[3])
56
+ end
57
+ elsif ARGV[2] == "list"
58
+ resource.list
59
+ elsif ARGV[2] == "migrate"
60
+ resource.migrate
61
+ elsif ARGV[2] == "sync"
62
+ if ARGV.size < 4
63
+ resource.sync
64
+ else
65
+ resource.sync_one(ARGV[3])
66
+ end
67
+ end
68
+ end
69
+
70
+ # Public: Run the AutoScaling Group module
71
+ def self.autoscaling
72
+ if ARGV.size < 2 or
73
+ (ARGV.size >= 2 and ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "migrate" and ARGV[1] != "sync")
74
+ puts "Usage: cumulus autoscaling [diff|help|list|migrate|sync] <asset>"
75
+ exit
76
+ end
77
+
78
+ if ARGV[1] == "help"
79
+ puts "autoscaling: Manage AutoScaling groups."
80
+ puts "\tCompiles AutoScaling groups, scaling policies, and alarms that are defined in configuration files and syncs the resulting AutoScaling groups with AWS."
81
+ puts
82
+ puts "Usage: cumulus autoscaling [diff|help|list|migrate|sync] <asset>"
83
+ puts
84
+ puts "Commands"
85
+ puts "\tdiff\t- print out differences between local configuration and AWS (supplying the name of an AutoScaling group will diff only that group)"
86
+ puts "\tlist\t- list the AutoScaling groups defined locally"
87
+ puts "\tmigrate\t- produce Cumulus configuration from current configuration in AWS"
88
+ puts "\tsync\t- sync local AutoScaling definitions with AWS (supplying the name of an AutoScaling group will sync only that group)"
89
+ end
90
+
91
+ require "autoscaling/manager/Manager"
92
+ autoscaling = Cumulus::AutoScaling::Manager.new
93
+ if ARGV[1] == "diff"
94
+ if ARGV.size == 2
95
+ autoscaling.diff
96
+ else
97
+ autoscaling.diff_one(ARGV[2])
98
+ end
99
+ elsif ARGV[1] == "list"
100
+ autoscaling.list
101
+ elsif ARGV[1] == "migrate"
102
+ autoscaling.migrate
103
+ elsif ARGV[1] == "sync"
104
+ if ARGV.size == 2
105
+ autoscaling.sync
106
+ else
107
+ autoscaling.sync_one(ARGV[2])
108
+ end
109
+ end
110
+ end
111
+
112
+ # Public: Run the route53 module
113
+ def self.route53
114
+ if ARGV.size < 2 or (ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "migrate" and ARGV[1] != "sync")
115
+ puts "Usage: cumulus route53 [diff|help|list|migrate|sync] <asset>"
116
+ exit
117
+ end
118
+
119
+ if ARGV[1] == "help"
120
+ puts "route53: Manage Route53"
121
+ puts "\tDiff and sync Route53 configuration with AWS."
122
+ puts
123
+ puts "Usage: cumulus route53 [diff|help|list|migrate|sync] <asset>"
124
+ puts "Commands"
125
+ puts "\tdiff\t- print out differences between local configuration and AWS (supplying the name of the zone will diff only that zone)"
126
+ puts "\tlist\t- list the locally defined zones"
127
+ puts "\tmigrate\t- produce Cumulus zone configuration from current AWS configuration"
128
+ puts "\tsync\t- sync local zone definitions with AWS (supplying the name of the zone will sync only that zone)"
129
+ exit
130
+ end
131
+
132
+ require "route53/manager/Manager"
133
+ route53 = Cumulus::Route53::Manager.new
134
+ if ARGV[1] == "diff"
135
+ if ARGV.size == 2
136
+ route53.diff
137
+ else
138
+ route53.diff_one(ARGV[2])
139
+ end
140
+ elsif ARGV[1] == "list"
141
+ route53.list
142
+ elsif ARGV[1] == "migrate"
143
+ route53.migrate
144
+ elsif ARGV[1] == "sync"
145
+ if ARGV.size == 2
146
+ route53.sync
147
+ else
148
+ route53.sync_one(ARGV[2])
149
+ end
150
+ end
151
+ end
152
+
153
+ # Public: Run the Security Group module
154
+ def self.security
155
+ if ARGV.size < 2 or (ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "migrate" and ARGV[1] != "sync")
156
+ puts "Usage: cumulus security-groups [diff|help|list|migrate|sync] <asset>"
157
+ exit
158
+ end
159
+
160
+ if ARGV[1] == "help"
161
+ puts "security-groups: Manage EC2 Security Groups"
162
+ puts "\tDiff and sync EC2 security group configuration with AWS."
163
+ puts
164
+ puts "Usage: cumulus security-groups [diff|help|list|migrate|sync] <asset>"
165
+ puts
166
+ puts "Commands"
167
+ puts "\tdiff\t- print out differences between local configuration and AWS (supplying the name of the security group will diff only that security group)"
168
+ puts "\tlist\t- list the locally defined security groups"
169
+ puts "\tmigrate\t- produce Cumulus security group configuration from current AWS configuration"
170
+ puts "\tsync\t- sync local security group definitions with AWS (supplying the name of the security group will sync only that security group)"
171
+ exit
172
+ end
173
+
174
+ require "security/manager/Manager"
175
+ security = Cumulus::SecurityGroups::Manager.new
176
+ if ARGV[1] == "diff"
177
+ if ARGV.size == 2
178
+ security.diff
179
+ else
180
+ security.diff_one(ARGV[2])
181
+ end
182
+ elsif ARGV[1] == "list"
183
+ security.list
184
+ elsif ARGV[1] == "migrate"
185
+ security.migrate
186
+ elsif ARGV[1] == "sync"
187
+ if ARGV.size == 2
188
+ security.sync
189
+ else
190
+ security.sync_one(ARGV[2])
191
+ end
192
+ end
193
+
194
+ end
195
+
196
+ # Public: Run the Cloudfront module
197
+ def self.cloudfront
198
+ if ARGV.size < 2 or (ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "sync" and ARGV[1] != "invalidate" and ARGV[1] != "migrate")
199
+ puts "Usage: cumulus cloudfront [diff|help|invalidate|list|migrate|sync] <asset>"
200
+ exit
201
+ end
202
+
203
+ if ARGV[1] == "help"
204
+ puts "cloudfront: Manage CloudFront"
205
+ puts "\tDiff and sync CloudFront configuration with AWS."
206
+ puts
207
+ puts "Usage: cumulus cloudfront [diff|help|invalidate|list] <asset>"
208
+ puts "Commands"
209
+ puts "\tdiff\t\t- print out differences between local configuration and AWS (supplying the id of the distribution will diff only that distribution)"
210
+ puts "\tinvalidate\t- create an invalidation. Must supply the name of the invalidation to run. Specifying 'list' as an argument lists the local invalidation configurations"
211
+ puts "\tlist\t\t- list the locally defined distributions"
212
+ puts "\tmigrate\t\t- produce Cumulus CloudFront distribution configuration from current AWS configuration"
213
+ puts "\tsync\t\t- sync local cloudfront distribution configuration with AWS (supplying the id of the distribution will sync only that distribution)"
214
+ exit
215
+ end
216
+
217
+ require "cloudfront/manager/Manager"
218
+
219
+ cloudfront = Cumulus::CloudFront::Manager.new
220
+
221
+ if ARGV[1] == "list"
222
+ cloudfront.list
223
+ elsif ARGV[1] == "diff"
224
+ if ARGV.size == 2
225
+ cloudfront.diff
226
+ else
227
+ cloudfront.diff_one(ARGV[2])
228
+ end
229
+ elsif ARGV[1] == "sync"
230
+ if ARGV.size == 2
231
+ cloudfront.sync
232
+ else
233
+ cloudfront.sync_one(ARGV[2])
234
+ end
235
+ elsif ARGV[1] == "invalidate"
236
+ if ARGV.size != 3
237
+ puts "Specify one invalidation to run"
238
+ exit
239
+ else
240
+ if ARGV[2] == "list"
241
+ cloudfront.list_invalidations
242
+ else
243
+ cloudfront.invalidate(ARGV[2])
244
+ end
245
+ end
246
+ elsif ARGV[1] == "migrate"
247
+ cloudfront.migrate
248
+ end
249
+
250
+ end
251
+
252
+ # Public: Run the S3 module
253
+ def self.s3
254
+ if ARGV.size < 2 or (ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "migrate" and ARGV[1] != "sync")
255
+ puts "Usage: cumulus s3 [diff|help|list|migrate|sync] <asset>"
256
+ exit
257
+ end
258
+
259
+ if ARGV[1] == "help"
260
+ puts "s3: Manage S3 Buckets"
261
+ puts "\tDiff and sync S3 bucket configuration with AWS."
262
+ puts
263
+ puts "Usage: cumulus s3 [diff|help|list|migrate|sync] <asset>"
264
+ puts
265
+ puts "Commands"
266
+ puts "\tdiff\t- print out differences between local configuration and AWS (supplying the name of the bucket will diff only that bucket)"
267
+ puts "\tlist\t- list the locally defined S3 buckets"
268
+ puts "\tmigrate\t- produce Cumulus S3 configuration from current AWS configuration"
269
+ puts "\tsync\t- sync local bucket definitions with AWS (supplying the name of the bucket will sync only that bucket)"
270
+ exit
271
+ end
272
+
273
+ require "s3/manager/Manager"
274
+ s3 = Cumulus::S3::Manager.new
275
+ if ARGV[1] == "diff"
276
+ if ARGV.size == 2
277
+ s3.diff
278
+ else
279
+ s3.diff_one(ARGV[2])
280
+ end
281
+ elsif ARGV[1] == "list"
282
+ s3.list
283
+ elsif ARGV[1] == "migrate"
284
+ s3.migrate
285
+ elsif ARGV[1] == "sync"
286
+ if ARGV.size == 2
287
+ s3.sync
288
+ else
289
+ s3.sync_one(ARGV[2])
290
+ end
291
+ end
292
+ end
293
+
294
+ # Public: Run the elb module
295
+ def self.elb
296
+ if ARGV.size < 2 or (ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "sync" and ARGV[1] != "migrate")
297
+ puts "Usage: cumulus elb [diff|help|list|migrate|sync] <asset>"
298
+ exit
299
+ end
300
+
301
+ if ARGV[1] == "help"
302
+ puts "elb: Manage Elastic Load Balancers"
303
+ puts "\tDiff and sync ELB configuration with AWS."
304
+ puts
305
+ puts "Usage: cumulus elb [diff|help|list|migrate|sync] <asset>"
306
+ puts
307
+ puts "Commands"
308
+ puts "\tdiff\t- print out differences between local configuration and AWS (supplying the name of the elb will diff only that elb)"
309
+ puts "\tlist\t- list the locally defined ELBs"
310
+ puts "\tsync\t- sync local ELB definitions with AWS (supplying the name of the elb will sync only that elb)"
311
+ puts "\tmigrate\t- migrate AWS configuration to Cumulus"
312
+ puts "\t\tdefault-policies- migrate default ELB policies from AWS to Cumulus"
313
+ puts "\t\telbs\t\t- migrate the current ELB configuration from AWS to Cumulus"
314
+ exit
315
+ end
316
+
317
+ require "elb/manager/Manager"
318
+ elb = Cumulus::ELB::Manager.new
319
+ if ARGV[1] == "diff"
320
+ if ARGV.size == 2
321
+ elb.diff
322
+ else
323
+ elb.diff_one(ARGV[2])
324
+ end
325
+ elsif ARGV[1] == "list"
326
+ elb.list
327
+ elsif ARGV[1] == "sync"
328
+ if ARGV.size == 2
329
+ elb.sync
330
+ else
331
+ elb.sync_one(ARGV[2])
332
+ end
333
+ elsif ARGV[1] == "migrate"
334
+ if ARGV[2] == "default-policies"
335
+ elb.migrate_default_policies
336
+ elsif ARGV[2] == "elbs"
337
+ elb.migrate_elbs
338
+ else
339
+ puts "Usage: cumulus elb migrate [default-policies|elbs]"
340
+ end
341
+ end
342
+ end
343
+
344
+ # Public: Run the vpc module
345
+ def self.vpc
346
+ if ARGV.size < 2 or (ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "sync" and ARGV[1] != "migrate" and ARGV[1] != "rename")
347
+ puts "Usage: cumulus vpc [diff|help|list|migrate|sync|rename] <asset>"
348
+ exit
349
+ end
350
+
351
+ if ARGV[1] == "help"
352
+ puts "vpc: Manage Virtual Private Cloud"
353
+ puts "\tDiff and sync VPC configuration with AWS."
354
+ puts
355
+ puts "Usage: cumulus vpc [diff|help|list|migrate|sync|rename] <asset>"
356
+ puts
357
+ puts "Commands"
358
+ puts "\tdiff\t- print out differences between local configuration and AWS (supplying the name of the VPC will diff only that VPC)"
359
+ puts "\tlist\t- list the locally defined VPCs"
360
+ puts "\tsync\t- sync local VPC definitions with AWS (supplying the name of the VPC will sync only that VPC)"
361
+ puts "\tmigrate\t- migrate AWS configuration to Cumulus"
362
+ puts "\trename\t- renames a cumulus asset and all references to it"
363
+ exit
364
+ end
365
+
366
+ require "vpc/manager/Manager"
367
+ vpc = Cumulus::VPC::Manager.new
368
+ if ARGV[1] == "diff"
369
+ if ARGV.size == 2
370
+ vpc.diff
371
+ else
372
+ vpc.diff_one(ARGV[2])
373
+ end
374
+ elsif ARGV[1] == "sync"
375
+ if ARGV.size == 2
376
+ vpc.sync
377
+ else
378
+ vpc.sync_one(ARGV[2])
379
+ end
380
+ elsif ARGV[1] == "list"
381
+ vpc.list
382
+ elsif ARGV[1] == "migrate"
383
+ vpc.migrate
384
+ elsif ARGV[1] == "rename"
385
+ if ARGV.size == 5
386
+ vpc.rename(ARGV[2], ARGV[3], ARGV[4])
387
+ else
388
+ puts "Usage: cumulus vpc rename [network-acl|policy|route-table|subnet|vpc] <old-asset-name> <new-asset-name>"
389
+ end
390
+ end
391
+ end
392
+
393
+ # Public: Run the kinesis module
394
+ def self.kinesis
395
+ if ARGV.size < 2 or (ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "sync" and ARGV[1] != "migrate")
396
+ puts "Usage: cumulus kinesis [diff|help|list|migrate|sync] <asset>"
397
+ exit
398
+ end
399
+
400
+ if ARGV[1] == "help"
401
+ puts "kinesis: Manage Kinesis Streams"
402
+ puts "\tDiff and sync Kinesis configuration with AWS."
403
+ puts
404
+ puts "Usage: cumulus kinesis [diff|help|list|migrate|sync] <asset>"
405
+ puts
406
+ puts "Commands"
407
+ puts "\tdiff\t- print out differences between local configuration and AWS (supplying the name of the stream will diff only that stream)"
408
+ puts "\tlist\t- list the locally defined VPCs"
409
+ puts "\tsync\t- sync local stream definitions with AWS (supplying the name of the stream will sync only that stream)"
410
+ puts "\tmigrate\t- migrate AWS configuration to Cumulus"
411
+ exit
412
+ end
413
+
414
+ require "kinesis/manager/Manager"
415
+ kinesis = Cumulus::Kinesis::Manager.new
416
+ if ARGV[1] == "diff"
417
+ if ARGV.size == 2
418
+ kinesis.diff
419
+ else
420
+ kinesis.diff_one(ARGV[2])
421
+ end
422
+ elsif ARGV[1] == "sync"
423
+ if ARGV.size == 2
424
+ kinesis.sync
425
+ else
426
+ kinesis.sync_one(ARGV[2])
427
+ end
428
+ elsif ARGV[1] == "list"
429
+ kinesis.list
430
+ elsif ARGV[1] == "migrate"
431
+ kinesis.migrate
432
+ end
433
+ end
434
+
435
+ # Public: Run the SQS module
436
+ def self.sqs
437
+ if ARGV.size < 2 or (ARGV[1] != "help" and ARGV[1] != "diff" and ARGV[1] != "list" and ARGV[1] != "urls" and ARGV[1] != "sync" and ARGV[1] != "migrate")
438
+ puts "Usage: cumulus sqs [diff|help|list|migrate|sync|urls] <asset>"
439
+ end
440
+
441
+ if ARGV[1] == "help"
442
+ puts "SQS: Manage SQS"
443
+ puts "\tDiff and sync SQS configuration with AWS."
444
+ puts
445
+ puts "Usage: cumulus sqs [diff|help|list|migrate|sync|urls] <asset>"
446
+ puts
447
+ puts "Commands"
448
+ puts "\tdiff\t- print out differences between local configuration and AWS (supplying the name of the queue will diff only that queue)"
449
+ puts "\tlist\t- list the locally defined queues"
450
+ puts "\turls\t- list the url for each locally defined queue"
451
+ puts "\tsync\t- sync local queue definitions with AWS (supplying the name of the queue will sync only that queue)"
452
+ puts "\tmigrate\t- migrate AWS configuration to Cumulus"
453
+ exit
454
+ end
455
+
456
+ require "sqs/manager/Manager"
457
+ sqs = Cumulus::SQS::Manager.new
458
+ if ARGV[1] == "diff"
459
+ if ARGV.size == 2
460
+ sqs.diff
461
+ else
462
+ sqs.diff_one(ARGV[2])
463
+ end
464
+ elsif ARGV[1] == "sync"
465
+ if ARGV.size == 2
466
+ sqs.sync
467
+ else
468
+ sqs.sync_one(ARGV[2])
469
+ end
470
+ elsif ARGV[1] == "list"
471
+ sqs.list
472
+ elsif ARGV[1] == "urls"
473
+ sqs.urls
474
+ elsif ARGV[1] == "migrate"
475
+ sqs.migrate
476
+ end
477
+ end
478
+
479
+ # Public: Run the EC2 module
480
+ def self.ec2
481
+ if ARGV.size < 2 or
482
+ (ARGV.size == 2 and ARGV[1] != "help") or
483
+ (ARGV.size >= 3 and ((ARGV[1] != "ebs" and ARGV[1] != "instances") or (ARGV[2] != "diff" and ARGV[2] != "list" and ARGV[2] != "migrate" and ARGV[2] != "sync")))
484
+ puts "Usage: cumulus ec2 [help|ebs|instances] [diff|list|migrate|sync] <asset>"
485
+ exit
486
+ end
487
+
488
+ if ARGV[1] == "help"
489
+ puts "ec2: Manage EC2 instances and related configuration."
490
+ puts
491
+ puts "Usage: cumulus ec2 [help|ebs|instances] [diff|list|migrate|sync] <asset>"
492
+ puts
493
+ puts "Commands"
494
+ puts "\tebs - Manage EBS volumes in groups"
495
+ puts "\t\tdiff\t- get a list of groups that have different definitions locally than in AWS (supplying the name of the group will diff only that group)"
496
+ puts "\t\tlist\t- list the groups defined in configuration"
497
+ puts "\t\tmigrate\t- create group configuration files that match the definitions in AWS"
498
+ puts "\t\tsync\t- sync the local group definition with AWS (supplying the name of the group will sync only that group). Also creates volumes in a group"
499
+ puts "\tinstances - Manage EC2 instances"
500
+ puts "\t\tdiff\t- get a list of instances that have different definitions locally than in AWS (supplying the name of the instance will diff only that instance)"
501
+ puts "\t\tlist\t- list the instances defined in configuration"
502
+ puts "\t\tmigrate\t - create instances configuration files that match the definitions in AWS"
503
+ puts "\t\tsync\t- sync the local instance definition with AWS (supplying the name of the instance will sync only that instance)"
504
+ exit
505
+ end
506
+
507
+ require "ec2/managers/EbsManager"
508
+ require "ec2/managers/InstanceManager"
509
+
510
+ # Get the manager depending on which submodule is ran
511
+ manager = nil
512
+ if ARGV[1] == "ebs"
513
+ manager = Cumulus::EC2::EbsManager.new
514
+ elsif ARGV[1] == "instances"
515
+ manager = Cumulus::EC2::InstanceManager.new
516
+ end
517
+
518
+ # Run actions on the manager
519
+ if ARGV[2] == "diff"
520
+ if ARGV.size < 4
521
+ manager.diff
522
+ else
523
+ manager.diff_one(ARGV[3])
524
+ end
525
+ elsif ARGV[2] == "list"
526
+ manager.list
527
+ elsif ARGV[2] == "migrate"
528
+ manager.migrate
529
+ elsif ARGV[2] == "sync"
530
+ if ARGV.size < 4
531
+ manager.sync
532
+ else
533
+ manager.sync_one(ARGV[3])
534
+ end
535
+ end
536
+ end
537
+
538
+ end
539
+
540
+ def usage_message
541
+ "Usage: cumulus [autoscaling|cloudfront|ec2|elb|help|iam|kinesis|route53|s3|security-groups|sqs|vpc]"
542
+ end
543
+
544
+ def help_message
545
+ [
546
+ "cumulus: AWS Configuration Manager",
547
+ "\tConfiguration based management of AWS resources.",
548
+ "\t#{usage_message}",
549
+ "",
550
+ "Modules",
551
+ "\tautoscaling\t- Manages configuration for EC2 AutoScaling",
552
+ "\tcloudfront\t- Manages configuration for cloudfront distributions",
553
+ "\tec2\t\t- Manages configuration for managed EC2 instances, EBS volumes and Network Interfaces",
554
+ "\telb\t\t- Manages configuration for elastic load balancers",
555
+ "\tiam\t\t- Compiles IAM roles and policies that are defined with configuration files and syncs the resulting IAM roles and policies with AWS",
556
+ "\tkinesis\t\t- Manages configuration for Kinesis streams",
557
+ "\troute53\t\t- Manages configuration for Route53",
558
+ "\ts3\t\t- Manages configuration of S3 buckets",
559
+ "\tsecurity-groups\t- Manages configuration for EC2 Security Groups",
560
+ "\tsqs\t\t- Manages configuration for SQS Queues",
561
+ "\tvpc\t\t- Manages configuration for Virtual Private Clouds",
562
+ "\n"
563
+ ].join("\n")
564
+ end
565
+
566
+ if ARGV[0] == "help"
567
+ ARGV[0] = "--help"
568
+ end
569
+
570
+ # read in the optional path to the configuration file to use
571
+ options = {
572
+ :config => Dir.pwd,
573
+ :profile => nil,
574
+ :assume_role => nil,
575
+ :autoscaling_force_size => false,
576
+ :verbose => false
577
+ }
578
+ OptionParser.new do |opts|
579
+ opts.banner = help_message
580
+
581
+ opts.on("-c", "--config [DIR]", "Specify the configuration directory") do |c|
582
+ options[:config] = File.expand_path(c)
583
+ end
584
+
585
+ opts.on("-p", "--aws-profile [NAME]", "Specify the AWS profile to use for API requests") do |p|
586
+ options[:profile] = p
587
+ end
588
+
589
+ opts.on("--autoscaling-force-size", "Forces autoscaling to use configured min/max/desired values instead of scheduled actions") do |f|
590
+ options[:autoscaling_force_size] = true
591
+ end
592
+
593
+ opts.on("-v", "--verbose", "Verbose output") do |v|
594
+ options[:verbose] = true
595
+ end
596
+
597
+ opts.on("-r", "--assume-role [NAME]", "Assume Role") do |a|
598
+ options[:assume_role] = a
599
+ end
600
+ end.parse!
601
+
602
+ if ARGV.size == 0 or (ARGV[0] != "iam" and ARGV[0] != "help" and ARGV[0] != "--help" and ARGV[0] != "autoscaling" and
603
+ ARGV[0] != "route53" and ARGV[0] != "s3" and ARGV[0] != "security-groups" and
604
+ ARGV[0] != "cloudfront" and ARGV[0] != "elb" and ARGV[0] != "vpc" and ARGV[0] != "kinesis" and
605
+ ARGV[0] != "sqs" and ARGV[0] != "ec2")
606
+
607
+ puts usage_message
608
+ exit
609
+ end
610
+
611
+ # config parameters can also be read in from environment variables
612
+ if !ENV["CUMULUS_CONFIG"].nil?
613
+ options[:config] = ENV["CUMULUS_CONFIG"]
614
+ end
615
+
616
+ if !ENV["CUMULUS_AWS_PROFILE"].nil?
617
+ options[:profile] = ENV["CUMULUS_AWS_PROFILE"]
618
+ end
619
+
620
+ # set up the application path
621
+ $LOAD_PATH.unshift(File.expand_path(
622
+ File.join(File.dirname(__FILE__), "../lib")
623
+ ))
624
+
625
+ # set up configuration for the application
626
+ require "conf/Configuration"
627
+
628
+ puts "Reading configuration from '#{options[:config]}'" if options[:verbose]
629
+
630
+ Cumulus::Configuration.init(options[:config], options[:profile], options[:assume_role], options[:autoscaling_force_size])
631
+
632
+ puts "Using aws profile '#{options[:profile]}'" if options[:verbose]
633
+ puts "Using assume role '#{options[:assume_role]}'" if options[:verbose]
634
+
635
+
636
+ if ARGV[0] == "iam"
637
+ Modules.iam
638
+ elsif ARGV[0] == "autoscaling"
639
+ Modules.autoscaling
640
+ elsif ARGV[0] == "cloudfront"
641
+ Modules.cloudfront
642
+ elsif ARGV[0] == "ec2"
643
+ Modules.ec2
644
+ elsif ARGV[0] == "elb"
645
+ Modules.elb
646
+ elsif ARGV[0] == "kinesis"
647
+ Modules.kinesis
648
+ elsif ARGV[0] == "route53"
649
+ Modules.route53
650
+ elsif ARGV[0] == "security-groups"
651
+ Modules.security
652
+ elsif ARGV[0] == "s3"
653
+ Modules.s3
654
+ elsif ARGV[0] == "sqs"
655
+ Modules.sqs
656
+ elsif ARGV[0] == "vpc"
657
+ Modules.vpc
658
+ end