From 02c14e8282622c45bd600e23c3e6cffc1554c890 Mon Sep 17 00:00:00 2001 From: "B. Heath Robinson" Date: Wed, 25 Feb 2015 17:16:07 -0600 Subject: [PATCH] Use attribute for region if not in ec2 --- attributes/default.rb | 1 + libraries/ec2.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 0798c85a..4b3dc108 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -20,3 +20,4 @@ default['aws']['aws_sdk_version'] = '~> 2.0.22' default['aws']['databag_name'] = nil default['aws']['databag_entry'] = nil +default['aws']['region'] = nil diff --git a/libraries/ec2.rb b/libraries/ec2.rb index 640de56c..75d3a2d0 100644 --- a/libraries/ec2.rb +++ b/libraries/ec2.rb @@ -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)