Skip to content

Commit 1c56846

Browse files
abhilash-avdshelbyo
authored andcommitted
Add support for approximateCount and approximate Size of the objects within the bucket as bucket statistics
1 parent 8beaf32 commit 1c56846

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

oci/object_storage_bucket_data_source.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package provider
44

55
import (
66
"context"
7+
"strconv"
78

89
"github.com/hashicorp/terraform/helper/schema"
910
oci_object_storage "github.com/oracle/oci-go-sdk/objectstorage"
@@ -26,6 +27,14 @@ func BucketDataSource() *schema.Resource {
2627
Type: schema.TypeString,
2728
Computed: true,
2829
},
30+
"approximate_count": {
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
34+
"approximate_size": {
35+
Type: schema.TypeString,
36+
Computed: true,
37+
},
2938
"compartment_id": {
3039
Type: schema.TypeString,
3140
Computed: true,
@@ -104,6 +113,7 @@ func (s *BucketDataSourceCrud) Get() error {
104113
request.NamespaceName = &tmp
105114
}
106115

116+
request.Fields = oci_object_storage.GetGetBucketFieldsEnumValues()
107117
request.RequestMetadata.RetryPolicy = getRetryPolicy(true, "object_storage")
108118

109119
response, err := s.Client.GetBucket(context.Background(), request)
@@ -124,6 +134,14 @@ func (s *BucketDataSourceCrud) SetData() error {
124134

125135
s.D.Set("access_type", s.Res.PublicAccessType)
126136

137+
if s.Res.ApproximateCount != nil {
138+
s.D.Set("approximate_count", strconv.FormatInt(*s.Res.ApproximateCount, 10))
139+
}
140+
141+
if s.Res.ApproximateSize != nil {
142+
s.D.Set("approximate_size", strconv.FormatInt(*s.Res.ApproximateSize, 10))
143+
}
144+
127145
if s.Res.CompartmentId != nil {
128146
s.D.Set("compartment_id", *s.Res.CompartmentId)
129147
}

oci/object_storage_bucket_resource.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package provider
55
import (
66
"context"
77
"log"
8+
"strconv"
89

910
"github.com/hashicorp/terraform/helper/schema"
1011

@@ -72,6 +73,14 @@ func BucketResource() *schema.Resource {
7273
},
7374

7475
// Computed
76+
"approximate_count": {
77+
Type: schema.TypeString,
78+
Computed: true,
79+
},
80+
"approximate_size": {
81+
Type: schema.TypeString,
82+
Computed: true,
83+
},
7584
"created_by": {
7685
Type: schema.TypeString,
7786
Computed: true,
@@ -211,6 +220,7 @@ func (s *BucketResourceCrud) Get() error {
211220
request.NamespaceName = &tmp
212221
}
213222

223+
request.Fields = oci_object_storage.GetGetBucketFieldsEnumValues()
214224
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "object_storage")
215225

216226
response, err := s.Client.GetBucket(context.Background(), request)
@@ -314,6 +324,14 @@ func (s *BucketResourceCrud) Delete() error {
314324
func (s *BucketResourceCrud) SetData() error {
315325
s.D.Set("access_type", s.Res.PublicAccessType)
316326

327+
if s.Res.ApproximateCount != nil {
328+
s.D.Set("approximate_count", strconv.FormatInt(*s.Res.ApproximateCount, 10))
329+
}
330+
331+
if s.Res.ApproximateSize != nil {
332+
s.D.Set("approximate_size", strconv.FormatInt(*s.Res.ApproximateSize, 10))
333+
}
334+
317335
if s.Res.CompartmentId != nil {
318336
s.D.Set("compartment_id", *s.Res.CompartmentId)
319337
}

oci/object_storage_bucket_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,19 @@ func TestObjectStorageBucketResource_basic(t *testing.T) {
119119
},
120120
),
121121
},
122+
{
123+
Config: config + compartmentIdVariableStr + BucketResourceDependencies +
124+
generateResourceFromRepresentationMap("oci_objectstorage_bucket", "test_bucket", Optional, Create, bucketRepresentation),
125+
Check: resource.ComposeAggregateTestCheckFunc(
126+
resource.TestCheckResourceAttrSet(resourceName, "approximate_count"),
127+
resource.TestCheckResourceAttrSet(resourceName, "approximate_size"),
122128

129+
func(s *terraform.State) (err error) {
130+
resId, err = fromInstanceState(s, resourceName, "id")
131+
return err
132+
},
133+
),
134+
},
123135
// verify updates to compartment
124136
{
125137
Config: config + compartmentId2VariableStr + BucketResourceDependencies +
@@ -136,6 +148,8 @@ func TestObjectStorageBucketResource_basic(t *testing.T) {
136148
resource.TestCheckResourceAttrSet(resourceName, "namespace"),
137149
resource.TestCheckResourceAttr(resourceName, "storage_tier", "Standard"),
138150
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
151+
resource.TestCheckResourceAttrSet(resourceName, "approximate_count"),
152+
resource.TestCheckResourceAttrSet(resourceName, "approximate_size"),
139153

140154
func(s *terraform.State) (err error) {
141155
resId2, err = fromInstanceState(s, resourceName, "id")
@@ -218,6 +232,8 @@ func TestObjectStorageBucketResource_basic(t *testing.T) {
218232
//resource.TestCheckResourceAttrSet(singularDatasourceName, "object_lifecycle_policy_etag"),
219233
resource.TestCheckResourceAttr(singularDatasourceName, "storage_tier", "Standard"),
220234
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
235+
resource.TestCheckResourceAttrSet(singularDatasourceName, "approximate_count"),
236+
resource.TestCheckResourceAttrSet(singularDatasourceName, "approximate_size"),
221237
),
222238
},
223239
},

website/docs/d/object_storage_bucket.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ The following arguments are supported:
3535
The following attributes are exported:
3636

3737
* `access_type` - The type of public access enabled on this bucket. A bucket is set to `NoPublicAccess` by default, which only allows an authenticated caller to access the bucket and its contents. When `ObjectRead` is enabled on the bucket, public access is allowed for the `GetObject`, `HeadObject`, and `ListObjects` operations. When `ObjectReadWithoutList` is enabled on the bucket, public access is allowed for the `GetObject` and `HeadObject` operations.
38+
* `approximate_count` - The approximate number of objects in the bucket. Count statistics are reported periodically. You will see a lag between what is displayed and the actual object count.
39+
* `approximate_size` - The approximate total size in bytes of all objects in the bucket. Size statistics are reported periodically. You will see a lag between what is displayed and the actual size of the bucket.
3840
* `compartment_id` - The compartment ID in which the bucket is authorized.
3941
* `created_by` - The OCID of the user who created the bucket.
4042
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`

website/docs/r/object_storage_bucket.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Any change to a property that does not support update will force the destruction
5454
The following attributes are exported:
5555

5656
* `access_type` - The type of public access enabled on this bucket. A bucket is set to `NoPublicAccess` by default, which only allows an authenticated caller to access the bucket and its contents. When `ObjectRead` is enabled on the bucket, public access is allowed for the `GetObject`, `HeadObject`, and `ListObjects` operations. When `ObjectReadWithoutList` is enabled on the bucket, public access is allowed for the `GetObject` and `HeadObject` operations.
57+
* `approximate_count` - The approximate number of objects in the bucket. Count statistics are reported periodically. You will see a lag between what is displayed and the actual object count.
58+
* `approximate_size` - The approximate total size in bytes of all objects in the bucket. Size statistics are reported periodically. You will see a lag between what is displayed and the actual size of the bucket.
5759
* `compartment_id` - The compartment ID in which the bucket is authorized.
5860
* `created_by` - The OCID of the user who created the bucket.
5961
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`

0 commit comments

Comments
 (0)