@@ -241,8 +241,10 @@ package tencentcloud
241241import (
242242 "bytes"
243243 "context"
244+ "encoding/json"
244245 "encoding/xml"
245246 "fmt"
247+ "io/ioutil"
246248 "log"
247249 "reflect"
248250 "time"
@@ -434,6 +436,12 @@ func resourceTencentCloudCosBucket() *schema.Resource {
434436 Default : false ,
435437 Description : "Enable bucket versioning." ,
436438 },
439+ "acceleration_enable" : {
440+ Type : schema .TypeBool ,
441+ Optional : true ,
442+ Default : false ,
443+ Description : "Enable bucket acceleration." ,
444+ },
437445 "force_clean" : {
438446 Type : schema .TypeBool ,
439447 Optional : true ,
@@ -905,6 +913,15 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
905913 return fmt .Errorf ("setting versioning_enable error: %v" , err )
906914 }
907915
916+ // read the acceleration
917+ acceleration , err := cosService .GetBucketAccleration (ctx , bucket )
918+ if err != nil {
919+ return err
920+ }
921+ if err = d .Set ("acceleration_enable" , acceleration ); err != nil {
922+ return fmt .Errorf ("setting acceleration_enable error: %v" , err )
923+ }
924+
908925 replicaResult , err := cosService .GetBucketReplication (ctx , bucket )
909926 if err != nil {
910927 return err
@@ -950,6 +967,7 @@ func resourceTencentCloudCosBucketUpdate(d *schema.ResourceData, meta interface{
950967 ctx := context .WithValue (context .TODO (), logIdKey , logId )
951968
952969 client := meta .(* TencentCloudClient ).apiV3Conn .UseCosClient ()
970+ tcClient := meta .(* TencentCloudClient ).apiV3Conn .UseTencentCosClient (d .Id ())
953971 cosService := CosService {client : meta .(* TencentCloudClient ).apiV3Conn }
954972
955973 d .Partial (true )
@@ -1027,6 +1045,14 @@ func resourceTencentCloudCosBucketUpdate(d *schema.ResourceData, meta interface{
10271045 d .SetPartial ("versioning_enable" )
10281046 }
10291047
1048+ if d .HasChange ("acceleration_enable" ) {
1049+ err := resourceTencentCloudCosBucketAccelerationUpdate (ctx , tcClient , d )
1050+ if err != nil {
1051+ return err
1052+ }
1053+ d .SetPartial ("acceleration_enable" )
1054+ }
1055+
10301056 if d .HasChange ("replica_role" ) || d .HasChange ("replica_rules" ) {
10311057 err := resourceTencentCloudCosBucketReplicaUpdate (ctx , cosService , d )
10321058
@@ -1163,6 +1189,33 @@ func resourceTencentCloudCosBucketVersioningUpdate(ctx context.Context, client *
11631189 return nil
11641190}
11651191
1192+ func resourceTencentCloudCosBucketAccelerationUpdate (ctx context.Context , client * cos.Client , d * schema.ResourceData ) error {
1193+ logId := getLogId (ctx )
1194+
1195+ bucket := d .Get ("bucket" ).(string )
1196+ enabled := d .Get ("acceleration_enable" ).(bool )
1197+ status := "Suspended"
1198+ if enabled {
1199+ status = "Enabled"
1200+ }
1201+
1202+ opt := & cos.BucketPutAccelerateOptions {
1203+ Status : status ,
1204+ }
1205+ response , err := client .Bucket .PutAccelerate (ctx , opt )
1206+ if err != nil {
1207+ log .Printf ("[CRITAL]%s api[%s] fail, status [%s], reason[%s]\n " ,
1208+ logId , "put bucket acceleration" , opt .Status , err .Error ())
1209+ return fmt .Errorf ("cos put bucket acceleration error: %s, bucket: %s" , err .Error (), bucket )
1210+ }
1211+ rb , _ := ioutil .ReadAll (response .Body )
1212+ body , _ := json .Marshal (rb )
1213+ log .Printf ("[DEBUG]%s api[%s] success, status [%s], response body [%s]\n " ,
1214+ logId , "put bucket acceleration" , opt .Status , string (body ))
1215+
1216+ return err
1217+ }
1218+
11661219func resourceTencentCloudCosBucketReplicaUpdate (ctx context.Context , service CosService , d * schema.ResourceData ) error {
11671220 bucket := d .Get ("bucket" ).(string )
11681221 oldRole , newRole := d .GetChange ("replica_role" )
0 commit comments