vagrant-gecko-aws 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +96 -0
- data/Gemfile +10 -0
- data/LICENSE +8 -0
- data/README.md +329 -0
- data/Rakefile +22 -0
- data/dummy.box +0 -0
- data/example_box/README.md +13 -0
- data/example_box/metadata.json +3 -0
- data/lib/vagrant-aws/action/connect_aws.rb +48 -0
- data/lib/vagrant-aws/action/elb_deregister_instance.rb +24 -0
- data/lib/vagrant-aws/action/elb_register_instance.rb +24 -0
- data/lib/vagrant-aws/action/is_created.rb +18 -0
- data/lib/vagrant-aws/action/is_stopped.rb +18 -0
- data/lib/vagrant-aws/action/message_already_created.rb +16 -0
- data/lib/vagrant-aws/action/message_not_created.rb +16 -0
- data/lib/vagrant-aws/action/message_will_not_destroy.rb +16 -0
- data/lib/vagrant-aws/action/package_instance.rb +192 -0
- data/lib/vagrant-aws/action/read_ssh_info.rb +53 -0
- data/lib/vagrant-aws/action/read_state.rb +38 -0
- data/lib/vagrant-aws/action/run_instance.rb +314 -0
- data/lib/vagrant-aws/action/start_instance.rb +81 -0
- data/lib/vagrant-aws/action/stop_instance.rb +28 -0
- data/lib/vagrant-aws/action/terminate_instance.rb +51 -0
- data/lib/vagrant-aws/action/timed_provision.rb +21 -0
- data/lib/vagrant-aws/action/wait_for_state.rb +41 -0
- data/lib/vagrant-aws/action/warn_networks.rb +19 -0
- data/lib/vagrant-aws/action.rb +210 -0
- data/lib/vagrant-aws/config.rb +572 -0
- data/lib/vagrant-aws/errors.rb +43 -0
- data/lib/vagrant-aws/plugin.rb +73 -0
- data/lib/vagrant-aws/provider.rb +50 -0
- data/lib/vagrant-aws/util/elb.rb +58 -0
- data/lib/vagrant-aws/util/timer.rb +17 -0
- data/lib/vagrant-aws/version.rb +5 -0
- data/lib/vagrant-aws.rb +18 -0
- data/locales/en.yml +159 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/vagrant-aws/config_spec.rb +374 -0
- data/templates/metadata.json.erb +3 -0
- data/templates/vagrant-aws_package_Vagrantfile.erb +5 -0
- data/vagrant-aws.gemspec +58 -0
- metadata +156 -0
@@ -0,0 +1,572 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
require "iniparse"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module AWS
|
6
|
+
class Config < Vagrant.plugin("2", :config)
|
7
|
+
# The access key ID for accessing AWS.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
attr_accessor :access_key_id
|
11
|
+
|
12
|
+
# The ID of the AMI to use.
|
13
|
+
#
|
14
|
+
# @return [String]
|
15
|
+
attr_accessor :ami
|
16
|
+
|
17
|
+
# The availability zone to launch the instance into. If nil, it will
|
18
|
+
# use the default for your account.
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
attr_accessor :availability_zone
|
22
|
+
|
23
|
+
# The placement group to launch the instance into. If nil, it will
|
24
|
+
# not use a placement group
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
attr_accessor :placement_group
|
28
|
+
|
29
|
+
# The timeout to wait for an instance to become ready.
|
30
|
+
#
|
31
|
+
# @return [Fixnum]
|
32
|
+
attr_accessor :instance_ready_timeout
|
33
|
+
|
34
|
+
# The interval to wait for checking an instance's state.
|
35
|
+
#
|
36
|
+
# @return [Fixnum]
|
37
|
+
attr_accessor :instance_check_interval
|
38
|
+
|
39
|
+
# The timeout to wait for an instance to successfully burn into an AMI.
|
40
|
+
#
|
41
|
+
# @return [Fixnum]
|
42
|
+
attr_accessor :instance_package_timeout
|
43
|
+
|
44
|
+
# The type of instance to launch, such as "m3.medium"
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
attr_accessor :instance_type
|
48
|
+
|
49
|
+
# The name of the keypair to use.
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
attr_accessor :keypair_name
|
53
|
+
|
54
|
+
# The private IP address to give this machine (VPC).
|
55
|
+
#
|
56
|
+
# @return [String]
|
57
|
+
attr_accessor :private_ip_address
|
58
|
+
|
59
|
+
# If true, acquire and attach an elastic IP address.
|
60
|
+
# If set to an IP address, assign to the instance.
|
61
|
+
#
|
62
|
+
# @return [String]
|
63
|
+
attr_accessor :elastic_ip
|
64
|
+
|
65
|
+
# The name of the AWS region in which to create the instance.
|
66
|
+
#
|
67
|
+
# @return [String]
|
68
|
+
attr_accessor :region
|
69
|
+
|
70
|
+
# The EC2 endpoint to connect to
|
71
|
+
#
|
72
|
+
# @return [String]
|
73
|
+
attr_accessor :endpoint
|
74
|
+
|
75
|
+
# The version of the AWS api to use
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
attr_accessor :version
|
79
|
+
|
80
|
+
# The secret access key for accessing AWS.
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
attr_accessor :secret_access_key
|
84
|
+
|
85
|
+
# The token associated with the key for accessing AWS.
|
86
|
+
#
|
87
|
+
# @return [String]
|
88
|
+
attr_accessor :session_token
|
89
|
+
|
90
|
+
# The security groups to set on the instance. For VPC this must
|
91
|
+
# be a list of IDs. For EC2, it can be either.
|
92
|
+
#
|
93
|
+
# @return [Array<String>]
|
94
|
+
attr_reader :security_groups
|
95
|
+
|
96
|
+
# The Amazon resource name (ARN) of the IAM Instance Profile
|
97
|
+
# to associate with the instance.
|
98
|
+
#
|
99
|
+
# @return [String]
|
100
|
+
attr_accessor :iam_instance_profile_arn
|
101
|
+
|
102
|
+
# The name of the IAM Instance Profile to associate with
|
103
|
+
# the instance.
|
104
|
+
#
|
105
|
+
# @return [String]
|
106
|
+
attr_accessor :iam_instance_profile_name
|
107
|
+
|
108
|
+
# The subnet ID to launch the machine into (VPC).
|
109
|
+
#
|
110
|
+
# @return [String]
|
111
|
+
attr_accessor :subnet_id
|
112
|
+
|
113
|
+
# The tags for the machine.
|
114
|
+
#
|
115
|
+
# @return [Hash<String, String>]
|
116
|
+
attr_accessor :tags
|
117
|
+
|
118
|
+
# The tags for the AMI generated with package.
|
119
|
+
#
|
120
|
+
# @return [Hash<String, String>]
|
121
|
+
attr_accessor :package_tags
|
122
|
+
|
123
|
+
# Use IAM Instance Role for authentication to AWS instead of an
|
124
|
+
# explicit access_id and secret_access_key
|
125
|
+
#
|
126
|
+
# @return [Boolean]
|
127
|
+
attr_accessor :use_iam_profile
|
128
|
+
|
129
|
+
# The user data string
|
130
|
+
#
|
131
|
+
# @return [String]
|
132
|
+
attr_accessor :user_data
|
133
|
+
|
134
|
+
# Block device mappings
|
135
|
+
#
|
136
|
+
# @return [Array<Hash>]
|
137
|
+
attr_accessor :block_device_mapping
|
138
|
+
|
139
|
+
# Indicates whether an instance stops or terminates when you initiate shutdown from the instance
|
140
|
+
#
|
141
|
+
# @return [bool]
|
142
|
+
attr_accessor :terminate_on_shutdown
|
143
|
+
|
144
|
+
# Specifies which address to connect to with ssh
|
145
|
+
# Must be one of:
|
146
|
+
# - :public_ip_address
|
147
|
+
# - :dns_name
|
148
|
+
# - :private_ip_address
|
149
|
+
# This attribute also accepts an array of symbols
|
150
|
+
#
|
151
|
+
# @return [Symbol]
|
152
|
+
attr_accessor :ssh_host_attribute
|
153
|
+
|
154
|
+
# Enables Monitoring
|
155
|
+
#
|
156
|
+
# @return [Boolean]
|
157
|
+
attr_accessor :monitoring
|
158
|
+
|
159
|
+
# EBS optimized instance
|
160
|
+
#
|
161
|
+
# @return [Boolean]
|
162
|
+
attr_accessor :ebs_optimized
|
163
|
+
|
164
|
+
# Source Destination check
|
165
|
+
#
|
166
|
+
# @return [Boolean]
|
167
|
+
attr_accessor :source_dest_check
|
168
|
+
|
169
|
+
# Assigning a public IP address in a VPC
|
170
|
+
#
|
171
|
+
# @return [Boolean]
|
172
|
+
attr_accessor :associate_public_ip
|
173
|
+
|
174
|
+
# The name of ELB, which an instance should be
|
175
|
+
# attached to
|
176
|
+
#
|
177
|
+
# @return [String]
|
178
|
+
attr_accessor :elb
|
179
|
+
|
180
|
+
# Disable unregisering ELB's from AZ - useful in case of not using default VPC
|
181
|
+
# @return [Boolean]
|
182
|
+
attr_accessor :unregister_elb_from_az
|
183
|
+
|
184
|
+
# Kernel Id
|
185
|
+
#
|
186
|
+
# @return [String]
|
187
|
+
attr_accessor :kernel_id
|
188
|
+
|
189
|
+
# The tenancy of the instance in a VPC.
|
190
|
+
# Defaults to 'default'.
|
191
|
+
#
|
192
|
+
# @return [String]
|
193
|
+
attr_accessor :tenancy
|
194
|
+
|
195
|
+
# The directory where AWS files are stored (usually $HOME/.aws)
|
196
|
+
#
|
197
|
+
# @return [String]
|
198
|
+
attr_accessor :aws_dir
|
199
|
+
|
200
|
+
# The selected AWS named profile (as defined in $HOME/.aws/* files)
|
201
|
+
#
|
202
|
+
# @return [String]
|
203
|
+
attr_accessor :aws_profile
|
204
|
+
|
205
|
+
def initialize(region_specific=false)
|
206
|
+
@access_key_id = UNSET_VALUE
|
207
|
+
@ami = UNSET_VALUE
|
208
|
+
@availability_zone = UNSET_VALUE
|
209
|
+
@instance_check_interval = UNSET_VALUE
|
210
|
+
@placement_group = UNSET_VALUE
|
211
|
+
@instance_ready_timeout = UNSET_VALUE
|
212
|
+
@instance_package_timeout = UNSET_VALUE
|
213
|
+
@instance_type = UNSET_VALUE
|
214
|
+
@keypair_name = UNSET_VALUE
|
215
|
+
@private_ip_address = UNSET_VALUE
|
216
|
+
@region = UNSET_VALUE
|
217
|
+
@endpoint = UNSET_VALUE
|
218
|
+
@version = UNSET_VALUE
|
219
|
+
@secret_access_key = UNSET_VALUE
|
220
|
+
@session_token = UNSET_VALUE
|
221
|
+
@security_groups = UNSET_VALUE
|
222
|
+
@subnet_id = UNSET_VALUE
|
223
|
+
@tags = {}
|
224
|
+
@package_tags = {}
|
225
|
+
@user_data = UNSET_VALUE
|
226
|
+
@use_iam_profile = UNSET_VALUE
|
227
|
+
@block_device_mapping = []
|
228
|
+
@elastic_ip = UNSET_VALUE
|
229
|
+
@iam_instance_profile_arn = UNSET_VALUE
|
230
|
+
@iam_instance_profile_name = UNSET_VALUE
|
231
|
+
@terminate_on_shutdown = UNSET_VALUE
|
232
|
+
@ssh_host_attribute = UNSET_VALUE
|
233
|
+
@monitoring = UNSET_VALUE
|
234
|
+
@ebs_optimized = UNSET_VALUE
|
235
|
+
@source_dest_check = UNSET_VALUE
|
236
|
+
@associate_public_ip = UNSET_VALUE
|
237
|
+
@elb = UNSET_VALUE
|
238
|
+
@unregister_elb_from_az = UNSET_VALUE
|
239
|
+
@kernel_id = UNSET_VALUE
|
240
|
+
@tenancy = UNSET_VALUE
|
241
|
+
@aws_dir = UNSET_VALUE
|
242
|
+
@aws_profile = UNSET_VALUE
|
243
|
+
|
244
|
+
# Internal state (prefix with __ so they aren't automatically
|
245
|
+
# merged)
|
246
|
+
@__compiled_region_configs = {}
|
247
|
+
@__finalized = false
|
248
|
+
@__region_config = {}
|
249
|
+
@__region_specific = region_specific
|
250
|
+
end
|
251
|
+
|
252
|
+
# set security_groups
|
253
|
+
def security_groups=(value)
|
254
|
+
# convert value to array if necessary
|
255
|
+
@security_groups = value.is_a?(Array) ? value : [value]
|
256
|
+
end
|
257
|
+
|
258
|
+
# Allows region-specific overrides of any of the settings on this
|
259
|
+
# configuration object. This allows the user to override things like
|
260
|
+
# AMI and keypair name for regions. Example:
|
261
|
+
#
|
262
|
+
# aws.region_config "us-east-1" do |region|
|
263
|
+
# region.ami = "ami-12345678"
|
264
|
+
# region.keypair_name = "company-east"
|
265
|
+
# end
|
266
|
+
#
|
267
|
+
# @param [String] region The region name to configure.
|
268
|
+
# @param [Hash] attributes Direct attributes to set on the configuration
|
269
|
+
# as a shortcut instead of specifying a full block.
|
270
|
+
# @yield [config] Yields a new AWS configuration.
|
271
|
+
def region_config(region, attributes=nil, &block)
|
272
|
+
# Append the block to the list of region configs for that region.
|
273
|
+
# We'll evaluate these upon finalization.
|
274
|
+
@__region_config[region] ||= []
|
275
|
+
|
276
|
+
# Append a block that sets attributes if we got one
|
277
|
+
if attributes
|
278
|
+
attr_block = lambda do |config|
|
279
|
+
config.set_options(attributes)
|
280
|
+
end
|
281
|
+
|
282
|
+
@__region_config[region] << attr_block
|
283
|
+
end
|
284
|
+
|
285
|
+
# Append a block if we got one
|
286
|
+
@__region_config[region] << block if block_given?
|
287
|
+
end
|
288
|
+
|
289
|
+
#-------------------------------------------------------------------
|
290
|
+
# Internal methods.
|
291
|
+
#-------------------------------------------------------------------
|
292
|
+
|
293
|
+
def merge(other)
|
294
|
+
super.tap do |result|
|
295
|
+
# Copy over the region specific flag. "True" is retained if either
|
296
|
+
# has it.
|
297
|
+
new_region_specific = other.instance_variable_get(:@__region_specific)
|
298
|
+
result.instance_variable_set(
|
299
|
+
:@__region_specific, new_region_specific || @__region_specific)
|
300
|
+
|
301
|
+
# Go through all the region configs and prepend ours onto
|
302
|
+
# theirs.
|
303
|
+
new_region_config = other.instance_variable_get(:@__region_config)
|
304
|
+
@__region_config.each do |key, value|
|
305
|
+
new_region_config[key] ||= []
|
306
|
+
new_region_config[key] = value + new_region_config[key]
|
307
|
+
end
|
308
|
+
|
309
|
+
# Set it
|
310
|
+
result.instance_variable_set(:@__region_config, new_region_config)
|
311
|
+
|
312
|
+
# Merge in the tags
|
313
|
+
result.tags.merge!(self.tags)
|
314
|
+
result.tags.merge!(other.tags)
|
315
|
+
|
316
|
+
# Merge in the package tags
|
317
|
+
result.package_tags.merge!(self.package_tags)
|
318
|
+
result.package_tags.merge!(other.package_tags)
|
319
|
+
|
320
|
+
# Merge block_device_mapping
|
321
|
+
result.block_device_mapping |= self.block_device_mapping
|
322
|
+
result.block_device_mapping |= other.block_device_mapping
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
def finalize!
|
327
|
+
# If access_key_id or secret_access_key were not specified in Vagrantfile
|
328
|
+
# then try to read from environment variables first, and if it fails from
|
329
|
+
# the AWS folder.
|
330
|
+
if @access_key_id == UNSET_VALUE or @secret_access_key == UNSET_VALUE
|
331
|
+
@aws_profile = 'default' if @aws_profile == UNSET_VALUE
|
332
|
+
@aws_dir = ENV['HOME'].to_s + '/.aws/' if @aws_dir == UNSET_VALUE
|
333
|
+
@region, @access_key_id, @secret_access_key, @session_token = Credentials.new.get_aws_info(@aws_profile, @aws_dir)
|
334
|
+
@region = UNSET_VALUE if @region.nil?
|
335
|
+
else
|
336
|
+
@aws_profile = nil
|
337
|
+
@aws_dir = nil
|
338
|
+
end
|
339
|
+
|
340
|
+
# session token must be set to nil, empty string isn't enough!
|
341
|
+
@session_token = nil if @session_token == UNSET_VALUE
|
342
|
+
|
343
|
+
# AMI must be nil, since we can't default that
|
344
|
+
@ami = nil if @ami == UNSET_VALUE
|
345
|
+
|
346
|
+
# Set the default timeout for waiting for an instance to be ready
|
347
|
+
@instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE
|
348
|
+
|
349
|
+
# Set the default interval to check instance state
|
350
|
+
@instance_check_interval = 2 if @instance_check_interval == UNSET_VALUE
|
351
|
+
|
352
|
+
# Set the default timeout for waiting for an instance to burn into and ami
|
353
|
+
@instance_package_timeout = 600 if @instance_package_timeout == UNSET_VALUE
|
354
|
+
|
355
|
+
# Default instance type is an m3.medium
|
356
|
+
@instance_type = "m3.medium" if @instance_type == UNSET_VALUE
|
357
|
+
|
358
|
+
# Keypair defaults to nil
|
359
|
+
@keypair_name = nil if @keypair_name == UNSET_VALUE
|
360
|
+
|
361
|
+
# Default the private IP to nil since VPC is not default
|
362
|
+
@private_ip_address = nil if @private_ip_address == UNSET_VALUE
|
363
|
+
|
364
|
+
# Acquire an elastic IP if requested
|
365
|
+
@elastic_ip = nil if @elastic_ip == UNSET_VALUE
|
366
|
+
|
367
|
+
# Default region is us-east-1. This is sensible because AWS
|
368
|
+
# generally defaults to this as well.
|
369
|
+
@region = "us-east-1" if @region == UNSET_VALUE
|
370
|
+
@availability_zone = nil if @availability_zone == UNSET_VALUE
|
371
|
+
@placement_group = nil if @placement_group == UNSET_VALUE
|
372
|
+
@endpoint = nil if @endpoint == UNSET_VALUE
|
373
|
+
@version = nil if @version == UNSET_VALUE
|
374
|
+
|
375
|
+
# The security groups are empty by default.
|
376
|
+
@security_groups = [] if @security_groups == UNSET_VALUE
|
377
|
+
|
378
|
+
# Subnet is nil by default otherwise we'd launch into VPC.
|
379
|
+
@subnet_id = nil if @subnet_id == UNSET_VALUE
|
380
|
+
|
381
|
+
# IAM Instance profile arn/name is nil by default.
|
382
|
+
@iam_instance_profile_arn = nil if @iam_instance_profile_arn == UNSET_VALUE
|
383
|
+
@iam_instance_profile_name = nil if @iam_instance_profile_name == UNSET_VALUE
|
384
|
+
|
385
|
+
# By default we don't use an IAM profile
|
386
|
+
@use_iam_profile = false if @use_iam_profile == UNSET_VALUE
|
387
|
+
|
388
|
+
# User Data is nil by default
|
389
|
+
@user_data = nil if @user_data == UNSET_VALUE
|
390
|
+
|
391
|
+
# default false
|
392
|
+
@terminate_on_shutdown = false if @terminate_on_shutdown == UNSET_VALUE
|
393
|
+
|
394
|
+
# default to nil
|
395
|
+
@ssh_host_attribute = nil if @ssh_host_attribute == UNSET_VALUE
|
396
|
+
|
397
|
+
# default false
|
398
|
+
@monitoring = false if @monitoring == UNSET_VALUE
|
399
|
+
|
400
|
+
# default false
|
401
|
+
@ebs_optimized = false if @ebs_optimized == UNSET_VALUE
|
402
|
+
|
403
|
+
# default to nil
|
404
|
+
@source_dest_check = nil if @source_dest_check == UNSET_VALUE
|
405
|
+
|
406
|
+
# default false
|
407
|
+
@associate_public_ip = false if @associate_public_ip == UNSET_VALUE
|
408
|
+
|
409
|
+
# default 'default'
|
410
|
+
@tenancy = "default" if @tenancy == UNSET_VALUE
|
411
|
+
|
412
|
+
# Don't attach instance to any ELB by default
|
413
|
+
@elb = nil if @elb == UNSET_VALUE
|
414
|
+
|
415
|
+
@unregister_elb_from_az = true if @unregister_elb_from_az == UNSET_VALUE
|
416
|
+
|
417
|
+
# default to nil
|
418
|
+
@kernel_id = nil if @kernel_id == UNSET_VALUE
|
419
|
+
|
420
|
+
# Compile our region specific configurations only within
|
421
|
+
# NON-REGION-SPECIFIC configurations.
|
422
|
+
if !@__region_specific
|
423
|
+
@__region_config.each do |region, blocks|
|
424
|
+
config = self.class.new(true).merge(self)
|
425
|
+
|
426
|
+
# Execute the configuration for each block
|
427
|
+
blocks.each { |b| b.call(config) }
|
428
|
+
|
429
|
+
# The region name of the configuration always equals the
|
430
|
+
# region config name:
|
431
|
+
config.region = region
|
432
|
+
|
433
|
+
# Finalize the configuration
|
434
|
+
config.finalize!
|
435
|
+
|
436
|
+
# Store it for retrieval
|
437
|
+
@__compiled_region_configs[region] = config
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
# Mark that we finalized
|
442
|
+
@__finalized = true
|
443
|
+
end
|
444
|
+
|
445
|
+
def validate(machine)
|
446
|
+
errors = _detected_errors
|
447
|
+
|
448
|
+
errors << I18n.t("vagrant_aws.config.aws_info_required",
|
449
|
+
:profile => @aws_profile, :location => @aws_dir) if \
|
450
|
+
@aws_profile and (@access_key_id.nil? or @secret_access_key.nil? or @region.nil?)
|
451
|
+
|
452
|
+
errors << I18n.t("vagrant_aws.config.region_required") if @region.nil?
|
453
|
+
|
454
|
+
if @region
|
455
|
+
# Get the configuration for the region we're using and validate only
|
456
|
+
# that region.
|
457
|
+
config = get_region_config(@region)
|
458
|
+
|
459
|
+
if !config.use_iam_profile
|
460
|
+
errors << I18n.t("vagrant_aws.config.access_key_id_required") if \
|
461
|
+
config.access_key_id.nil?
|
462
|
+
errors << I18n.t("vagrant_aws.config.secret_access_key_required") if \
|
463
|
+
config.secret_access_key.nil?
|
464
|
+
end
|
465
|
+
|
466
|
+
if config.associate_public_ip && !config.subnet_id
|
467
|
+
errors << I18n.t("vagrant_aws.config.subnet_id_required_with_public_ip")
|
468
|
+
end
|
469
|
+
|
470
|
+
errors << I18n.t("vagrant_aws.config.ami_required", :region => @region) if config.ami.nil?
|
471
|
+
end
|
472
|
+
|
473
|
+
{ "AWS Provider" => errors }
|
474
|
+
end
|
475
|
+
|
476
|
+
# This gets the configuration for a specific region. It shouldn't
|
477
|
+
# be called by the general public and is only used internally.
|
478
|
+
def get_region_config(name)
|
479
|
+
if !@__finalized
|
480
|
+
raise "Configuration must be finalized before calling this method."
|
481
|
+
end
|
482
|
+
|
483
|
+
# Return the compiled region config
|
484
|
+
@__compiled_region_configs[name] || self
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
|
489
|
+
class Credentials < Vagrant.plugin("2", :config)
|
490
|
+
# This module reads AWS config and credentials.
|
491
|
+
# Behaviour aims to mimic what is described in AWS documentation:
|
492
|
+
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
|
493
|
+
# http://docs.aws.amazon.com/cli/latest/topic/config-vars.html
|
494
|
+
# Which is the following (stopping at the first successful case):
|
495
|
+
# 1) read config and credentials from environment variables
|
496
|
+
# 2) read config and credentials from files at location defined by environment variables
|
497
|
+
# 3) read config and credentials from files at default location
|
498
|
+
#
|
499
|
+
# The mandatory fields for a successful "get credentials" are the id and the secret keys.
|
500
|
+
# Region is not required since Config#finalize falls back to sensible defaults.
|
501
|
+
# The behaviour is all-or-nothing (ie: no mixing between vars and files).
|
502
|
+
#
|
503
|
+
# It also allows choosing a profile (by default it's [default]) and an "info"
|
504
|
+
# directory (by default $HOME/.aws), which can be specified in the Vagrantfile.
|
505
|
+
# Supported information: region, aws_access_key_id, aws_secret_access_key, and aws_session_token.
|
506
|
+
|
507
|
+
def get_aws_info(profile, location)
|
508
|
+
# read credentials from environment variables
|
509
|
+
aws_region, aws_id, aws_secret, aws_token = read_aws_environment()
|
510
|
+
# if nothing there, then read from files
|
511
|
+
# (the _if_ doesn't check aws_region since Config#finalize sets one by default)
|
512
|
+
if aws_id.to_s == '' or aws_secret.to_s == ''
|
513
|
+
# check if there are env variables for credential location, if so use then
|
514
|
+
aws_config = ENV['AWS_CONFIG_FILE'].to_s
|
515
|
+
aws_creds = ENV['AWS_SHARED_CREDENTIALS_FILE'].to_s
|
516
|
+
if aws_config == '' or aws_creds == ''
|
517
|
+
aws_config = location + 'config'
|
518
|
+
aws_creds = location + 'credentials'
|
519
|
+
end
|
520
|
+
if File.exist?(aws_config) and File.exist?(aws_creds)
|
521
|
+
aws_region, aws_id, aws_secret, aws_token = read_aws_files(profile, aws_config, aws_creds)
|
522
|
+
end
|
523
|
+
end
|
524
|
+
aws_region = nil if aws_region == ''
|
525
|
+
aws_id = nil if aws_id == ''
|
526
|
+
aws_secret = nil if aws_secret == ''
|
527
|
+
aws_token = nil if aws_token == ''
|
528
|
+
|
529
|
+
return aws_region, aws_id, aws_secret, aws_token
|
530
|
+
end
|
531
|
+
|
532
|
+
|
533
|
+
private
|
534
|
+
|
535
|
+
def read_aws_files(profile, aws_config, aws_creds)
|
536
|
+
# determine section in config ini file
|
537
|
+
if profile == 'default'
|
538
|
+
ini_profile = profile
|
539
|
+
else
|
540
|
+
ini_profile = 'profile ' + profile
|
541
|
+
end
|
542
|
+
# get info from config ini file for selected profile
|
543
|
+
data = File.read(aws_config)
|
544
|
+
doc_cfg = IniParse.parse(data)
|
545
|
+
aws_region = doc_cfg[ini_profile]['region']
|
546
|
+
|
547
|
+
# determine section in credentials ini file
|
548
|
+
ini_profile = profile
|
549
|
+
# get info from credentials ini file for selected profile
|
550
|
+
data = File.read(aws_creds)
|
551
|
+
doc_cfg = IniParse.parse(data)
|
552
|
+
aws_id = doc_cfg[ini_profile]['aws_access_key_id']
|
553
|
+
aws_secret = doc_cfg[ini_profile]['aws_secret_access_key']
|
554
|
+
aws_token = doc_cfg[ini_profile]['aws_session_token']
|
555
|
+
|
556
|
+
return aws_region, aws_id, aws_secret, aws_token
|
557
|
+
end
|
558
|
+
|
559
|
+
def read_aws_environment()
|
560
|
+
aws_region = ENV['AWS_DEFAULT_REGION']
|
561
|
+
aws_id = ENV['AWS_ACCESS_KEY_ID']
|
562
|
+
aws_secret = ENV['AWS_SECRET_ACCESS_KEY']
|
563
|
+
aws_token = ENV['AWS_SESSION_TOKEN']
|
564
|
+
|
565
|
+
return aws_region, aws_id, aws_secret, aws_token
|
566
|
+
end
|
567
|
+
|
568
|
+
end
|
569
|
+
|
570
|
+
|
571
|
+
end
|
572
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module AWS
|
5
|
+
module Errors
|
6
|
+
class VagrantAWSError < Vagrant::Errors::VagrantError
|
7
|
+
error_namespace("vagrant_aws.errors")
|
8
|
+
end
|
9
|
+
|
10
|
+
class FogError < VagrantAWSError
|
11
|
+
error_key(:fog_error)
|
12
|
+
end
|
13
|
+
|
14
|
+
class InternalFogError < VagrantAWSError
|
15
|
+
error_key(:internal_fog_error)
|
16
|
+
end
|
17
|
+
|
18
|
+
class InstanceReadyTimeout < VagrantAWSError
|
19
|
+
error_key(:instance_ready_timeout)
|
20
|
+
end
|
21
|
+
|
22
|
+
class InstancePackageError < VagrantAWSError
|
23
|
+
error_key(:instance_package_error)
|
24
|
+
end
|
25
|
+
|
26
|
+
class InstancePackageTimeout < VagrantAWSError
|
27
|
+
error_key(:instance_package_timeout)
|
28
|
+
end
|
29
|
+
|
30
|
+
class RsyncError < VagrantAWSError
|
31
|
+
error_key(:rsync_error)
|
32
|
+
end
|
33
|
+
|
34
|
+
class MkdirError < VagrantAWSError
|
35
|
+
error_key(:mkdir_error)
|
36
|
+
end
|
37
|
+
|
38
|
+
class ElbDoesNotExistError < VagrantAWSError
|
39
|
+
error_key("elb_does_not_exist")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant AWS plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
# This is a sanity check to make sure no one is attempting to install
|
8
|
+
# this into an early Vagrant version.
|
9
|
+
if Vagrant::VERSION < "1.2.0"
|
10
|
+
raise "The Vagrant AWS plugin is only compatible with Vagrant 1.2+"
|
11
|
+
end
|
12
|
+
|
13
|
+
module VagrantPlugins
|
14
|
+
module AWS
|
15
|
+
class Plugin < Vagrant.plugin("2")
|
16
|
+
name "AWS"
|
17
|
+
description <<-DESC
|
18
|
+
This plugin installs a provider that allows Vagrant to manage
|
19
|
+
machines in AWS (EC2/VPC).
|
20
|
+
DESC
|
21
|
+
|
22
|
+
config(:aws, :provider) do
|
23
|
+
require_relative "config"
|
24
|
+
Config
|
25
|
+
end
|
26
|
+
|
27
|
+
provider(:aws, parallel: true) do
|
28
|
+
# Setup logging and i18n
|
29
|
+
setup_logging
|
30
|
+
setup_i18n
|
31
|
+
|
32
|
+
# Return the provider
|
33
|
+
require_relative "provider"
|
34
|
+
Provider
|
35
|
+
end
|
36
|
+
|
37
|
+
# This initializes the internationalization strings.
|
38
|
+
def self.setup_i18n
|
39
|
+
I18n.load_path << File.expand_path("locales/en.yml", AWS.source_root)
|
40
|
+
I18n.reload!
|
41
|
+
end
|
42
|
+
|
43
|
+
# This sets up our log level to be whatever VAGRANT_LOG is.
|
44
|
+
def self.setup_logging
|
45
|
+
require "log4r"
|
46
|
+
|
47
|
+
level = nil
|
48
|
+
begin
|
49
|
+
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
50
|
+
rescue NameError
|
51
|
+
# This means that the logging constant wasn't found,
|
52
|
+
# which is fine. We just keep `level` as `nil`. But
|
53
|
+
# we tell the user.
|
54
|
+
level = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
# Some constants, such as "true" resolve to booleans, so the
|
58
|
+
# above error checking doesn't catch it. This will check to make
|
59
|
+
# sure that the log level is an integer, as Log4r requires.
|
60
|
+
level = nil if !level.is_a?(Integer)
|
61
|
+
|
62
|
+
# Set the logging level on all "vagrant" namespaced
|
63
|
+
# logs as long as we have a valid level.
|
64
|
+
if level
|
65
|
+
logger = Log4r::Logger.new("vagrant_aws")
|
66
|
+
logger.outputters = Log4r::Outputter.stderr
|
67
|
+
logger.level = level
|
68
|
+
logger = nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|