1- resource "tencentcloud_cos_bucket" "bucket" {
2- bucket = var. bucket-name
3- acl = var. acl
1+ data "tencentcloud_user_info" "info" {}
42
5- cors_rules {
6- allowed_headers = [" *" ]
7- allowed_methods = [" GET" , " POST" ]
8- allowed_origins = [" https://www.test.com" ]
9- expose_headers = [" x-cos-test" ]
10- max_age_seconds = 300
11- }
3+ locals {
4+ app_id = data. tencentcloud_user_info . info . app_id
5+ uin = data. tencentcloud_user_info . info . uin
6+ owner_uin = data. tencentcloud_user_info . info . owner_uin
7+ region = " ap-guangzhou"
8+ }
129
13- lifecycle_rules {
14- filter_prefix = " test/"
10+ # Private Bucket
11+ resource "tencentcloud_cos_bucket" "private_sbucket" {
12+ bucket = " private-bucket-${ local . app_id } "
13+ acl = " private"
14+ }
1515
16- expiration {
17- days = 365
18- }
16+ # Multiple available zone bucket
17+ resource "tencentcloud_cos_bucket" "multi_zone_bucket" {
18+ bucket = " multi-zone-bucket-${ local . app_id } "
19+ acl = " private"
20+ multi_az = true
21+ versioning_enable = true
22+ force_clean = true
23+ }
1924
20- transition {
21- days = 30
22- storage_class = " STANDARD_IA"
23- }
25+ # Using verbose acl
26+ resource "tencentcloud_cos_bucket" "bucket_with_acl" {
27+ bucket = " bucketwith-acl-${ local . app_id } "
28+ # NOTE: Specify the acl_body by the priority sequence of permission and user type with the following sequence: `CanonicalUser with READ`, `CanonicalUser with WRITE`, `CanonicalUser with FULL_CONTROL`, `CanonicalUser with WRITE_ACP`, `CanonicalUser with READ_ACP`, then specify the `Group` of permissions same as `CanonicalUser`.
29+ acl_body = << EOF
30+ <AccessControlPolicy>
31+ <Owner>
32+ <ID>qcs::cam::uin/100022975249:uin/100022975249</ID>
33+ <DisplayName>qcs::cam::uin/100022975249:uin/100022975249</DisplayName>
34+ </Owner>
35+ <AccessControlList>
36+ <Grant>
37+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
38+ <URI>http://cam.qcloud.com/groups/global/AllUsers</URI>
39+ </Grantee>
40+ <Permission>READ</Permission>
41+ </Grant>
42+ <Grant>
43+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
44+ <ID>qcs::cam::uin/100022975249:uin/100022975249</ID>
45+ <DisplayName>qcs::cam::uin/100022975249:uin/100022975249</DisplayName>
46+ </Grantee>
47+ <Permission>FULL_CONTROL</Permission>
48+ </Grant>
49+ <Grant>
50+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
51+ <ID>qcs::cam::uin/100022975249:uin/100022975249</ID>
52+ <DisplayName>qcs::cam::uin/100022975249:uin/100022975249</DisplayName>
53+ </Grantee>
54+ <Permission>WRITE_ACP</Permission>
55+ </Grant>
56+ <Grant>
57+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
58+ <URI>http://cam.qcloud.com/groups/global/AllUsers</URI>
59+ </Grantee>
60+ <Permission>READ_ACP</Permission>
61+ </Grant>
62+ <Grant>
63+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
64+ <URI>http://cam.qcloud.com/groups/global/AllUsers</URI>
65+ </Grantee>
66+ <Permission>WRITE_ACP</Permission>
67+ </Grant>
68+ <Grant>
69+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
70+ <ID>qcs::cam::uin/100022975249:uin/100022975249</ID>
71+ <DisplayName>qcs::cam::uin/100022975249:uin/100022975249</DisplayName>
72+ </Grantee>
73+ <Permission>READ</Permission>
74+ </Grant>
75+ <Grant>
76+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
77+ <ID>qcs::cam::uin/100022975249:uin/100022975249</ID>
78+ <DisplayName>qcs::cam::uin/100022975249:uin/100022975249</DisplayName>
79+ </Grantee>
80+ <Permission>WRITE</Permission>
81+ </Grant>
82+ <Grant>
83+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
84+ <URI>http://cam.qcloud.com/groups/global/AllUsers</URI>
85+ </Grantee>
86+ <Permission>FULL_CONTROL</Permission>
87+ </Grant>
88+ </AccessControlList>
89+ </AccessControlPolicy>
90+ EOF
91+ }
2492
25- transition {
26- days = 60
27- storage_class = " ARCHIVE"
28- }
29- }
93+ # Static Website
94+ resource "tencentcloud_cos_bucket" "bucket_with_static_website" {
95+ bucket = " bucket-with-static-website-${ local . app_id } "
3096
3197 website {
3298 index_document = " index.html"
3399 error_document = " error.html"
34100 }
35-
36- tags = {
37- " test" = " test"
38- }
39101}
40102
41- resource "tencentcloud_cos_bucket_object" "object" {
42- bucket = tencentcloud_cos_bucket. bucket . bucket
43- key = var. object-name
44- content = var. object-content
45- content_type = " binary/octet-stream"
103+ output "endpoint_test" {
104+ value = tencentcloud_cos_bucket. bucket_with_static_website . website . 0 . endpoint
46105}
47106
48- data "tencentcloud_cos_bucket_object" "data_object" {
49- bucket = tencentcloud_cos_bucket. bucket . id
50- key = tencentcloud_cos_bucket_object. object . key
107+ # Using CORS
108+ resource "tencentcloud_cos_bucket" "bucket_with_cors" {
109+ bucket = " bucket-with-cors-${ local . app_id } "
110+ acl = " public-read-write"
111+
112+ cors_rules {
113+ allowed_origins = [" http://*.abc.com" ]
114+ allowed_methods = [" PUT" , " POST" ]
115+ allowed_headers = [" *" ]
116+ max_age_seconds = 300
117+ expose_headers = [" Etag" ]
118+ }
51119}
52120
53- data "tencentcloud_cos_buckets" "data_bucket" {
54- bucket_prefix = tencentcloud_cos_bucket. bucket . id
55- tags = tencentcloud_cos_bucket. bucket . tags
121+ # Using object lifecycle
122+ resource "tencentcloud_cos_bucket" "bucket_with_lifecycle" {
123+ bucket = " bucket-with-lifecycle-${ local . app_id } "
124+ acl = " public-read-write"
125+
126+ lifecycle_rules {
127+ filter_prefix = " path1/"
128+
129+ transition {
130+ days = 30
131+ storage_class = " STANDARD_IA"
132+ }
133+
134+ expiration {
135+ days = 90
136+ }
137+ }
56138}
57139
58- resource "tencentcloud_cos_bucket_policy" "cos_policy" {
59- bucket = " mycos-1258798060"
60- policy = var. policy
140+ # Using replication
141+ resource "tencentcloud_cos_bucket" "bucket_replicate" {
142+ bucket = " bucket-replicate-${ local . app_id } "
143+ acl = " private"
144+ versioning_enable = true
61145}
62146
63- resource "tencentcloud_cos_buckets" "verbose_acl_bucket" {
64- bucket_prefix = " mycos-1258798060"
65- acl_body = var. acl_body
147+ resource "tencentcloud_cos_bucket" "bucket_with_replication" {
148+ bucket = " bucket-with-replication-${ local . app_id } "
149+ acl = " private"
150+ versioning_enable = true
151+ replica_role = " qcs::cam::uin/${ local . owner_uin } :uin/${ local . uin } "
152+ replica_rules {
153+ id = " test-rep1"
154+ status = " Enabled"
155+ prefix = " dist"
156+ destination_bucket = " qcs::cos:${ local . region } ::${ tencentcloud_cos_bucket . bucket_replicate . bucket } "
157+ }
66158}
0 commit comments