From d53c5ce9c932c4dfec5613d389984c4341bcff7a Mon Sep 17 00:00:00 2001 From: Stephen Cross Date: Mon, 20 Nov 2017 14:44:10 -0500 Subject: [PATCH 01/10] fix delete_at description --- opc/resource_storage_object.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opc/resource_storage_object.go b/opc/resource_storage_object.go index 51a57e1..a00f046 100644 --- a/opc/resource_storage_object.go +++ b/opc/resource_storage_object.go @@ -86,7 +86,7 @@ func resourceOPCStorageObject() *schema.Resource { Optional: true, Computed: true, ForceNew: true, - Description: "Specify the number of seconds after which the system deletes the object", + Description: "The date and time in UNIX Epoch time stamp format when the system removes the object", }, "etag": { Type: schema.TypeString, From 59635fb0ca7469c6ea0477eeeab64d57d8235654 Mon Sep 17 00:00:00 2001 From: Stephen Cross Date: Mon, 20 Nov 2017 23:06:41 -0500 Subject: [PATCH 02/10] storage object update & tests WIP --- opc/resource_storage_object.go | 16 ++++++++++ opc/resource_storage_object_test.go | 45 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/opc/resource_storage_object.go b/opc/resource_storage_object.go index a00f046..08566f0 100644 --- a/opc/resource_storage_object.go +++ b/opc/resource_storage_object.go @@ -95,6 +95,13 @@ func resourceOPCStorageObject() *schema.Resource { ForceNew: true, Description: "MD5 checksum value of the request body. Unquoted. Strongly Recommended", }, + "metadata": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + ForceNew: true, + Description: "The object metadata", + }, "transfer_encoding": { Type: schema.TypeString, Optional: true, @@ -201,6 +208,14 @@ func resourceOPCStorageObjectCreate(d *schema.ResourceData, meta interface{}) er input.ETag = v.(string) } + if v, ok := d.GetOk("metadata"); ok { + metadata := make(map[string]string) + for name, value := range v.(map[string]interface{}) { + metadata[name] = value.(string) + } + input.ObjectMetadata = metadata + } + if v, ok := d.GetOk("transfer_encoding"); ok { input.TransferEncoding = v.(string) } @@ -245,6 +260,7 @@ func resourceOPCStorageObjectRead(d *schema.ResourceData, meta interface{}) erro d.Set("last_modified", result.LastModified) d.Set("delete_at", result.DeleteAt) d.Set("object_manifest", result.ObjectManifest) + d.Set("metadata", result.ObjectMetadata) d.Set("timestamp", result.Timestamp) d.Set("transaction_id", result.TransactionID) diff --git a/opc/resource_storage_object_test.go b/opc/resource_storage_object_test.go index d121c97..03165e9 100644 --- a/opc/resource_storage_object_test.go +++ b/opc/resource_storage_object_test.go @@ -99,6 +99,30 @@ func TestAccOPCStorageObject_fileSource(t *testing.T) { }) } +func TestAccOPCStorageObject_objectMetadata(t *testing.T) { + resName := "opc_storage_object.test" + rInt := acctest.RandInt() + + body := _SourceInput + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckStorageObjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccOPCStorageObject_objectMetadata(rInt, body), + Check: resource.ComposeTestCheckFunc( + testAccCheckStorageObjectExists, + resource.TestCheckResourceAttr(resName, "name", fmt.Sprintf("test-acc-%d", rInt)), + resource.TestCheckResourceAttr(resName, "container", fmt.Sprintf("acc-test-%d", rInt)), + resource.TestCheckResourceAttrSet(resName, "metadata"), + ), + }, + }, + }) +} + func testAccCheckStorageObjectExists(s *terraform.State) error { client := testAccProvider.Meta().(*OPCClient).storageClient.Objects() @@ -146,6 +170,27 @@ resource "opc_storage_container" "foo" { }`, rInt) } +func testAccOPCStorageObject_objectMetadata(rInt int, body string) string { + return fmt.Sprintf(` +%s + +resource "opc_storage_object" "test" { + name = "test-acc-%d" + container = "${opc_storage_container.foo.name}" + content_type = "text/plain;charset=UTF-8" + metadata { + "Foo": "bar", + "Abc-Def": "XYZ" + } + content = < Date: Mon, 20 Nov 2017 23:07:46 -0500 Subject: [PATCH 03/10] Add additional attributed to sotrage container --- opc/resource_storage_container.go | 50 ++++++++++++++++++++++++++ opc/resource_storage_container_test.go | 12 +++++++ 2 files changed, 62 insertions(+) diff --git a/opc/resource_storage_container.go b/opc/resource_storage_container.go index afaecc9..b6f69e4 100644 --- a/opc/resource_storage_container.go +++ b/opc/resource_storage_container.go @@ -59,6 +59,24 @@ func resourceOPCStorageContainer() *schema.Resource { Type: schema.TypeInt, Optional: true, }, + "quota_bytes": { + Type: schema.TypeInt, + Optional: true, + }, + "quota_count": { + Type: schema.TypeInt, + Optional: true, + }, + "metadata": { + Type: schema.TypeMap, + Optional: true, + }, + // "georeplication_policy": { + // Type: schema.TypeList, + // Optional: true, + // Computed: true, + // Elem: &schema.Schema{Type: schema.TypeString}, + // }, }, } } @@ -93,6 +111,20 @@ func resourceOPCStorageContainerCreate(d *schema.ResourceData, meta interface{}) if maxAge, ok := d.GetOk("max_age"); ok { input.MaxAge = maxAge.(int) } + if quotaBytes, ok := d.GetOk("quota_bytes"); ok { + input.QuotaBytes = quotaBytes.(int) + } + if quotaCount, ok := d.GetOk("quota_count"); ok { + input.QuotaCount = quotaCount.(int) + } + + if v, ok := d.GetOk("metadata"); ok { + metadata := make(map[string]string) + for name, value := range v.(map[string]interface{}) { + metadata[name] = value.(string) + } + input.CustomMetadata = metadata + } info, err := client.CreateContainer(&input) if err != nil { @@ -134,6 +166,10 @@ func resourceOPCStorageContainerRead(d *schema.ResourceData, meta interface{}) e d.Set("primary_key", result.PrimaryKey) d.Set("secondary_key", result.SecondaryKey) d.Set("max_age", result.MaxAge) + d.Set("quota_bytes", result.QuotaBytes) + d.Set("quota_count", result.QuotaCount) + d.Set("metadata", result.CustomMetadata) + if err := setStringList(d, "read_acls", result.ReadACLs); err != nil { return err } @@ -197,6 +233,20 @@ func resourceOPCStorageContainerUpdate(d *schema.ResourceData, meta interface{}) if maxAge, ok := d.GetOk("max_age"); ok { input.MaxAge = maxAge.(int) } + if quotaBytes, ok := d.GetOk("quota_bytes"); ok { + input.QuotaBytes = quotaBytes.(int) + } + if quotaCount, ok := d.GetOk("quota_count"); ok { + input.QuotaCount = quotaCount.(int) + } + + if v, ok := d.GetOk("metadata"); ok { + metadata := make(map[string]string) + for name, value := range v.(map[string]interface{}) { + metadata[name] = value.(string) + } + input.CustomMetadata = metadata + } info, err := client.UpdateContainer(&input) if err != nil { diff --git a/opc/resource_storage_container_test.go b/opc/resource_storage_container_test.go index 1219284..b32246b 100644 --- a/opc/resource_storage_container_test.go +++ b/opc/resource_storage_container_test.go @@ -114,9 +114,14 @@ const testAccOPCStorageContainerBasic = ` resource "opc_storage_container" "test" { name = "acc-storage-container-%d" max_age = 50 + quota_bytes = 1000000000 + quota_count = 1000 primary_key = "test-key" allowed_origins = ["origin-1"] exposed_headers = ["exposed-header-1"] + metadate { + "Foo": "bar" + } } ` @@ -124,9 +129,16 @@ const testAccOPCStorageContainerUpdated = ` resource "opc_storage_container" "test" { name = "acc-storage-container-%d" max_age = 60 + quota_bytes = 2000000000 + quota_count = 2000 primary_key = "test-key-updated" secondary_key = "test-key" allowed_origins = ["origin-1", "origin-2"] exposed_headers = ["exposed-header-1", "exposed-header-2"] + metadate { + "Foo": "bar", + "Abc-Def": "xyz" + } + } ` From 6bef74d031b78a48e6ead52a069dea56fd1c75b7 Mon Sep 17 00:00:00 2001 From: Stephen Cross Date: Thu, 23 Nov 2017 17:18:34 -0500 Subject: [PATCH 04/10] update docs --- .../r/opc_storage_container.html.markdown | 5 ++ .../docs/r/opc_storage_object.html.markdown | 84 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 website/docs/r/opc_storage_object.html.markdown diff --git a/website/docs/r/opc_storage_container.html.markdown b/website/docs/r/opc_storage_container.html.markdown index c2a750f..12c34a4 100644 --- a/website/docs/r/opc_storage_container.html.markdown +++ b/website/docs/r/opc_storage_container.html.markdown @@ -41,6 +41,11 @@ The following arguments are supported: * `max_age` - (Optional) Maximum age in seconds for the origin to hold the preflight results. +* `quota_bytes` - (Optional) Maximum size of the container, in bytes + +* `quota_count` - (Optional) Maximum object count of the container + + ## Import Container's can be imported using the `resource name`, e.g. diff --git a/website/docs/r/opc_storage_object.html.markdown b/website/docs/r/opc_storage_object.html.markdown new file mode 100644 index 0000000..b6abe31 --- /dev/null +++ b/website/docs/r/opc_storage_object.html.markdown @@ -0,0 +1,84 @@ +--- +layout: "opc" +page_title: "Oracle: opc_storage_opject" +sidebar_current: "docs-opc-resource-storage-object" +description: |- + Creates and manages a Object in the OPC Storage Container. `storage_endpoint` must be set in the provider or environment to manage these resources. +--- + +# opc\_storage\_object + +Creates and manages a Object in the OPC Storage Container. `storage_endpoint` must be set in the provider or environment to manage these resources. + +## Example Usage + +```hcl +resource "opc_storage_object" "default" { + name = "storage-object-1" + container = "${opc_storage_container.container.name}" + file = "${"./source_file.txt"}" + etag = "${md5(file("./source_file.txt"))}" + content_type = "text/plain;charset=utf-8" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Storage Object. + +* `container` - (Required) The name of Storage Container the store the object in. + +* `content` - (Optional) Raw content in string-form of the data. + +* `file` - (Optional) File path for the content to use for data. + +* `copy_from` - (Optional) name of an existing object used to create the new object as a copy. The value is in form `container/object`. You must UTF-8-encode and then URL-encode the names of the container and object. + +* `content_disposition` - (Optional) Set the HTTP `Content-Disposition` header to specify the override behaviour for the browser, e.g. `inline` or `attachment`. + +* `content_encoding` - (Optional) set the HTTP `Content-Encoding` for the object. + +* `content_type` - (Optional) set the MIME type for the object. + +* `delete_at` - (Optional) The date and time in UNIX Epoch time stamp format when the system removes the object. + +* `etag` - (Optional) MD5 checksum value of the request body. Strongly Recommended. + +* `transfer_encoding` - (Optional) Set to `chunked` to enable chunked transfer encoding. + +* `metadata` - (Optional) Additional object metadata headers. See [Object Metadata ](#object-metadata) below for more information. + +## Attributes + +In addition to the attributes listed above, the following attributes are exported: + +* `id` - The combined container and object name path of the object. +* `accept_ranges` - Type of ranges that the object accepts. +* `content_length` - Length of the object in bytes. +* `last_modified` - Date and Time that the object was created/modified in ISO 8601. +* `object_manifest` - The dynamic large-object manifest object. +* `timestamp` - Date and Time in UNIX EPOCH when the account, container, or object was initially created at the current version. +* `transaction_id` - Transaction ID of the request. + +## Object Metadata + +The `metadata` config defines a map of additional meta data header name value pairs. + +```hcl +metadata { + "Foo-Bar" = "barfoo", + "Sha256" = "e91ed4f93637379a7539cb5d8d0b5bca3972755de4f9371ab2e123e7b4c53680" +} +``` + +The additional meta data items set on the object in the form `X-Object-Meta-{name}: {value}`, where `{name}` is the name of the metadata item `{value}` is the header content. + +## Import + +Object's can be imported using the `resource id`, e.g. + +```shell +$ terraform import opc_storage_object.default container/example +``` From e56e064a96ec065231ae06b879c4783f3283dd19 Mon Sep 17 00:00:00 2001 From: Stephen Cross Date: Thu, 23 Nov 2017 17:41:55 -0500 Subject: [PATCH 05/10] update service names --- website/opc.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/opc.erb b/website/opc.erb index fddd98e..3d9186b 100644 --- a/website/opc.erb +++ b/website/opc.erb @@ -26,7 +26,7 @@ > - Compute Resources + Compute Classic Resources - > - Storage PAAS Resources + > + Object Storage Classic Resources