Skip to content

Commit 54c462f

Browse files
committed
updated based on comments from @tyler-ball
1 parent b4c3e10 commit 54c462f

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'
@@ -103,6 +98,15 @@ class Ec2 < Kitchen::Driver::SSHBase
10398
end
10499
end
105100

101+
def self.iam_creds
102+
@iam_creds ||= begin
103+
fetch_credentials(use_iam_profile:true)
104+
rescue
105+
debug("fetch_credentials failed with exception #{e.message}:#{e.backtrace.join("\n")}")
106+
{}
107+
end
108+
end
109+
106110
def create(state)
107111
return if state[:server_id]
108112

0 commit comments

Comments
 (0)