Skip to content

Commit c0d1134

Browse files
committed
Allow move of bucket to other compartment
Add changelog for move compartment functionality for bucket
1 parent 6d62eee commit c0d1134

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
77

88
### Changed
99
- Default timeout changed from 5 minutes to 15 minutes to accommodate more resources that don't time out quicker.
10+
- Ability to update compartment of a bucket
1011

1112
## 2.1.13 - 2018-07-02
1213

docs/object_storage/buckets.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,43 @@
66

77
The following attributes are exported:
88

9-
* `access_type` - The type of public access available on this bucket. Allows authenticated caller to access the bucket or contents of this bucket. By default a bucket is set to NoPublicAccess. It is treated as NoPublicAccess when this value is not specified. When the type is NoPublicAccess the bucket does not allow any public access. When the type is ObjectRead the bucket allows public access to the GetObject, HeadObject, ListObjects.
9+
* `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.
1010
* `compartment_id` - The compartment ID in which the bucket is authorized.
1111
* `created_by` - The OCID of the user who created the bucket.
1212
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
1313
* `etag` - The entity tag for the bucket.
1414
* `freeform_tags` - Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
1515
* `metadata` - Arbitrary string keys and values for user-defined metadata.
16-
* `name` - The name of the bucket.
16+
* `name` - The name of the bucket. Avoid entering confidential information. Example: my-new-bucket1
1717
* `namespace` - The namespace in which the bucket lives.
1818
* `storage_tier` - The type of storage tier of this bucket. A bucket is set to 'Standard' tier by default, which means the bucket will be put in the standard storage tier. When 'Archive' tier type is set explicitly, the bucket is put in the archive storage tier. The 'storageTier' property is immutable after bucket is created.
19-
* `time_created` - The date and time at which the bucket was created.
19+
* `time_created` - The date and time the bucket was created, as described in [RFC 2616](https://tools.ietf.org/rfc/rfc2616), section 14.29.
2020

2121

2222

2323
### Create Operation
2424
Creates a bucket in the given namespace with a bucket name and optional user-defined metadata.
2525

26-
To use this and other API operations, you must be authorized in an IAM policy. If you're not authorized,
27-
talk to an administrator. If you're an administrator who needs to write policies to give users access, see
28-
[Getting Started with Policies](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Concepts/policygetstarted.htm).
29-
3026

3127
The following arguments are supported:
3228

33-
* `access_type` - (Optional) The type of public access available on this bucket. Allows authenticated caller to access the bucket or contents of this bucket. By default a bucket is set to NoPublicAccess. It is treated as NoPublicAccess when this value is not specified. When the type is NoPublicAccess the bucket does not allow any public access. When the type is ObjectRead the bucket allows public access to the GetObject, HeadObject, ListObjects.
29+
* `access_type` - (Optional) 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.
3430
* `compartment_id` - (Required) The ID of the compartment in which to create the bucket.
3531
* `defined_tags` - (Optional) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
3632
* `freeform_tags` - (Optional) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
3733
* `metadata` - (Optional) Arbitrary string, up to 4KB, of keys and values for user-defined metadata.
38-
* `name` - (Required) The name of the bucket. Valid characters are uppercase or lowercase letters, numbers, and dashes. Bucket names must be unique within the namespace.
34+
* `name` - (Required) The name of the bucket. Valid characters are uppercase or lowercase letters, numbers, and dashes. Bucket names must be unique within the namespace. Avoid entering confidential information. example: Example: my-new-bucket1
3935
* `namespace` - (Required) The top-level namespace used for the request.
4036
* `storage_tier` - (Optional) The type of storage tier of this bucket. A bucket is set to 'Standard' tier by default, which means the bucket will be put in the standard storage tier. When 'Archive' tier type is set explicitly, the bucket is put in the Archive Storage tier. The 'storageTier' property is immutable after bucket is created.
4137

4238

4339
### Update Operation
40+
Performs a partial or full update of a bucket's user-defined metadata.
41+
4442

4543
The following arguments support updates:
46-
* `access_type` - The type of public access available on this bucket. Allows authenticated caller to access the bucket or contents of this bucket. By default a bucket is set to NoPublicAccess. It is treated as NoPublicAccess when this value is not specified. When the type is NoPublicAccess the bucket does not allow any public access. When the type is ObjectRead the bucket allows public access to the GetObject, HeadObject, ListObjects.
44+
* `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.
45+
* `compartment_id` - The ID of the compartment in which to create the bucket.
4746
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
4847
* `freeform_tags` - Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
4948
* `metadata` - Arbitrary string, up to 4KB, of keys and values for user-defined metadata.
@@ -79,8 +78,8 @@ Gets a list of buckets.
7978
Gets a list of all `BucketSummary`s in a compartment. A `BucketSummary` contains only summary fields for the bucket
8079
and does not contain fields like the user-defined metadata.
8180

82-
To use this and other API operations, you must be authorized in an IAM policy. If you're not authorized,
83-
talk to an administrator. If you're an administrator who needs to write policies to give users access, see
81+
To use this and other API operations, you must be authorized in an IAM policy. If you're not authorized,
82+
talk to an administrator. If you're an administrator who needs to write policies to give users access, see
8483
[Getting Started with Policies](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Concepts/policygetstarted.htm).
8584

8685
The following arguments are supported:

