Skip to content

Commit 4b0a001

Browse files
committed
updated based on comments from @tyler-ball
1 parent 0ab44fe commit 4b0a001

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/kitchen/driver/ec2.rb

+10-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
require 'json'
2121
require 'fog'
2222
require 'kitchen'
23-
include Fog::AWS::CredentialFetcher::ServiceMethods
2423

2524
module Kitchen
2625

@@ -31,11 +30,7 @@ module Driver
3130
# @author Fletcher Nichol <[email protected]>
3231
class Ec2 < Kitchen::Driver::SSHBase
3332

34-
35-
iam_creds = Fog::AWS::CredentialFetcher::ServiceMethods.fetch_credentials(
36-
use_iam_profile: true
37-
) rescue {}
38-
33+
extend Fog::AWS::CredentialFetcher::ServiceMethods
3934
default_config :region, 'us-east-1'
4035
default_config :availability_zone, 'us-east-1b'
4136
default_config :flavor_id, 'm1.small'
@@ -78,6 +73,15 @@ class Ec2 < Kitchen::Driver::SSHBase
7873
required_config :aws_ssh_key_id
7974
required_config :image_id
8075

76+
def self.iam_creds
77+
@iam_creds ||= begin
78+
fetch_credentials(use_iam_profile:true)
79+
rescue
80+
debug("fetch_credentials failed with exception #{e.message}:#{e.backtrace.join("\n")}")
81+
{}
82+
end
83+
end
84+
8185
def create(state)
8286
return if state[:server_id]
8387

0 commit comments

Comments
 (0)