Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/resources/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ The following arguments are supported:

* `metadata` - (Optional) Map of metadata used for the object (keys must be lowercase).

* `content_type` - (Optional) The standard MIME type of the object's content (e.g., 'application/json', 'text/plain'). This specifies how the object should be interpreted by clients. See RFC 9110: https://www.rfc-editor.org/rfc/rfc9110.html#name-content-type

* `tags` - (Optional) Map of tags.

* `sse_customer_key` - (Optional) Customer's encryption keys to encrypt data (SSE-C)
Expand Down
19 changes: 15 additions & 4 deletions docs/resources/object_bucket_website_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,27 @@ Refer to the [dedicated documentation](https://www.scaleway.com/en/docs/object-s
## Example Usage

```terraform
resource "scaleway_object_bucket" "main" {
name = "MyBucket"
resource "scaleway_object_bucket" "test" {
name = "my-bucket"
acl = "public-read"
}

resource "scaleway_object_bucket_website_configuration" "main" {
bucket = scaleway_object_bucket.main.id
resource scaleway_object "some_file" {
bucket = scaleway_object_bucket.test.name
key = "index.html"
file = "index.html"
visibility = "public-read"
content_type = "text/html"
}

resource "scaleway_object_bucket_website_configuration" "test" {
bucket = scaleway_object_bucket.test.name
index_document {
suffix = "index.html"
}
error_document {
key = "error.html"
}
}
```

Expand Down
694 changes: 348 additions & 346 deletions internal/services/block/testdata/snapshot-from-s3.cassette.yaml

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions internal/services/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func ResourceObject() *schema.Resource {
},
ValidateDiagFunc: validateMapKeyLowerCase(),
},
"content_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The standard MIME type of the object's content (e.g., 'application/json', 'text/plain'). This specifies how the object should be interpreted by clients. See RFC 9110: https://www.rfc-editor.org/rfc/rfc9110.html#name-content-type",
},
"tags": {
Optional: true,
Type: schema.TypeMap,
Expand Down Expand Up @@ -153,6 +159,10 @@ func resourceObjectCreate(ctx context.Context, d *schema.ResourceData, m interfa
Metadata: types.ExpandMapStringString(d.Get("metadata")),
}

if contentType, ok := d.GetOk("content_type"); ok {
req.ContentType = types.ExpandStringPtr(contentType)
}

visibilityStr := types.ExpandStringPtr(d.Get("visibility").(string))
if visibilityStr != nil {
req.ACL = s3Types.ObjectCannedACL(*visibilityStr)
Expand Down Expand Up @@ -253,6 +263,10 @@ func resourceObjectUpdate(ctx context.Context, d *schema.ResourceData, m interfa
ACL: s3Types.ObjectCannedACL(d.Get("visibility").(string)),
}

if contentType, ok := d.GetOk("content_type"); ok {
req.ContentType = types.ExpandStringPtr(contentType)
}

if encryptionKey, ok := d.GetOk("sse_customer_key"); ok {
digestMD5, encryption, err := EncryptCustomerKey(encryptionKey.(string))
if err != nil {
Expand Down Expand Up @@ -286,6 +300,10 @@ func resourceObjectUpdate(ctx context.Context, d *schema.ResourceData, m interfa
ACL: s3Types.ObjectCannedACL(d.Get("visibility").(string)),
}

if contentType, ok := d.GetOk("content_type"); ok {
req.ContentType = types.ExpandStringPtr(contentType)
}

if encryptionKey, ok := d.GetOk("sse_customer_key"); ok {
digestMD5, encryption, err := EncryptCustomerKey(encryptionKey.(string))
if err != nil {
Expand Down Expand Up @@ -368,6 +386,7 @@ func resourceObjectRead(ctx context.Context, d *schema.ResourceData, m interface
}

_ = d.Set("metadata", types.FlattenMap(obj.Metadata))
_ = d.Set("content_type", &obj.ContentType)

tags, err := s3Client.GetObjectTagging(ctx, &s3.GetObjectTaggingInput{
Bucket: types.ExpandStringPtr(bucket),
Expand Down
40 changes: 39 additions & 1 deletion internal/services/object/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,45 @@ func TestAccObject_Basic(t *testing.T) {
})
}

func TestAccObject_ContentType(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()

bucketName := sdkacctest.RandomWithPrefix("test-acc-scaleway-object-content-type")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: resource.ComposeTestCheckFunc(
objectchecks.IsObjectDestroyed(tt),
objectchecks.IsBucketDestroyed(tt),
),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "scaleway_object_bucket" "main" {
name = "%s"
region = "%s"
}

resource "scaleway_object" "file" {
bucket = scaleway_object_bucket.main.id
key = "index.html"
file = "testfixture/index.html"
visibility = "public-read"
content_type = "text/html"
}

`, bucketName, objectTestsMainRegion),
Check: resource.ComposeTestCheckFunc(
objectchecks.CheckBucketExists(tt, "scaleway_object_bucket.main", true),
testAccCheckObjectExists(tt, "scaleway_object.file"),
resource.TestCheckResourceAttr("scaleway_object.file", "content_type", "text/html"),
),
},
},
})
}

func TestAccObject_Hash(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
Expand Down Expand Up @@ -161,7 +200,6 @@ func TestAccObject_Hash(t *testing.T) {
`, bucketName, objectTestsMainRegion),
Check: resource.ComposeTestCheckFunc(
objectchecks.CheckBucketExists(tt, "scaleway_object_bucket.base-01", true),
testAccCheckObjectExists(tt, "scaleway_object.file"),
),
},
},
Expand Down
Loading
Loading