provider/object_storage_bucket_resource.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func BucketResource() *schema.Resource {
2828
"compartment_id": {
2929
Type: schema.TypeString,
3030
Required: true,
31-
ForceNew: true,
3231
},
3332
"name": {
3433
Type: schema.TypeString,
@@ -130,7 +129,6 @@ type BucketResourceCrud struct {
130129
DisableNotFoundRetries bool
131130
}
132131

133-
// @CODEGEN 2/2018: Remove ID() function from here. This resource doesn't have an ID property.
134132
func (s *BucketResourceCrud) ID() string {
135133
if s.Res.Namespace == nil || s.Res.Name == nil {
136134
log.Printf("Could not get ID for bucket. The bucket namespace and/or name is nil")
@@ -195,8 +193,8 @@ func (s *BucketResourceCrud) Create() error {
195193
func (s *BucketResourceCrud) Get() error {
196194
request := oci_object_storage.GetBucketRequest{}
197195

198-
if bucketName, ok := s.D.GetOkExists("name"); ok {
199-
tmp := bucketName.(string)
196+
if name, ok := s.D.GetOkExists("name"); ok {
197+
tmp := name.(string)
200198
request.BucketName = &tmp
201199
}
202200

@@ -223,11 +221,16 @@ func (s *BucketResourceCrud) Update() error {
223221
request.PublicAccessType = oci_object_storage.UpdateBucketDetailsPublicAccessTypeEnum(accessType.(string))
224222
}
225223

226-
if bucketName, ok := s.D.GetOkExists("name"); ok {
227-
tmp := bucketName.(string)
224+
if bucket, ok := s.D.GetOkExists("name"); ok {
225+
tmp := bucket.(string)
228226
request.BucketName = &tmp
229227
}
230228

229+
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
230+
tmp := compartmentId.(string)
231+
request.CompartmentId = &tmp
232+
}
233+
231234
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
232235
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
233236
if err != nil {
@@ -279,8 +282,8 @@ func (s *BucketResourceCrud) Update() error {
279282
func (s *BucketResourceCrud) Delete() error {
280283
request := oci_object_storage.DeleteBucketRequest{}
281284

282-
if bucketName, ok := s.D.GetOkExists("name"); ok {
283-
tmp := bucketName.(string)
285+
if name, ok := s.D.GetOkExists("name"); ok {
286+
tmp := name.(string)
284287
request.BucketName = &tmp
285288
}
286289

@@ -335,7 +338,3 @@ func (s *BucketResourceCrud) SetData() {
335338
}
336339

337340
}
338-
339-
// @CODEGEN 2/2018: mapToObject functions are generated here because generator doesn't handle map types from the spec.
340-
// Metadata field actually needs to be converted to a map[string]string type.
341-
// Remove the mapToObject functions from here and use the converter from helpers_objectstorage.go

provider/object_storage_bucket_test.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func TestObjectStorageBucketResource_basic(t *testing.T) {
5757
compartmentId := getRequiredEnvSetting("compartment_ocid")
5858
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
5959

60+
compartmentId2 := getRequiredEnvSetting("compartment_id_for_update")
61+
compartmentId2VariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId2)
62+
6063
resourceName := "oci_objectstorage_bucket.test_bucket"
6164
datasourceName := "data.oci_objectstorage_bucket_summaries.test_buckets"
6265

@@ -111,6 +114,31 @@ func TestObjectStorageBucketResource_basic(t *testing.T) {
111114
),
112115
},
113116

117+
// verify updates to compartment
118+
{
119+
Config: config + BucketPropertyVariables + compartmentId2VariableStr + BucketResourceConfig,
120+
Check: resource.ComposeAggregateTestCheckFunc(
121+
resource.TestCheckResourceAttr(resourceName, "access_type", "NoPublicAccess"),
122+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId2),
123+
resource.TestCheckResourceAttrSet(resourceName, "created_by"),
124+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
125+
resource.TestCheckResourceAttrSet(resourceName, "etag"),
126+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
127+
resource.TestCheckResourceAttr(resourceName, "metadata.%", "1"),
128+
resource.TestCheckResourceAttr(resourceName, "name", "my-test-1"),
129+
resource.TestCheckResourceAttrSet(resourceName, "namespace"),
130+
resource.TestCheckResourceAttr(resourceName, "storage_tier", "Standard"),
131+
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
132+
133+
func(s *terraform.State) (err error) {
134+
resId2, err = fromInstanceState(s, resourceName, "id")
135+
if resId != resId2 {
136+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
137+
}
138+
return err
139+
},
140+
),
141+
},
114142
// verify updates to updatable parameters
115143
{
116144
Config: config + `
@@ -119,7 +147,7 @@ variable "bucket_defined_tags_value" { default = "updatedValue" }
119147
variable "bucket_freeform_tags" { default = {"Department"= "Accounting"} }
120148
variable "bucket_metadata" { default = {"content-type" = "text/xml"} }
121149
variable "bucket_name" { default = "name2" }
122-
variable "bucket_storage_tier" { default = "Standard" }
150+
variable "bucket_storage_tier" { default = "Archive" }
123151
124152
` + compartmentIdVariableStr + BucketResourceConfig,
125153
Check: resource.ComposeAggregateTestCheckFunc(
@@ -132,12 +160,12 @@ variable "bucket_storage_tier" { default = "Standard" }
132160
resource.TestCheckResourceAttr(resourceName, "metadata.%", "1"),
133161
resource.TestCheckResourceAttr(resourceName, "name", "name2"),
134162
resource.TestCheckResourceAttrSet(resourceName, "namespace"),
135-
resource.TestCheckResourceAttr(resourceName, "storage_tier", "Standard"),
163+
resource.TestCheckResourceAttr(resourceName, "storage_tier", "Archive"),
136164
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
137165

138166
func(s *terraform.State) (err error) {
139167
resId2, err = fromInstanceState(s, resourceName, "id")
140-
// Reverse the check till we have absorbed the changes
168+
// The id changes when the name changes
141169
if resId == resId2 {
142170
return fmt.Errorf("Resource updated when it was supposed to be recreated.")
143171
}

0 commit comments

Comments
 (0)