vagrant-aws 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 724f1ec5fa0d9c7bd580c8e61ed48b89adc3f68f
4
- data.tar.gz: 0d69fbb52adcb5587ba5e59289126f0bd2bfb6d1
3
+ metadata.gz: 6eb997239c2902fd5ffe82a2ad85f6a750b68fcc
4
+ data.tar.gz: b4db22de6d6004ec60a2bd97f8bea1abe0b23ff8
5
5
  SHA512:
6
- metadata.gz: 06e1e6f007d498b296c68d12c14852a5c58246a4707d6d0874091d59d05f0dc08caa3f7ce58b75ab91ae2ad3f1d3702a3ea07a12cf5109e3e90092417cf7fc3d
7
- data.tar.gz: f4211a869114ac7f4ef6ce5d157e96850150a5e782dd006a37887fc67c85a9427fa19ae1ec23e072233f29704bddfe346df02eb11c4e5009c1e5283a0dfe9de6
6
+ metadata.gz: 6a38047b88672ff53ff8002acaf948071bd020bac0e6cb4503291a1e10e2fb57406b4f6a6e1fadb63b5d1cfdf601b47b58bbb20191fe1d855a8748e0339422ad
7
+ data.tar.gz: d93eca59839124a024b471430d8864b4aec2a5d2a8723e3ddb77d2a9babab505a478bc4517cc39db8bd82f1b16a00a238b15347a38d83bf42ae6914d4f57be6f
data/.gitignore CHANGED
@@ -15,3 +15,7 @@ Gemfile.lock
15
15
  .vagrant
16
16
  Vagrantfile
17
17
  !example_box/Vagrantfile
18
+
19
+ # RVM files for gemset/ruby setting
20
+ .ruby-*
21
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format doc --order random --color --fail-fast
@@ -1,5 +1,14 @@
1
1
  # 0.5.0 (unreleased)
2
2
 
