@@ -1403,13 +1403,14 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf
1403
1403
request := s3.DeleteBucketWebsiteInput {
1404
1404
Bucket : aws .String (bucket ),
1405
1405
}
1406
- response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCosClientNew (cdcId ).DeleteBucketWebsite (& request )
1407
1406
1407
+ response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCosClientNew (cdcId ).DeleteBucketWebsite (& request )
1408
1408
if err != nil {
1409
1409
log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
1410
1410
logId , "delete bucket website" , request .String (), err .Error ())
1411
1411
return fmt .Errorf ("cos delete bucket website error: %s, bucket: %s" , err .Error (), bucket )
1412
1412
}
1413
+
1413
1414
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
1414
1415
logId , "delete bucket website" , request .String (), response .String ())
1415
1416
} else {
@@ -1423,40 +1424,41 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf
1423
1424
} else {
1424
1425
w = make (map [string ]interface {})
1425
1426
}
1426
- var indexDocument , errorDocument string
1427
+
1428
+ websiteConfiguration := & s3.WebsiteConfiguration {}
1429
+ endPointUrl := fmt .Sprintf ("%s.cos-website.%s.myqcloud.com" , d .Id (), meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().Region )
1427
1430
var redirectAllRequestsTo = "http"
1428
- if v , ok := w ["index_document" ]; ok {
1429
- indexDocument = v .(string )
1431
+ if v , ok := w ["index_document" ].(string ); ok && v != "" {
1432
+ websiteConfiguration .IndexDocument = & s3.IndexDocument {
1433
+ Suffix : aws .String (v ),
1434
+ }
1430
1435
}
1431
- if v , ok := w ["error_document" ]; ok {
1432
- errorDocument = v .(string )
1436
+
1437
+ if v , ok := w ["error_document" ].(string ); ok && v != "" {
1438
+ websiteConfiguration .ErrorDocument = & s3.ErrorDocument {
1439
+ Key : aws .String (v ),
1440
+ }
1433
1441
}
1434
- if v , ok := w ["redirect_all_requests_to" ]; ok && v != "" {
1435
- redirectAllRequestsTo = v .(string )
1442
+
1443
+ if v , ok := w ["redirect_all_requests_to" ].(string ); ok && v != "" {
1444
+ websiteConfiguration .RedirectAllRequestsTo = & s3.RedirectAllRequestsTo {
1445
+ HostName : aws .String (endPointUrl ),
1446
+ Protocol : aws .String (redirectAllRequestsTo ),
1447
+ }
1436
1448
}
1437
- endPointUrl := fmt . Sprintf ( "%s.cos-website.%s.myqcloud.com" , d . Id (), meta .(tccommon. ProviderMeta ). GetAPIV3Conn (). Region )
1449
+
1438
1450
request := s3.PutBucketWebsiteInput {
1439
- Bucket : aws .String (bucket ),
1440
- WebsiteConfiguration : & s3.WebsiteConfiguration {
1441
- IndexDocument : & s3.IndexDocument {
1442
- Suffix : aws .String (indexDocument ),
1443
- },
1444
- ErrorDocument : & s3.ErrorDocument {
1445
- Key : aws .String (errorDocument ),
1446
- },
1447
- RedirectAllRequestsTo : & s3.RedirectAllRequestsTo {
1448
- HostName : aws .String (endPointUrl ),
1449
- Protocol : aws .String (redirectAllRequestsTo ),
1450
- },
1451
- },
1451
+ Bucket : aws .String (bucket ),
1452
+ WebsiteConfiguration : websiteConfiguration ,
1452
1453
}
1453
- response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCosClientNew (cdcId ).PutBucketWebsite (& request )
1454
1454
1455
+ response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCosClientNew (cdcId ).PutBucketWebsite (& request )
1455
1456
if err != nil {
1456
1457
log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
1457
1458
logId , "put bucket website" , request .String (), err .Error ())
1458
1459
return fmt .Errorf ("cos put bucket website error: %s, bucket: %s" , err .Error (), bucket )
1459
1460
}
1461
+
1460
1462
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
1461
1463
logId , "put bucket website" , request .String (), response .String ())
1462
1464
}
0 commit comments