vagrant-aws 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.2.0 (April 16, 2013)
2
+
3
+ * Add support for `vagrant ssh -c` [GH-42]
4
+ * Ability to specify a timeout for waiting for instances to become ready. [GH-44]
5
+ * Better error message if instance didn't become ready in time.
6
+ * Connection can now be done using IAM profiles. [GH-41]
7
+
1
8
  # 0.1.3 (April 9, 2013)
2
9
 
3
10
  * The `AWS_ACCESS_KEY` and `AWS_SECRET_KEY` will be used if available
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Vagrant AWS Provider
2
2
 
3
- This is a [Vagrant](http://www.vagrantup.com) 1.1+ plugin that adds an [AWS](http://aws.amazon.com)
3
+ This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds an [AWS](http://aws.amazon.com)
4
4
  provider to Vagrant, allowing Vagrant to control and provision machines in
5
5
  EC2 and VPC.
6
6
 
7
- **NOTE:** This plugin requires Vagrant 1.1+,
7
+ **NOTE:** This plugin requires Vagrant 1.2+,
8
8
 
9
9
  ## Features
10
10
 
@@ -50,14 +50,15 @@ your information where necessary.
50
50
  Vagrant.configure("2") do |config|
51
51
  config.vm.box = "dummy"
52
52
 
53
- config.vm.provider :aws do |aws|
53
+ config.vm.provider :aws do |aws, override|
54
54
  aws.access_key_id = "YOUR KEY"
55
55
  aws.secret_access_key = "YOUR SECRET KEY"
56
56
  aws.keypair_name = "KEYPAIR NAME"
57
- aws.ssh_private_key_path = "PATH TO YOUR PRIVATE KEY"
58
57
 
59
58
  aws.ami = "ami-7747d01e"
60
- aws.ssh_username = "ubuntu"
59
+
60
+ override.ssh.username = "ubuntu"
61
+ override.ssh.private_key_path = "PATH TO YOUR PRIVATE KEY"
61
62
  end
62
63
  end
63
64
  ```
@@ -94,6 +95,8 @@ This provider exposes quite a few provider-specific configuration options:
94
95
  * `ami` - The AMI id to boot, such as "ami-12345678"
95
96
  * `availability_zone` - The availability zone within the region to launch
96
97
  the instance. If nil, it will use the default set by Amazon.
98
+ * `instance_ready_timeout` - The number of seconds to wait for the instance
99
+ to become "ready" in AWS. Defaults to 120 seconds.
97
100
  * `instance_type` - The type of instance, such as "m1.small". The default
98
101
  value of this if not specified is "m1.small".
99
102
  * `keypair_name` - The name of the keypair to use to bootstrap AMIs
@@ -102,14 +105,13 @@ This provider exposes quite a few provider-specific configuration options:
102
105
  within a [VPC](http://aws.amazon.com/vpc/)
103
106
  * `region` - The region to start the instance in, such as "us-east-1"
104
107
  * `secret_access_key` - The secret access key for accessing AWS
105
- * `ssh_private_key_path` - The path to the SSH private key. This overrides
106
- `config.ssh.private_key_path`.
107
- * `ssh_username` - The SSH username, which overrides `config.ssh.username`.
108
108
  * `security_groups` - An array of security groups for the instance. If this
109
109
  instance will be launched in VPC, this must be a list of security group
110
110
  IDs.
111
111
  * `subnet_id` - The subnet to boot the instance into, for VPC.
112
112
  * `tags` - A hash of tags to set on the machine.
113
+ * `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
114
+ for credentials.
113
115
 
114
116
  These can be set like typical provider-specific configuration:
115
117
 
@@ -23,10 +23,14 @@ module VagrantPlugins
23
23
  # Build the fog config
24
24
  fog_config = {
25
25
  :provider => :aws,
26
- :aws_access_key_id => region_config.access_key_id,
27
- :aws_secret_access_key => region_config.secret_access_key,
28
26
  :region => region
29
27
  }
28
+ if region_config.use_iam_profile
29
+ fog_config[:use_iam_profile] = True
30
+ else
31
+ fog_config[:aws_access_key_id] = region_config.access_key_id
32
+ fog_config[:aws_secret_access_key] = region_config.secret_access_key
33
+ end
30
34
 
31
35
  fog_config[:endpoint] = region_config.endpoint if region_config.endpoint
32
36
  fog_config[:version] = region_config.version if region_config.version
@@ -95,13 +95,24 @@ module VagrantPlugins
95
95
 
96
96
  # Wait for the instance to be ready first
97
97
  env[:metrics]["instance_ready_time"] = Util::Timer.time do
98
+ tries = region_config.instance_ready_timeout / 2
99
+
98
100
  env[:ui].info(I18n.t("vagrant_aws.waiting_for_ready"))
99
- retryable(:on => Fog::Errors::TimeoutError, :tries => 30) do
100
- # If we're interrupted don't worry about waiting
101
- next if env[:interrupted]
101
+ begin
102
+ retryable(:on => Fog::Errors::TimeoutError, :tries => tries) do
103
+ # If we're interrupted don't worry about waiting
104
+ next if env[:interrupted]
105
+
106
+ # Wait for the server to be ready
107
+ server.wait_for(2) { ready? }
108
+ end
109
+ rescue Fog::Errors::TimeoutError
110
+ # Delete the instance
111
+ terminate(env)
102
112
 
103
- # Wait for the server to be ready
104
- server.wait_for(2) { ready? }
113
+ # Notify the user
114
+ raise Errors::InstanceReadyTimeout,
115
+ timeout: region_config.instance_ready_timeout
105
116
  end
106
117
  end
107
118
 
@@ -70,6 +70,20 @@ module VagrantPlugins
70
70
  end
71
71
  end
72
72
 
73
+ def self.action_ssh_run
74
+ Vagrant::Action::Builder.new.tap do |b|
75
+ b.use ConfigValidate
76
+ b.use Call, IsCreated do |env, b2|
77
+ if !env[:result]
78
+ b2.use MessageNotCreated
79
+ next
80
+ end
81
+
82
+ b2.use SSHRun
83
+ end
84
+ end
85
+ end
86
+
73
87
  # This action is called to bring the box up from nothing.
74
88
  def self.action_up
75
89
  Vagrant::Action::Builder.new.tap do |b|
@@ -19,6 +19,11 @@ module VagrantPlugins
19
19
  # @return [String]
20
20
  attr_accessor :availability_zone
21
21
 
22
+ # The timeout to wait for an instance to become ready.
23
+ #
24
+ # @return [Fixnum]
25
+ attr_accessor :instance_ready_timeout
26
+
22
27
  # The type of instance to launch, such as "m1.small"
23
28
  #
24
29
  # @return [String]
@@ -87,6 +92,12 @@ module VagrantPlugins
87
92
  # @return [Hash<String, String>]
88
93
  attr_accessor :tags
89
94
 
95
+ # Use IAM Instance Role for authentication to AWS instead of an
96
+ # explicit access_id and secret_access_key
97
+ #
98
+ # @return [Boolean]
99
+ attr_accessor :use_iam_profile
100
+
90
101
  # The user data string
91
102
  #
92
103
  # @return [String]
@@ -96,6 +107,7 @@ module VagrantPlugins
96
107
  @access_key_id = UNSET_VALUE
97
108
  @ami = UNSET_VALUE
98
109
  @availability_zone = UNSET_VALUE
110
+ @instance_ready_timeout = UNSET_VALUE
99
111
  @instance_type = UNSET_VALUE
100
112
  @keypair_name = UNSET_VALUE
101
113
  @private_ip_address = UNSET_VALUE
@@ -110,6 +122,7 @@ module VagrantPlugins
110
122
  @subnet_id = UNSET_VALUE
111
123
  @tags = {}
112
124
  @user_data = UNSET_VALUE
125
+ @use_iam_profile = UNSET_VALUE
113
126
 
114
127
  # Internal state (prefix with __ so they aren't automatically
115
128
  # merged)
@@ -188,6 +201,9 @@ module VagrantPlugins
188
201
  # AMI must be nil, since we can't default that
189
202
  @ami = nil if @ami == UNSET_VALUE
190
203
 
204
+ # Set the default timeout for waiting for an instance to be ready
205
+ @instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE
206
+
191
207
  # Default instance type is an m1.small
192
208
  @instance_type = "m1.small" if @instance_type == UNSET_VALUE
193
209
 
@@ -217,6 +233,9 @@ module VagrantPlugins
217
233
  # Subnet is nil by default otherwise we'd launch into VPC.
218
234
  @subnet_id = nil if @subnet_id == UNSET_VALUE
219
235
 
236
+ # By default we don't use an IAM profile
237
+ @use_iam_profile = false if @use_iam_profile == UNSET_VALUE
238
+
220
239
  # User Data is nil by default
221
240
  @user_data = nil if @user_data == UNSET_VALUE
222
241
 
@@ -255,10 +274,13 @@ module VagrantPlugins
255
274
  # that region.
256
275
  config = get_region_config(@region)
257
276
 
258
- errors << I18n.t("vagrant_aws.config.access_key_id_required") if \
259
- config.access_key_id.nil?
260
- errors << I18n.t("vagrant_aws.config.secret_access_key_required") if \
261
- config.secret_access_key.nil?
277
+ if !config.use_iam_profile
278
+ errors << I18n.t("vagrant_aws.config.access_key_id_required") if \
279
+ config.access_key_id.nil?
280
+ errors << I18n.t("vagrant_aws.config.secret_access_key_required") if \
281
+ config.secret_access_key.nil?
282
+ end
283
+
262
284
  errors << I18n.t("vagrant_aws.config.ami_required") if config.ami.nil?
263
285
 
264
286
  if config.ssh_private_key_path && \
@@ -11,6 +11,10 @@ module VagrantPlugins
11
11
  error_key(:fog_error)
12
12
  end
13
13
 
14
+ class InstanceReadyTimeout < VagrantAWSError
15
+ error_key(:instance_ready_timeout)
16
+ end
17
+
14
18
  class RsyncError < VagrantAWSError
15
19
  error_key(:rsync_error)
16
20
  end
@@ -6,8 +6,8 @@ end
6
6
 
7
7
  # This is a sanity check to make sure no one is attempting to install
8
8
  # this into an early Vagrant version.
9
- if Vagrant::VERSION < "1.1.0"
10
- raise "The Vagrant AWS plugin is only compatible with Vagrant 1.1+"
9
+ if Vagrant::VERSION < "1.2.0"
10
+ raise "The Vagrant AWS plugin is only compatible with Vagrant 1.2+"
11
11
  end
12
12
 
13
13
  module VagrantPlugins
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module AWS
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -47,6 +47,11 @@ en:
47
47
  below:
48
48
 
49
49
  %{message}
50
+ instance_ready_timeout: |-
51
+ The instance never became "ready" in AWS. The timeout currently
52
+ set waiting for the instance to become ready is %{timeout} seconds.
53
+ Please verify that the machine properly boots. If you need more time
54
+ set the `instance_ready_timeout` configuration on the AWS provider.
50
55
  rsync_error: |-
51
56
  There was an error when attemping to rsync a share folder.
52
57
  Please inspect the error message below for more info.
@@ -18,6 +18,7 @@ describe VagrantPlugins::AWS::Config do
18
18
  its("access_key_id") { should be_nil }
19
19
  its("ami") { should be_nil }
20
20
  its("availability_zone") { should be_nil }
21
+ its("instance_ready_timeout") { should == 120 }
21
22
  its("instance_type") { should == "m1.small" }
22
23
  its("keypair_name") { should be_nil }
23
24
  its("private_ip_address") { should be_nil }
@@ -29,6 +30,7 @@ describe VagrantPlugins::AWS::Config do
29
30
  its("subnet_id") { should be_nil }
30
31
  its("tags") { should == {} }
31
32
  its("user_data") { should be_nil }
33
+ its("use_iam_profile") { should be_false }
32
34
  end
33
35
 
34
36
  describe "overriding defaults" do
@@ -36,10 +38,11 @@ describe VagrantPlugins::AWS::Config do
36
38
  # simple boilerplate test, so I cut corners here. It just sets
37
39
  # each of these attributes to "foo" in isolation, and reads the value
38
40
  # and asserts the proper result comes back out.
39
- [:access_key_id, :ami, :availability_zone, :instance_type,
40
- :keypair_name,
41
+ [:access_key_id, :ami, :availability_zone, :instance_ready_timeout,
42
+ :instance_type, :keypair_name,
41
43
  :region, :secret_access_key, :security_groups,
42
- :ssh_private_key_path, :ssh_username, :subnet_id, :tags].each do |attribute|
44
+ :ssh_private_key_path, :ssh_username, :subnet_id, :tags,
45
+ :use_iam_profile, :user_data].each do |attribute|
43
46
 
44
47
  it "should not default #{attribute} if overridden" do
45
48
  instance.send("#{attribute}=".to_sym, "foo")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-09 00:00:00.000000000 Z
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: 3553654739612910885
145
+ hash: 1824347495740521097
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  none: false
148
148
  requirements: