Skip to content

Commit

Permalink
Merge pull request sous-chefs#160 from ubiquitousthey/region_from_att…
Browse files Browse the repository at this point in the history
…ribute

Use attribute for region if not in ec2
  • Loading branch information
tas50 committed Nov 25, 2015
2 parents 065c9a6 + 02c14e8 commit 7c68788
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
default['aws']['aws_sdk_version'] = '~> 2.2.3'
default['aws']['databag_name'] = nil
default['aws']['databag_entry'] = nil
default['aws']['region'] = nil
12 changes: 10 additions & 2 deletions libraries/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ def create_aws_interface(aws_interface)
Chef::Log.error("Missing gem 'aws-sdk'. Use the default aws recipe to install it first.")
end

region = instance_availability_zone
region = region[0, region.length - 1]
region = node['aws']['region']

if region.nil?
if node.attribute?('ec2')
region = instance_availability_zone
region = region[0, region.length - 1]
else
region = 'us-east-1'
end
end

if !new_resource.aws_access_key.to_s.empty? && !new_resource.aws_secret_access_key.to_s.empty?
creds = ::Aws::Credentials.new(new_resource.aws_access_key, new_resource.aws_secret_access_key, new_resource.aws_session_token)
Expand Down

0 comments on commit 7c68788

Please sign in to comment.