diff --git a/doc/_resource_types/s3_bucket.md b/doc/_resource_types/s3_bucket.md index b2ad5f65f..66ff07798 100644 --- a/doc/_resource_types/s3_bucket.md +++ b/doc/_resource_types/s3_bucket.md @@ -98,6 +98,14 @@ describe s3_bucket('my-bucket') do end ``` +### have_location + +```ruby +describe s3_bucket('my-bucket') do + it { should have_location('us-east-1') } +end +``` + ### have_logging_enabled ```ruby diff --git a/doc/resource_types.md b/doc/resource_types.md index 827cae5f0..227ac2396 100644 --- a/doc/resource_types.md +++ b/doc/resource_types.md @@ -3114,6 +3114,15 @@ end ``` +### have_location + +```ruby +describe s3_bucket('my-bucket') do + it { should have_location('us-east-1') } +end +``` + + ### have_logging_enabled ```ruby diff --git a/lib/awspec/generator/spec/s3_bucket.rb b/lib/awspec/generator/spec/s3_bucket.rb index f51cf9510..d411f8963 100644 --- a/lib/awspec/generator/spec/s3_bucket.rb +++ b/lib/awspec/generator/spec/s3_bucket.rb @@ -102,6 +102,9 @@ def bucket_spec_template <%= line %> <% end %> <%- end -%> +<%- if location -%> + it { should have_location('<%= location %>') } +<%- end -%> end EOF template @@ -117,6 +120,7 @@ def content(bucket) bucket_policy = policy.policy.read if policy lifecycle_rule = find_bucket_lifecycle_configuration(bucket.name) lifecycle_specs = generate_lifecycle_rule_specs(lifecycle_rule) if lifecycle_rule + location = find_bucket_location(bucket.name) ERB.new(bucket_spec_template, nil, '-').result(binding).gsub(/^\n/, '') end end diff --git a/lib/awspec/helper/finder/s3.rb b/lib/awspec/helper/finder/s3.rb index 8d7be1afb..1cc586846 100644 --- a/lib/awspec/helper/finder/s3.rb +++ b/lib/awspec/helper/finder/s3.rb @@ -35,6 +35,13 @@ def find_bucket_policy(id) nil end + def find_bucket_location(id) + bucket_location = s3_client.get_bucket_location(bucket: id) + bucket_location.location_constraint + rescue Aws::S3::Errors::ServiceError + nil + end + def find_bucket_logging(id) s3_client.get_bucket_logging(bucket: id) rescue Aws::S3::Errors::ServiceError diff --git a/lib/awspec/stub/s3_bucket.rb b/lib/awspec/stub/s3_bucket.rb index 813ed747b..1f2fc4a10 100644 --- a/lib/awspec/stub/s3_bucket.rb +++ b/lib/awspec/stub/s3_bucket.rb @@ -119,6 +119,9 @@ } ] }, + get_bucket_location: { + location_constraint: 'us-east-1' + }, get_bucket_encryption: { server_side_encryption_configuration: { rules: [ diff --git a/lib/awspec/type/s3_bucket.rb b/lib/awspec/type/s3_bucket.rb index 22e33dff7..4d448c4b8 100644 --- a/lib/awspec/type/s3_bucket.rb +++ b/lib/awspec/type/s3_bucket.rb @@ -24,6 +24,11 @@ def has_acl_grant?(grantee:, permission:) end end + def has_location?(location) + check_existence + find_bucket_location(id) == location + end + def acl_owner check_existence @acl = find_bucket_acl(id) diff --git a/spec/generator/spec/s3_bucket_spec.rb b/spec/generator/spec/s3_bucket_spec.rb index 83d8ee111..4290cdd22 100644 --- a/spec/generator/spec/s3_bucket_spec.rb +++ b/spec/generator/spec/s3_bucket_spec.rb @@ -35,6 +35,7 @@ status: 'Enabled' ) end + it { should have_location('us-east-1') } end EOF expect(s3_bucket.generate_all.to_s).to eq spec diff --git a/spec/type/s3_bucket_spec.rb b/spec/type/s3_bucket_spec.rb index fd953bae6..849de9fbe 100644 --- a/spec/type/s3_bucket_spec.rb +++ b/spec/type/s3_bucket_spec.rb @@ -10,6 +10,7 @@ it { should have_acl_grant(grantee: 'my-bucket-owner', permission: 'FULL_CONTROL') } it { should have_acl_grant(grantee: 'http://acs.amazonaws.com/groups/s3/LogDelivery', permission: 'WRITE') } it { should have_acl_grant(grantee: '68f4bb06b094152df53893bfba57760e', permission: 'READ') } + it { should have_location('us-east-1') } it do should have_cors_rule(