@@ -1403,13 +1403,14 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf
14031403 request := s3.DeleteBucketWebsiteInput {
14041404 Bucket : aws .String (bucket ),
14051405 }
1406- response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCosClientNew (cdcId ).DeleteBucketWebsite (& request )
14071406
1407+ response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCosClientNew (cdcId ).DeleteBucketWebsite (& request )
14081408 if err != nil {
14091409 log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
14101410 logId , "delete bucket website" , request .String (), err .Error ())
14111411 return fmt .Errorf ("cos delete bucket website error: %s, bucket: %s" , err .Error (), bucket )
14121412 }
1413+
14131414 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
14141415 logId , "delete bucket website" , request .String (), response .String ())
14151416 } else {
@@ -1423,40 +1424,41 @@ func resourceTencentCloudCosBucketWebsiteUpdate(ctx context.Context, meta interf
14231424 } else {
14241425 w = make (map [string ]interface {})
14251426 }
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 )
14271430 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+ }
14301435 }
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+ }
14331441 }
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+ }
14361448 }
1437- endPointUrl := fmt . Sprintf ( "%s.cos-website.%s.myqcloud.com" , d . Id (), meta .(tccommon. ProviderMeta ). GetAPIV3Conn (). Region )
1449+
14381450 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 ,
14521453 }
1453- response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCosClientNew (cdcId ).PutBucketWebsite (& request )
14541454
1455+ response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCosClientNew (cdcId ).PutBucketWebsite (& request )
14551456 if err != nil {
14561457 log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
14571458 logId , "put bucket website" , request .String (), err .Error ())
14581459 return fmt .Errorf ("cos put bucket website error: %s, bucket: %s" , err .Error (), bucket )
14591460 }
1461+
14601462 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
14611463 logId , "put bucket website" , request .String (), response .String ())
14621464 }
0 commit comments