3
+ * Support for associating public IPs for VMs inside of VPCs (GH
4
+ [#219](https://github.com/mitchellh/vagrant-aws/pull/219), GH
5
+ [#205](https://github.com/mitchellh/vagrant-aws/issues/205))
6
+ * Bug-fix for per region configs with `associate_public_ip` (GH
7
+ [#237](https://github.com/mitchellh/vagrant-aws/pull/237))
8
+ * rsyncing folders uses `--delete` flag to better emulate "real shared folders
9
+ (GH [#194](https://github.com/mitchellh/vagrant-aws/pull/194))
10
+ * fog gem version bumped to 1.22 (GH [#253](https://github.com/mitchellh/vagrant-aws/pull/253))
11
+
3
12
  # 0.4.1 (December 17, 2013)
4
13
 
5
14
  * Update fog.io to 1.18.0
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
  The MIT License (MIT)
2
- Copyright (c) 2013 Mitchell Hashimoto
2
+ Copyright (c) 2014 Mitchell Hashimoto
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
5
 
data/README.md CHANGED
@@ -115,15 +115,17 @@ This provider exposes quite a few provider-specific configuration options:
115
115
  * `secret_access_key` - The secret access key for accessing AWS
116
116
  * `security_groups` - An array of security groups for the instance. If this
117
117
  instance will be launched in VPC, this must be a list of security group
118
- IDs.
118
+ Name.
119
119
  * `iam_instance_profile_arn` - The Amazon resource name (ARN) of the IAM Instance
120
120
  Profile to associate with the instance
121
121
  * `iam_instance_profile_name` - The name of the IAM Instance Profile to associate
122
122
  with the instance
123
123
  * `subnet_id` - The subnet to boot the instance into, for VPC.
124
+ * `associate_public_ip` - If true, will associate a public IP address to an instance in a VPC.
124
125
  * `tags` - A hash of tags to set on the machine.
125
126
  * `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
126
127
  for credentials.
128
+ * `block_device_mapping` - Amazon EC2 Block Device Mapping Property
127
129
 
128
130
  These can be set like typical provider-specific configuration:
129
131
 
@@ -222,6 +224,34 @@ Vagrant.configure("2") do |config|
222
224
  end
223
225
  ```
224
226
 
227
+ ### Disk size
228
+
229
+ Need more space on your instance disk? Increase the disk size.
230
+
231
+ ```ruby
232
+ Vagrant.configure("2") do |config|
233
+ # ... other stuff
234
+
235
+ config.vm.provider "aws" do |aws|
236
+ aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1', 'Ebs.VolumeSize' => 50 }]
237
+ end
238
+ end
239
+ ```
240
+
241
+ ### Elastic Load Balancers
242
+
243
+ You can automatically attach an instance to an ELB during boot and detach on destroy.
244
+
245
+ ```ruby
246
+ Vagrant.configure("2") do |config|
247
+ # ... other stuff
248
+
249
+ config.vm.provider "aws" do |aws|
250
+ aws.elb = "production-web"
251
+ end
252
+ end
253
+ ```
254
+
225
255
  ## Development
226
256
 
227
257
  To work on the `vagrant-aws` plugin, clone this repository out, and use
@@ -37,6 +37,7 @@ module VagrantPlugins
37
37
  end
38
38
  end
39
39
  b2.use ConnectAWS
40
+ b2.use ElbDeregisterInstance
40
41
  b2.use TerminateInstance
41
42
  b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
42
43
  else
@@ -118,6 +119,7 @@ module VagrantPlugins
118
119
  b.use Provision
119
120
  b.use SyncFolders
120
121
  b.use WarnNetworks
122
+ b.use ElbRegisterInstance
121
123
  end
122
124
  end
123
125
 
@@ -185,6 +187,8 @@ module VagrantPlugins
185
187
  autoload :TimedProvision, action_root.join("timed_provision") # some plugins now expect this action to exist
186
188
  autoload :WaitForState, action_root.join("wait_for_state")
187
189
  autoload :WarnNetworks, action_root.join("warn_networks")
190
+ autoload :ElbRegisterInstance, action_root.join("elb_register_instance")
191
+ autoload :ElbDeregisterInstance, action_root.join("elb_deregister_instance")
188
192
  end
189
193
  end
190
194
  end
@@ -37,6 +37,7 @@ module VagrantPlugins
37
37
 
38
38
  @logger.info("Connecting to AWS...")
39
39
  env[:aws_compute] = Fog::Compute.new(fog_config)
40
+ env[:aws_elb] = Fog::AWS::ELB.new(fog_config.except(:provider))
40
41
 
41
42
  @app.call(env)
42
43
  end
@@ -0,0 +1,24 @@
1
+ require 'vagrant-aws/util/elb'
2
+
3
+ module VagrantPlugins
4
+ module AWS
5
+ module Action
6
+ # This registers instance in ELB
7
+ class ElbDeregisterInstance
8
+ include ElasticLoadBalancer
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_aws::action::elb_deregister_instance")
13
+ end
14
+
15
+ def call(env)
16
+ if elb_name = env[:machine].provider_config.elb
17
+ deregister_instance env, elb_name, env[:machine].id
18
+ end
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'vagrant-aws/util/elb'
2
+
3
+ module VagrantPlugins
4
+ module AWS
5
+ module Action
6
+ # This registers instance in ELB
7
+ class ElbRegisterInstance
8
+ include ElasticLoadBalancer
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_aws::action::elb_register_instance")
13
+ end
14
+
15
+ def call(env)
16
+ @app.call(env)
17
+ if elb_name = env[:machine].provider_config.elb
18
+ register_instance env, elb_name, env[:machine].id
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -42,6 +42,7 @@ module VagrantPlugins
42
42
  iam_instance_profile_name = region_config.iam_instance_profile_name
43
43
  monitoring = region_config.monitoring
44
44
  ebs_optimized = region_config.ebs_optimized
45
+ associate_public_ip = region_config.associate_public_ip
45
46
 
46
47
  # If there is no keypair then warn the user
47
48
  if !keypair
@@ -72,6 +73,7 @@ module VagrantPlugins
72
73
  env[:ui].info(" -- Terminate On Shutdown: #{terminate_on_shutdown}")
73
74
  env[:ui].info(" -- Monitoring: #{monitoring}")
74
75
  env[:ui].info(" -- EBS optimized: #{ebs_optimized}")
76
+ env[:ui].info(" -- Assigning a public IP address in a VPC: #{associate_public_ip}")
75
77
 
76
78
  options = {
77
79
  :availability_zone => availability_zone,
@@ -87,7 +89,8 @@ module VagrantPlugins
87
89
  :block_device_mapping => block_device_mapping,
88
90
  :instance_initiated_shutdown_behavior => terminate_on_shutdown == true ? "terminate" : nil,
89
91
  :monitoring => monitoring,
90
- :ebs_optimized => ebs_optimized
92
+ :ebs_optimized => ebs_optimized,
93
+ :associate_public_ip => associate_public_ip
91
94
  }
92
95
  if !security_groups.empty?
93
96
  security_group_key = options[:subnet_id].nil? ? :groups : :security_group_ids
@@ -75,11 +75,18 @@ module VagrantPlugins
75
75
  #collect rsync excludes specified :rsync_excludes=>['path1',...] in synced_folder options
76
76
  excludes = ['.vagrant/', 'Vagrantfile', *Array(data[:rsync_excludes])].uniq
77
77
 
78
+ ssh_options = ["StrictHostKeyChecking=no"]
79
+ # Use proxy command if it's set
80
+ if ssh_info[:proxy_command]
81
+ ssh_options.push("ProxyCommand #{ssh_info[:proxy_command]}")
82
+ end
83
+
78
84
  # Rsync over to the guest path using the SSH info
79
85
  command = [
80
- "rsync", "--verbose", "--archive", "-z",
86
+ "rsync", "--verbose", "--archive", "-z", "--delete",
81
87
  *excludes.map{|e|['--exclude', e]}.flatten,
82
- "-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{ssh_key_options(ssh_info)}",
88
+ "-e", "ssh -p #{ssh_info[:port]} #{ssh_key_options(ssh_info)} " +
89
+ ssh_options_to_args(ssh_options).join(' '),
83
90
  hostpath,
84
91
  "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
85
92
 
@@ -99,6 +106,18 @@ module VagrantPlugins
99
106
  end
100
107
  end
101
108
 
109
+ # Generate a ssh(1) command line list of options
110
+ #
111
+ # @param [Array] options An array of ssh options. E.g.
112
+ # `StrictHostKeyChecking=no` see ssh_config(5) for more
113
+ # @return [Array] Computed list of command line arguments
114
+ def ssh_options_to_args(options)
115
+ # Bail early if we get something that is not an array of options
116
+ return [] unless options
117
+
118
+ return options.map { |o| "-o '#{o}'" }
119
+ end
120
+
102
121
  private
103
122
 
104
123
  def ssh_key_options(ssh_info)
@@ -133,6 +133,17 @@ module VagrantPlugins
133
133
  # @return [Boolean]
134
134
  attr_accessor :ebs_optimized
135
135
 
136
+ # Assigning a public IP address in a VPC
137
+ #
138
+ # @return [Boolean]
139
+ attr_accessor :associate_public_ip
140
+
141
+ # The name of ELB, which an instance should be
142
+ # attached to
143
+ #
144
+ # @return [String]
145
+ attr_accessor :elb
146
+
136
147
  def initialize(region_specific=false)
137
148
  @access_key_id = UNSET_VALUE
138
149
  @ami = UNSET_VALUE
@@ -158,6 +169,8 @@ module VagrantPlugins
158
169
  @ssh_host_attribute = UNSET_VALUE
159
170
  @monitoring = UNSET_VALUE
160
171
  @ebs_optimized = UNSET_VALUE
172
+ @associate_public_ip = UNSET_VALUE
173
+ @elb = UNSET_VALUE
161
174
 
162
175
  # Internal state (prefix with __ so they aren't automatically
163
176
  # merged)
@@ -214,7 +227,7 @@ module VagrantPlugins
214
227
  # has it.
215
228
  new_region_specific = other.instance_variable_get(:@__region_specific)
216
229
  result.instance_variable_set(
217
- :@__region_specific, new_region_specific || @__region_specific)
230
+ :@__region_specific, new_region_specific || @__region_specific)
218
231
 
219
232
  # Go through all the region configs and prepend ours onto
220
233
  # theirs.
@@ -296,6 +309,12 @@ module VagrantPlugins
296
309
  # default false
297
310
  @ebs_optimized = false if @ebs_optimized == UNSET_VALUE
298
311
 
312
+ # default false
313
+ @associate_public_ip = false if @associate_public_ip == UNSET_VALUE
314
+
315
+ # Don't attach instance to any ELB by default
316
+ @elb = nil if @elb == UNSET_VALUE
317
+
299
318
  # Compile our region specific configurations only within
300
319
  # NON-REGION-SPECIFIC configurations.
301
320
  if !@__region_specific
@@ -338,7 +357,11 @@ module VagrantPlugins
338
357
  config.secret_access_key.nil?
339
358
  end
340
359
 
341
- errors << I18n.t("vagrant_aws.config.ami_required") if config.ami.nil?
360
+ if config.associate_public_ip && !config.subnet_id
361
+ errors << I18n.t("vagrant_aws.config.subnet_id_required_with_public_ip")
362
+ end
363
+
364
+ errors << I18n.interpolate("vagrant_aws.config.ami_required", :region => @region) if config.ami.nil?
342
365
  end
343
366
 
344
367
  { "AWS Provider" => errors }
@@ -26,6 +26,10 @@ module VagrantPlugins
26
26
  class MkdirError < VagrantAWSError
27
27
  error_key(:mkdir_error)
28
28
  end
29
+
30
+ class ElbDoesNotExistError < VagrantAWSError
31
+ error_key("elb_does_not_exist")
32
+ end
29
33
  end
30
34
  end
31
35
  end
@@ -0,0 +1,56 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module ElasticLoadBalancer
4
+
5
+ def register_instance(env, elb_name, instance_id)
6
+ env[:ui].info I18n.t("vagrant_aws.elb.registering", instance_id: instance_id, elb_name: elb_name), :new_line => false
7
+ elb = get_load_balancer(env[:aws_elb], elb_name)
8
+ unless elb.instances.include? instance_id
9
+ elb.register_instances([instance_id])
10
+ env[:ui].info I18n.t("vagrant_aws.elb.ok"), :prefix => false
11
+ adjust_availability_zones env, elb
12
+ else
13
+ env[:ui].info I18n.t("vagrant_aws.elb.skipped"), :prefix => false
14
+ end
15
+ end
16
+
17
+ def deregister_instance(env, elb_name, instance_id)
18
+ env[:ui].info I18n.t("vagrant_aws.elb.deregistering", instance_id: instance_id, elb_name: elb_name), :new_line => false
19
+ elb = get_load_balancer(env[:aws_elb], elb_name)
20
+ if elb.instances.include? instance_id
21
+ elb.deregister_instances([instance_id])
22
+ env[:ui].info I18n.t("vagrant_aws.elb.ok"), :prefix => false
23
+ adjust_availability_zones env, elb
24
+ else
25
+ env[:ui].info I18n.t("vagrant_aws.elb.skipped"), :prefix => false
26
+ end
27
+ end
28
+
29
+ def adjust_availability_zones(env, elb)
30
+ env[:ui].info I18n.t("vagrant_aws.elb.adjusting", elb_name: elb.id), :new_line => false
31
+
32
+ instances = env[:aws_compute].servers.all("instance-id" => elb.instances)
33
+
34
+ azs = if instances.empty?
35
+ ["#{env[:machine].provider_config.region}a"]
36
+ else
37
+ instances.map(&:availability_zone).uniq
38
+ end
39
+
40
+ az_to_disable = elb.availability_zones - azs
41
+ az_to_enable = azs - elb.availability_zones
42
+
43
+ elb.enable_availability_zones az_to_enable unless az_to_enable.empty?
44
+ elb.disable_availability_zones az_to_disable unless az_to_disable.empty?
45
+
46
+ env[:ui].info I18n.t("vagrant_aws.elb.ok"), :prefix => false
47
+ end
48
+
49
+ private
50
+
51
+ def get_load_balancer(aws, name)
52
+ aws.load_balancers.find { |lb| lb.id == name } or raise Errors::ElbDoesNotExistError
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module AWS
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -2,6 +2,18 @@ en:
2
2
  vagrant_aws:
3
3
  already_status: |-
4
4
  The machine is already %{status}.
5
+ elb:
6
+ adjusting: |-
7
+ Adjusting availability zones of ELB %{elb_name}...
8
+ registering: |-
9
+ Registering %{instance_id} at ELB %{elb_name}...
10
+ deregistering: |-
11
+ Deregistering %{instance_id} from ELB %{elb_name}...
12
+ ok: |-
13
+ ok
14
+ skipped: |-
15
+ skipped
16
+
5
17
  launching_instance: |-
6
18
  Launching an instance with the following settings...
7
19
  launch_no_keypair: |-
@@ -46,13 +58,15 @@ en:
46
58
  access_key_id_required: |-
47
59
  An access key ID must be specified via "access_key_id"
48
60
  ami_required: |-
49
- An AMI must be configured via "ami"
61
+ An AMI must be configured via "ami" (region: #{region})
50
62
  private_key_missing: |-
51
63
  The specified private key for AWS could not be found
52
64
  region_required: |-
53
65
  A region must be specified via "region"
54
66
  secret_access_key_required: |-
55
67
  A secret access key is required via "secret_access_key"
68
+ subnet_id_required_with_public_ip: |-
69
+ If you assign a public IP address to an instance in a VPC, a subnet must be specifed via "subnet_id"
56
70
 
57
71
  errors:
58
72
  fog_error: |-
@@ -72,7 +86,7 @@ en:
72
86
  Please verify that the machine properly boots. If you need more time
73
87
  set the `instance_ready_timeout` configuration on the AWS provider.
74
88
  rsync_error: |-
75
- There was an error when attempting to rsync a share folder.
89
+ There was an error when attempting to rsync a shared folder.
76
90
  Please inspect the error message below for more info.
77
91
 
78
92
  Host path: %{hostpath}
@@ -84,6 +98,8 @@ en:
84
98
 
85
99
  Host path: %{hostpath}
86
100
  Error: %{err}
101
+ elb_does_not_exist: |-
102
+ ELB configured for the instance does not exist
87
103
 
88
104
  states:
89
105
  short_not_created: |-
@@ -99,7 +115,7 @@ en:
99
115
  short_stopping: |-
100
116
  stopping
101
117
  long_stopping: |-
102
- The EC2 instance is stopping. Wait until is completely stopped to
118
+ The EC2 instance is stopping. Wait until is completely stopped to
103
119
  run `vagrant up` and start it.
104
120
 
105
121
  short_pending: |-