@@ -125,12 +125,10 @@ resource "tencentcloud_cos_bucket" "with_origin" {
125
125
protocol = "FOLLOW" // "HTTP" "HTTPS"
126
126
follow_query_string = true
127
127
follow_redirection = true
128
- follow_http_headers = ["Origin ", "Host "]
128
+ follow_http_headers = ["origin ", "host "]
129
129
custom_http_headers = {
130
- "X-Custom-Header " = "custom_value"
130
+ "x-custom-header " = "custom_value"
131
131
}
132
- redirect_prefix = "prefix"
133
- redirect_suffix = ".jpg"
134
132
}
135
133
}
136
134
```
@@ -241,7 +239,7 @@ func originPullRules() *schema.Resource {
241
239
Type : schema .TypeBool ,
242
240
Optional : true ,
243
241
Default : false ,
244
- Description : "If `true`, COS will not return 3XX status code when pulling data from an origin server. Currently available zone: ap-beijing, ap-shanghai, ap-singapore, ap-mumbai." ,
242
+ Description : "If `true`, COS will not return 3XX status code when pulling data from an origin server. Current available zone: ap-beijing, ap-shanghai, ap-singapore, ap-mumbai." ,
245
243
},
246
244
"prefix" : {
247
245
Type : schema .TypeString ,
@@ -253,7 +251,7 @@ func originPullRules() *schema.Resource {
253
251
Type : schema .TypeString ,
254
252
Optional : true ,
255
253
Default : "" ,
256
- Description : "the protocol used for COS to access the specified origin server. The available value include `HTTP`, `HTTPS` and `FOLLOW`" ,
254
+ Description : "the protocol used for COS to access the specified origin server. The available value include `HTTP`, `HTTPS` and `FOLLOW`. " ,
257
255
},
258
256
"host" : {
259
257
Type : schema .TypeString ,
@@ -270,7 +268,7 @@ func originPullRules() *schema.Resource {
270
268
Type : schema .TypeBool ,
271
269
Optional : true ,
272
270
Default : true ,
273
- Description : "Specifies whether to follow 3XX redirect to another origin server to pull data from" ,
271
+ Description : "Specifies whether to follow 3XX redirect to another origin server to pull data from. " ,
274
272
},
275
273
//"copy_origin_data": {
276
274
// Type: schema.TypeBool,
@@ -289,16 +287,16 @@ func originPullRules() *schema.Resource {
289
287
Optional : true ,
290
288
Description : "Specifies the custom headers that you can add for COS to access your origin server." ,
291
289
},
292
- "redirect_prefix" : {
293
- Type : schema .TypeString ,
294
- Optional : true ,
295
- Description : "Prefix for the file to which a request is redirected when the origin-pull rule is triggered." ,
296
- },
297
- "redirect_suffix" : {
298
- Type : schema .TypeString ,
299
- Optional : true ,
300
- Description : "Suffix for the file to which a request is redirected when the origin-pull rule is triggered." ,
301
- },
290
+ // "redirect_prefix": {
291
+ // Type: schema.TypeString,
292
+ // Optional: true,
293
+ // Description: "Prefix for the file to which a request is redirected when the origin-pull rule is triggered.",
294
+ // },
295
+ // "redirect_suffix": {
296
+ // Type: schema.TypeString,
297
+ // Optional: true,
298
+ // Description: "Suffix for the file to which a request is redirected when the origin-pull rule is triggered.",
299
+ // },
302
300
},
303
301
}
304
302
}
@@ -373,7 +371,7 @@ func resourceTencentCloudCosBucket() *schema.Resource {
373
371
"acl_body" : {
374
372
Type : schema .TypeString ,
375
373
Optional : true ,
376
- Description : "ACL XML body for multiple grant info" ,
374
+ Description : "ACL XML body for multiple grant info. " ,
377
375
},
378
376
"encryption_algorithm" : {
379
377
Type : schema .TypeString ,
@@ -445,7 +443,7 @@ func resourceTencentCloudCosBucket() *schema.Resource {
445
443
Type : schema .TypeString ,
446
444
Optional : true ,
447
445
Default : "REST" ,
448
- Description : "Specify origin domain type. Available values: `REST` , `WEBSITE`, `ACCELERATE`. Default : `REST`" ,
446
+ Description : "Specify origin domain type, available values: `REST`, `WEBSITE`, `ACCELERATE`, default : `REST`. " ,
449
447
},
450
448
"status" : {
451
449
Type : schema .TypeString ,
@@ -649,15 +647,6 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
649
647
_ = d .Set ("bucket" , d .Id ())
650
648
}
651
649
652
- acl , err := cosService .GetBucketACLXML (ctx , bucket )
653
- if err != nil {
654
- return err
655
- }
656
-
657
- if err = d .Set ("acl_body" , acl ); err != nil {
658
- return fmt .Errorf ("setting acl_body error: %v" , err )
659
- }
660
-
661
650
if err != nil {
662
651
return err
663
652
}
@@ -679,8 +668,13 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
679
668
return fmt .Errorf ("setting origin_pull_rules error: %v" , err )
680
669
}
681
670
682
- originDomainRules , _ := cosService .GetBucketOriginDomain (ctx , bucket )
683
- log .Printf ("--+-----*-*-*-originDomainRules, %s" , originDomainRules )
671
+ originDomainRules , err := cosService .GetBucketOriginDomain (ctx , bucket )
672
+ if err != nil {
673
+ return err
674
+ }
675
+ if err = d .Set ("origin_domain_rules" , originDomainRules ); err != nil {
676
+ return fmt .Errorf ("setting origin_domain_rules error: %v" , err )
677
+ }
684
678
685
679
// read the lifecycle
686
680
lifecycleRules , err := cosService .GetBucketLifecycle (ctx , bucket )
@@ -975,27 +969,6 @@ func resourceTencentCloudCosBucketAclUpdate(ctx context.Context, client *s3.S3,
975
969
return nil
976
970
}
977
971
978
- func resourceTencentCloudCosBucketAclHeaderUpdate (ctx context.Context , client * s3.S3 , d * schema.ResourceData ) error {
979
- logId := getLogId (ctx )
980
-
981
- bucket := d .Get ("bucket" ).(string )
982
- acl := d .Get ("acl" ).(string )
983
- request := s3.PutBucketAclInput {
984
- Bucket : aws .String (bucket ),
985
- ACL : aws .String (acl ),
986
- }
987
- response , err := client .PutBucketAcl (& request )
988
- if err != nil {
989
- log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
990
- logId , "put bucket acl" , request .String (), err .Error ())
991
- return fmt .Errorf ("cos put bucket error: %s, bucket: %s" , err .Error (), bucket )
992
- }
993
- log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
994
- logId , "put bucket acl" , request .String (), response .String ())
995
-
996
- return nil
997
- }
998
-
999
972
func resourceTencentCloudCosBucketCorsUpdate (ctx context.Context , client * s3.S3 , d * schema.ResourceData ) error {
1000
973
logId := getLogId (ctx )
1001
974
@@ -1271,15 +1244,20 @@ func resourceTencentCloudCosBucketLogStatusUpdate(ctx context.Context, client *s
1271
1244
}
1272
1245
1273
1246
func resourceTencentCloudCosBucketOriginACLBodyUpdate (ctx context.Context , service CosService , d * schema.ResourceData ) error {
1274
- var body string
1275
- v , ok := d .GetOk ("acl_body" )
1247
+ aclHeader := ""
1248
+ aclBody := ""
1249
+ body , bodyOk := d .GetOk ("acl_body" )
1250
+ header , headerOk := d .GetOk ("acl" )
1276
1251
bucket := d .Get ("bucket" ).(string )
1277
- if ! ok {
1278
- body = ""
1252
+ // If ACLXML update to empty, this will pass default header to delete verbose acl info
1253
+ if bodyOk {
1254
+ aclBody = body .(string )
1255
+ } else if headerOk {
1256
+ aclHeader = header .(string )
1279
1257
} else {
1280
- body = v .( string )
1258
+ aclHeader = "private"
1281
1259
}
1282
- if err := service .TencentCosPutBucketACL (ctx , bucket , body ); err != nil {
1260
+ if err := service .TencentCosPutBucketACL (ctx , bucket , aclBody , aclHeader ); err != nil {
1283
1261
return err
1284
1262
}
1285
1263
return nil
@@ -1345,19 +1323,27 @@ func resourceTencentCloudCosBucketOriginPullUpdate(ctx context.Context, service
1345
1323
// item.OriginParameter.CopyOriginData = v.(bool)
1346
1324
//}
1347
1325
if v , ok := dMap ["redirect_prefix" ]; ok {
1348
- item .OriginInfo .FileInfo .Prefix = v .(string )
1326
+ value := v .(string )
1327
+ if value != "" {
1328
+ item .OriginInfo .FileInfo .PrefixDirective = true
1329
+ }
1330
+ item .OriginInfo .FileInfo .Prefix = value
1349
1331
}
1350
1332
if v , ok := dMap ["redirect_suffix" ]; ok {
1351
- item .OriginInfo .FileInfo .Suffix = v .(string )
1333
+ value := v .(string )
1334
+ if value != "" {
1335
+ item .OriginInfo .FileInfo .PrefixDirective = true
1336
+ }
1337
+ item .OriginInfo .FileInfo .Suffix = value
1352
1338
}
1353
1339
if v , ok := dMap ["custom_http_headers" ]; ok {
1354
1340
var customHeaders []cos.OriginHttpHeader
1355
- header := cos.OriginHttpHeader {}
1356
1341
for key , val := range v .(map [string ]interface {}) {
1357
- header .Key = key
1358
- header .Value = val .(string )
1342
+ customHeaders = append (customHeaders , cos.OriginHttpHeader {
1343
+ Key : key ,
1344
+ Value : val .(string ),
1345
+ })
1359
1346
}
1360
- customHeaders = append (customHeaders , header )
1361
1347
item .OriginParameter .HttpHeader .NewHttpHeaders = customHeaders
1362
1348
}
1363
1349
if v , ok := dMap ["follow_http_headers" ]; ok {
@@ -1385,23 +1371,26 @@ func resourceTencentCloudCosBucketOriginDomainUpdate(ctx context.Context, servic
1385
1371
v , ok := d .GetOk ("origin_domain_rules" )
1386
1372
bucket := d .Get ("bucket" ).(string )
1387
1373
if ! ok {
1374
+ if err := service .DeleteBucketOriginDomain (ctx , bucket ); err != nil {
1375
+ return err
1376
+ }
1388
1377
return nil
1389
1378
}
1390
- rules := v .([]map [ string ] interface {})
1379
+ rules := v .([]interface {})
1391
1380
domainRules := make ([]cos.BucketDomainRule , 0 )
1392
1381
1393
1382
for _ , rule := range rules {
1383
+ dMap := rule .(map [string ]interface {})
1394
1384
item := cos.BucketDomainRule {}
1395
- if name , ok := rule ["domain" ]; ok {
1385
+ if name , ok := dMap ["domain" ]; ok {
1396
1386
item .Name = name .(string )
1397
1387
}
1398
- if status , ok := rule ["status" ]; ok {
1388
+ if status , ok := dMap ["status" ]; ok {
1399
1389
item .Status = status .(string )
1400
1390
}
1401
- if domainType , ok := rule ["type" ]; ok {
1391
+ if domainType , ok := dMap ["type" ]; ok {
1402
1392
item .Type = domainType .(string )
1403
1393
}
1404
-
1405
1394
domainRules = append (domainRules , item )
1406
1395
}
1407
1396
0 commit comments