lib/terraforming/resource/s3.rb in terraforming-0.1.6 vs lib/terraforming/resource/s3.rb in terraforming-0.2.0
- old
+ new
@@ -40,21 +40,30 @@
end
end
private
+ def bucket_location_of(bucket)
+ @client.get_bucket_location(bucket: bucket.name).location_constraint
+ end
+
def bucket_policy_of(bucket)
@client.get_bucket_policy(bucket: bucket.name)
rescue Aws::S3::Errors::NoSuchBucketPolicy
nil
end
def buckets
- @client.list_buckets.buckets
+ @client.list_buckets.buckets.select { |bucket| same_region?(bucket) }
end
def module_name_of(bucket)
normalize_module_name(bucket.name)
+ end
+
+ def same_region?(bucket)
+ bucket_location = bucket_location_of(bucket)
+ (bucket_location == @client.config.region) || (bucket_location == "" && @client.config.region == "us-east-1")
end
end
end
end