@@ -30,6 +30,7 @@ module Driver
30
30
# @author Fletcher Nichol <[email protected] >
31
31
class Ec2 < Kitchen ::Driver ::SSHBase
32
32
33
+ extend Fog ::AWS ::CredentialFetcher ::ServiceMethods
33
34
default_config :region , 'us-east-1'
34
35
default_config :availability_zone , 'us-east-1b'
35
36
default_config :flavor_id , 'm1.small'
@@ -41,13 +42,13 @@ class Ec2 < Kitchen::Driver::SSHBase
41
42
default_config :iam_profile_name , nil
42
43
default_config :price , nil
43
44
default_config :aws_access_key_id do |driver |
44
- ENV [ 'AWS_ACCESS_KEY' ] || ENV [ 'AWS_ACCESS_KEY_ID' ]
45
+ ENV [ 'AWS_ACCESS_KEY' ] || ENV [ 'AWS_ACCESS_KEY_ID' ] || iam_creds [ :aws_access_key_id ]
45
46
end
46
47
default_config :aws_secret_access_key do |driver |
47
- ENV [ 'AWS_SECRET_KEY' ] || ENV [ 'AWS_SECRET_ACCESS_KEY' ]
48
+ ENV [ 'AWS_SECRET_KEY' ] || ENV [ 'AWS_SECRET_ACCESS_KEY' ] || iam_creds [ :aws_secret_access_key ]
48
49
end
49
50
default_config :aws_session_token do |driver |
50
- ENV [ 'AWS_SESSION_TOKEN' ] || ENV [ 'AWS_TOKEN' ]
51
+ ENV [ 'AWS_SESSION_TOKEN' ] || ENV [ 'AWS_TOKEN' ] || iam_creds [ :aws_session_token ]
51
52
end
52
53
default_config :aws_ssh_key_id do |driver |
53
54
ENV [ 'AWS_SSH_KEY_ID' ]
@@ -80,7 +81,7 @@ class Ec2 < Kitchen::Driver::SSHBase
80
81
validations [ d ] = lambda do |attr , val , driver |
81
82
unless val . nil?
82
83
driver . warn "WARN: The config key `#{ attr } ` is deprecated," +
83
- " please use `block_device_mappings`"
84
+ ' please use `block_device_mappings`'
84
85
end
85
86
end
86
87
end
@@ -97,14 +98,23 @@ class Ec2 < Kitchen::Driver::SSHBase
97
98
end
98
99
end
99
100
101
+ def self . iam_creds
102
+ @iam_creds ||= begin
103
+ fetch_credentials ( use_iam_profile :true )
104
+ rescue RuntimeError => e
105
+ debug ( "fetch_credentials failed with exception #{ e . message } :#{ e . backtrace . join ( "\n " ) } " )
106
+ { }
107
+ end
108
+ end
109
+
100
110
def create ( state )
101
111
return if state [ :server_id ]
102
112
103
113
info ( "Creating <#{ state [ :server_id ] } >..." )
104
- info ( " If you are not using an account that qualifies under the AWS" )
105
- info ( " free-tier, you may be charged to run these suites. The charge" )
106
- info ( " should be minimal, but neither Test Kitchen nor its maintainers" )
107
- info ( " are responsible for your incurred costs." )
114
+ info ( ' If you are not using an account that qualifies under the AWS' )
115
+ info ( ' free-tier, you may be charged to run these suites. The charge' )
116
+ info ( ' should be minimal, but neither Test Kitchen nor its maintainers' )
117
+ info ( ' are responsible for your incurred costs.' )
108
118
109
119
if config [ :price ]
110
120
# Spot instance when a price is set
0 commit comments