Skip to content

Commit e143990

Browse files
authored
Refine object store examples (#306)
* Force new on all mutable object properties since PUT effectively forces new anyway * Change example to show practical use of file upload and PARs
1 parent 4d24261 commit e143990

File tree

10 files changed

+50
-121
lines changed

10 files changed

+50
-121
lines changed

docs/examples/object_storage/file_upload/data.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/examples/object_storage/file_upload/file_upload.tf

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ variable "user_ocid" {}
1111
variable "fingerprint" {}
1212
variable "private_key_path" {}
1313
variable "compartment_ocid" {}
14-
variable "region" { default = "us-phoenix-1" }
14+
variable "region" {}
1515

1616

1717
provider "oci" {
@@ -29,16 +29,27 @@ resource "oci_objectstorage_bucket" "t" {
2929
compartment_id = "${var.compartment_ocid}"
3030
namespace = "${data.oci_objectstorage_namespace.t.namespace}"
3131
name = "-tf-bucket"
32-
access_type="ObjectRead"
3332
}
3433

3534
resource "oci_objectstorage_object" "t" {
3635
namespace = "${data.oci_objectstorage_namespace.t.namespace}"
3736
bucket = "${oci_objectstorage_bucket.t.name}"
38-
object = "-tf-object"
39-
content = "${file("data.txt")}"
40-
content_type = "text/plain"
41-
metadata = {
42-
"version" = "1"
43-
}
37+
object = "index.html"
38+
content_language = "en-US"
39+
content_type = "text/html"
40+
content = "${file("index.html")}"
41+
}
42+
43+
resource "oci_objectstorage_preauthrequest" "par" {
44+
namespace = "${data.oci_objectstorage_namespace.t.namespace}"
45+
bucket = "${oci_objectstorage_bucket.t.name}"
46+
object = "${oci_objectstorage_object.t.object}"
47+
name = "par"
48+
access_type = "ObjectRead" // ObjectRead, ObjectWrite, ObjectReadWrite, AnyObjectWrite
49+
time_expires = "2019-11-10T23:00:00Z"
50+
}
51+
52+
// Note: this will only output the full, usable url the first time.
53+
output "par_request_url" {
54+
value = "https://objectstorage.${var.region}.oraclecloud.com${oci_objectstorage_preauthrequest.par.access_uri}"
4455
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<h1>Welcome</h1>
5+
</body>
6+
</html>

docs/examples/storage/preauthrequests/preauthreq.tf renamed to docs/examples/object_storage/preauthrequests/preauthreq.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ variable "user_ocid" {}
1414
variable "fingerprint" {}
1515
variable "private_key_path" {}
1616
variable "compartment_ocid" {}
17-
variable "namespace_name" {}
1817
variable "region" {}
1918

2019
variable "bucket_name" {}
@@ -28,28 +27,27 @@ provider "oci" {
2827
region = "${var.region}"
2928
}
3029

30+
data "oci_objectstorage_namespace" "ns" {
31+
}
3132

3233
resource "oci_objectstorage_preauthrequest" "parOnBucket" {
33-
namespace = "${var.namespace_name}"
34+
namespace = "${data.oci_objectstorage_namespace.ns.namespace}"
3435
bucket = "${var.bucket_name}"
3536
name = "parOnBucket"
3637
access_type = "AnyObjectWrite" //Other configurations accepted are ObjectWrite, ObjectReadWrite
3738
time_expires = "2019-11-10T23:00:00Z"
3839
}
3940

4041
resource "oci_objectstorage_preauthrequest" "parOnObject" {
41-
namespace = "${var.namespace_name}"
42+
namespace = "${data.oci_objectstorage_namespace.ns.namespace}"
4243
bucket = "${var.bucket_name}"
4344
object = "${var.object_name}"
4445
name = "parOnObject"
4546
access_type = "ObjectRead" //Other configurations accepted are ObjectWrite, ObjectReadWrite
4647
time_expires = "2019-11-10T23:00:00Z"
4748
}
4849

50+
// Note: this will only output the full, usable url the first time.
4951
output "par_request_url" {
50-
value = "${oci_objectstorage_preauthrequest.parOnObject.access_uri}"
51-
}
52-
53-
output "par_request_name" {
54-
value = "${oci_objectstorage_preauthrequest.parOnObject.name}"
52+
value = "https://objectstorage.${var.region}.oraclecloud.com${oci_objectstorage_preauthrequest.parOnObject.access_uri}"
5553
}

docs/examples/storage/object/README.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

docs/examples/storage/object/buckets.tf

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/examples/storage/object/env-vars

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/examples/storage/object/provider.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/examples/storage/object/variables.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

resource_obmcs_objectstorage_object.go

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ func ObjectResource() *schema.Resource {
1919
"namespace": {
2020
Type: schema.TypeString,
2121
Required: true,
22-
Computed: false,
22+
ForceNew: true,
2323
},
2424
"bucket": {
2525
Type: schema.TypeString,
2626
Required: true,
27-
Computed: false,
27+
ForceNew: true,
2828
},
2929
"object": {
3030
Type: schema.TypeString,
3131
Required: true,
32-
Computed: false,
32+
ForceNew: true,
3333
},
3434
"content": {
3535
Type: schema.TypeString,
3636
Optional: true,
37+
ForceNew: true,
3738
StateFunc: func(body interface{}) string {
3839
v := body.(string)
3940
if v == "" {
@@ -46,10 +47,12 @@ func ObjectResource() *schema.Resource {
4647
"content_encoding": {
4748
Type: schema.TypeString,
4849
Optional: true,
50+
ForceNew: true,
4951
},
5052
"content_language": {
5153
Type: schema.TypeString,
5254
Optional: true,
55+
ForceNew: true,
5356
},
5457
"content_length": {
5558
Type: schema.TypeInt,
@@ -63,10 +66,12 @@ func ObjectResource() *schema.Resource {
6366
Type: schema.TypeString,
6467
Optional: true,
6568
Computed: true,
69+
ForceNew: true,
6670
},
6771
"metadata": {
6872
Type: schema.TypeMap,
6973
Optional: true,
74+
ForceNew: true,
7075
},
7176
}
7277

@@ -77,7 +82,6 @@ func ObjectResource() *schema.Resource {
7782
Timeouts: crud.DefaultTimeout,
7883
Create: createObject,
7984
Read: readObject,
80-
Update: updateObject,
8185
Delete: deleteObject,
8286
Schema: objectSchema,
8387
}
@@ -97,13 +101,6 @@ func readObject(d *schema.ResourceData, m interface{}) (e error) {
97101
return crud.ReadResource(sync)
98102
}
99103

100-
func updateObject(d *schema.ResourceData, m interface{}) (e error) {
101-
sync := &ObjectResourceCrud{}
102-
sync.D = d
103-
sync.Client = m.(*OracleClients).client
104-
return crud.UpdateResource(d, sync)
105-
}
106-
107104
func deleteObject(d *schema.ResourceData, m interface{}) (e error) {
108105
sync := &ObjectResourceCrud{}
109106
sync.D = d
@@ -135,22 +132,6 @@ func (s *ObjectResourceCrud) SetData() {
135132
}
136133

137134
func (s *ObjectResourceCrud) Create() (e error) {
138-
e = s.Update()
139-
return
140-
}
141-
142-
func (s *ObjectResourceCrud) Get() (e error) {
143-
namespace := s.D.Get("namespace").(string)
144-
bucket := s.D.Get("bucket").(string)
145-
object := s.D.Get("object").(string)
146-
res, e := s.Client.GetObject(baremetal.Namespace(namespace), bucket, object, &baremetal.GetObjectOptions{})
147-
if e == nil {
148-
s.Res = res
149-
}
150-
return
151-
}
152-
153-
func (s *ObjectResourceCrud) Update() (e error) {
154135
namespace := s.D.Get("namespace").(string)
155136
bucket := s.D.Get("bucket").(string)
156137
object := s.D.Get("object").(string)
@@ -180,6 +161,17 @@ func (s *ObjectResourceCrud) Update() (e error) {
180161
return
181162
}
182163

164+
func (s *ObjectResourceCrud) Get() (e error) {
165+
namespace := s.D.Get("namespace").(string)
166+
bucket := s.D.Get("bucket").(string)
167+
object := s.D.Get("object").(string)
168+
res, e := s.Client.GetObject(baremetal.Namespace(namespace), bucket, object, &baremetal.GetObjectOptions{})
169+
if e == nil {
170+
s.Res = res
171+
}
172+
return
173+
}
174+
183175
func (s *ObjectResourceCrud) Delete() (e error) {
184176
namespace := s.D.Get("namespace").(string)
185177
bucket := s.D.Get("bucket").(string)

0 commit comments

Comments
 (0)