Skip to content

Commit 62dfb95

Browse files
committed
fix(object): add content_type attribut
1 parent 555a269 commit 62dfb95

File tree

4 files changed

+1567
-1
lines changed

4 files changed

+1567
-1
lines changed

internal/services/object/object.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func ResourceObject() *schema.Resource {
8989
},
9090
ValidateDiagFunc: validateMapKeyLowerCase(),
9191
},
92+
"content_type": {
93+
Type: schema.TypeString,
94+
Optional: true,
95+
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",
96+
},
9297
"tags": {
9398
Optional: true,
9499
Type: schema.TypeMap,
@@ -146,11 +151,13 @@ func resourceObjectCreate(ctx context.Context, d *schema.ResourceData, m interfa
146151
storageClassStr := d.Get("storage_class").(string)
147152
storageClass := s3Types.StorageClass(storageClassStr)
148153

154+
149155
req := &s3.PutObjectInput{
150156
Bucket: types.ExpandStringPtr(bucket),
151157
Key: types.ExpandStringPtr(key),
152158
StorageClass: storageClass,
153159
Metadata: types.ExpandMapStringString(d.Get("metadata")),
160+
ContentType: types.ExpandStringPtr(d.Get("content_type")),
154161
}
155162

156163
visibilityStr := types.ExpandStringPtr(d.Get("visibility").(string))
@@ -251,6 +258,7 @@ func resourceObjectUpdate(ctx context.Context, d *schema.ResourceData, m interfa
251258
StorageClass: s3Types.StorageClass(d.Get("storage_class").(string)),
252259
Metadata: types.ExpandMapStringString(d.Get("metadata")),
253260
ACL: s3Types.ObjectCannedACL(d.Get("visibility").(string)),
261+
ContentType: types.ExpandStringPtr(d.Get("content_type")),
254262
}
255263

256264
if encryptionKey, ok := d.GetOk("sse_customer_key"); ok {
@@ -284,6 +292,7 @@ func resourceObjectUpdate(ctx context.Context, d *schema.ResourceData, m interfa
284292
CopySource: scw.StringPtr(fmt.Sprintf("%s/%s", bucket, key)),
285293
Metadata: types.ExpandMapStringString(d.Get("metadata")),
286294
ACL: s3Types.ObjectCannedACL(d.Get("visibility").(string)),
295+
ContentType: types.ExpandStringPtr("content_type"),
287296
}
288297

289298
if encryptionKey, ok := d.GetOk("sse_customer_key"); ok {
@@ -368,6 +377,7 @@ func resourceObjectRead(ctx context.Context, d *schema.ResourceData, m interface
368377
}
369378

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

372382
tags, err := s3Client.GetObjectTagging(ctx, &s3.GetObjectTaggingInput{
373383
Bucket: types.ExpandStringPtr(bucket),

internal/services/object/object_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,45 @@ func TestAccObject_Basic(t *testing.T) {
107107
})
108108
}
109109

110+
func TestAccObject_ContentType(t *testing.T) {
111+
tt := acctest.NewTestTools(t)
112+
defer tt.Cleanup()
113+
114+
bucketName := sdkacctest.RandomWithPrefix("test-acc-scaleway-object-content-type")
115+
resource.ParallelTest(t, resource.TestCase{
116+
PreCheck: func() { acctest.PreCheck(t) },
117+
ProviderFactories: tt.ProviderFactories,
118+
CheckDestroy: resource.ComposeTestCheckFunc(
119+
objectchecks.IsObjectDestroyed(tt),
120+
objectchecks.IsBucketDestroyed(tt),
121+
),
122+
Steps: []resource.TestStep{
123+
{
124+
Config: fmt.Sprintf(`
125+
resource "scaleway_object_bucket" "main" {
126+
name = "%s"
127+
region = "%s"
128+
}
129+
130+
resource "scaleway_object" "file" {
131+
bucket = scaleway_object_bucket.main.id
132+
key = "index.html"
133+
file = "testfixture/index.html"
134+
visibility = "public-read"
135+
content_type = "text/html"
136+
}
137+
138+
`, bucketName, objectTestsMainRegion),
139+
Check: resource.ComposeTestCheckFunc(
140+
objectchecks.CheckBucketExists(tt, "scaleway_object_bucket.main", true),
141+
testAccCheckObjectExists(tt, "scaleway_object.file"),
142+
resource.TestCheckResourceAttr("scaleway_object.file", "content_type", "text/html"),
143+
),
144+
},
145+
},
146+
})
147+
}
148+
110149
func TestAccObject_Hash(t *testing.T) {
111150
tt := acctest.NewTestTools(t)
112151
defer tt.Cleanup()
@@ -161,7 +200,6 @@ func TestAccObject_Hash(t *testing.T) {
161200
`, bucketName, objectTestsMainRegion),
162201
Check: resource.ComposeTestCheckFunc(
163202
objectchecks.CheckBucketExists(tt, "scaleway_object_bucket.base-01", true),
164-
testAccCheckObjectExists(tt, "scaleway_object.file"),
165203
),
166204
},
167205
},

0 commit comments

Comments
 (0)