Skip to content

Commit 90f726e

Browse files
authored
feat(object): require index_document for website configurations (#1565)
1 parent 6354fdd commit 90f726e

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

docs/resources/object_bucket_website_configuration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,8 @@ resource "scaleway_object_bucket_website_configuration" "main" {
6868
The following arguments are supported:
6969

7070
* `bucket` - (Required, Forces new resource) The name of the bucket.
71+
* `index_document` - (Required) The name of the index document for the website [detailed below](#index_document).
7172
* `error_document` - (Optional) The name of the error document for the website [detailed below](#error_document).
72-
* `index_document` - (Optional) The name of the index document for the website [detailed below](#index_document).
73-
74-
## error_document
75-
76-
The error_document configuration block supports the following arguments:
77-
78-
* `key` - (Required) The object key name to use when a 4XX class error occurs.
7973

8074
## index_document
8175

@@ -93,6 +87,12 @@ In addition to all above arguments, the following attribute is exported:
9387

9488
~> **Important:** Please check our concepts section to know more about the [endpoint](https://www.scaleway.com/en/docs/storage/object/concepts/#endpoint).
9589

90+
## error_document
91+
92+
The error_document configuration block supports the following arguments:
93+
94+
* `key` - (Required) The object key name to use when a 4XX class error occurs.
95+
9696
## Import
9797

9898
Website configuration Bucket can be imported using the `{region}/{bucketName}` identifier, e.g.

scaleway/resource_object_bucket_website_configuration.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,34 @@ func ResourceBucketWebsiteConfiguration() *schema.Resource {
3737
ValidateFunc: validation.StringLenBetween(1, 63),
3838
Description: "The bucket name.",
3939
},
40-
"error_document": {
40+
"index_document": {
4141
Type: schema.TypeList,
42-
Optional: true,
42+
Required: true,
43+
MinItems: 1,
4344
MaxItems: 1,
4445
Elem: &schema.Resource{
4546
Schema: map[string]*schema.Schema{
46-
"key": {
47+
"suffix": {
4748
Type: schema.TypeString,
4849
Required: true,
4950
},
5051
},
5152
},
52-
Description: "The name of the error document for the website.",
53+
Description: "The name of the index document for the website.",
5354
},
54-
"index_document": {
55+
"error_document": {
5556
Type: schema.TypeList,
5657
Optional: true,
5758
MaxItems: 1,
5859
Elem: &schema.Resource{
5960
Schema: map[string]*schema.Schema{
60-
"suffix": {
61+
"key": {
6162
Type: schema.TypeString,
6263
Required: true,
6364
},
6465
},
6566
},
66-
Description: "The name of the index document for the website.",
67+
Description: "The name of the error document for the website.",
6768
},
6869
"website_endpoint": {
6970
Type: schema.TypeString,
@@ -87,16 +88,14 @@ func resourceBucketWebsiteConfigurationCreate(ctx context.Context, d *schema.Res
8788

8889
bucket := expandID(d.Get("bucket").(string))
8990

90-
websiteConfig := &s3.WebsiteConfiguration{}
91+
websiteConfig := &s3.WebsiteConfiguration{
92+
IndexDocument: expandBucketWebsiteConfigurationIndexDocument(d.Get("index_document").([]interface{})),
93+
}
9194

9295
if v, ok := d.GetOk("error_document"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
9396
websiteConfig.ErrorDocument = expandBucketWebsiteConfigurationErrorDocument(v.([]interface{}))
9497
}
9598

96-
if v, ok := d.GetOk("index_document"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
97-
websiteConfig.IndexDocument = expandBucketWebsiteConfigurationIndexDocument(v.([]interface{}))
98-
}
99-
10099
_, err = conn.ListObjectsWithContext(ctx, &s3.ListObjectsInput{
101100
Bucket: scw.StringPtr(bucket),
102101
})
@@ -168,15 +167,12 @@ func resourceBucketWebsiteConfigurationRead(ctx context.Context, d *schema.Resou
168167
}
169168

170169
_ = d.Set("bucket", bucket)
170+
_ = d.Set("index_document", flattenBucketWebsiteConfigurationIndexDocument(output.IndexDocument))
171171

172172
if err := d.Set("error_document", flattenBucketWebsiteConfigurationErrorDocument(output.ErrorDocument)); err != nil {
173173
return diag.FromErr(fmt.Errorf("error setting error_document: %w", err))
174174
}
175175

176-
if err := d.Set("index_document", flattenBucketWebsiteConfigurationIndexDocument(output.IndexDocument)); err != nil {
177-
return diag.FromErr(fmt.Errorf("error setting index_document: %w", err))
178-
}
179-
180176
// Add website_endpoint and website_domain as attributes
181177
websiteEndpoint, err := resourceBucketWebsiteConfigurationWebsiteEndpoint(ctx, conn, bucket, region)
182178
if err != nil {
@@ -197,16 +193,14 @@ func resourceBucketWebsiteConfigurationUpdate(ctx context.Context, d *schema.Res
197193
return diag.FromErr(err)
198194
}
199195

200-
websiteConfig := &s3.WebsiteConfiguration{}
196+
websiteConfig := &s3.WebsiteConfiguration{
197+
IndexDocument: expandBucketWebsiteConfigurationIndexDocument(d.Get("index_document").([]interface{})),
198+
}
201199

202200
if v, ok := d.GetOk("error_document"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
203201
websiteConfig.ErrorDocument = expandBucketWebsiteConfigurationErrorDocument(v.([]interface{}))
204202
}
205203

206-
if v, ok := d.GetOk("index_document"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
207-
websiteConfig.IndexDocument = expandBucketWebsiteConfigurationIndexDocument(v.([]interface{}))
208-
}
209-
210204
input := &s3.PutBucketWebsiteInput{
211205
Bucket: aws.String(bucket),
212206
WebsiteConfiguration: websiteConfig,

0 commit comments

Comments
 (0)