Skip to content

Commit c39ec93

Browse files
tongyimingmikatong
andauthored
Fix/doc example (#1999)
* update cos and emr doc * generate doc * update emr and cos example --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 0c8f568 commit c39ec93

File tree

9 files changed

+481
-375
lines changed

9 files changed

+481
-375
lines changed

examples/tencentcloud-cos/main.tf

Lines changed: 137 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,158 @@
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
}

examples/tencentcloud-cos/variables.tf

Lines changed: 0 additions & 70 deletions
This file was deleted.

examples/tencentcloud-emr/main.tf

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
data "tencentcloud_instance_types" "cvm4c8m" {
2+
exclude_sold_out=true
3+
cpu_core_count=4
4+
memory_size=8
5+
filter {
6+
name = "instance-charge-type"
7+
values = ["POSTPAID_BY_HOUR"]
8+
}
9+
filter {
10+
name = "zone"
11+
values = [var.availability_zone]
12+
}
13+
}
14+
15+
resource "tencentcloud_vpc" "emr_vpc" {
16+
name = "emr-vpc"
17+
cidr_block = "10.0.0.0/16"
18+
}
19+
20+
resource "tencentcloud_subnet" "emr_subnet" {
21+
availability_zone = var.availability_zone
22+
name = "emr-subnets"
23+
vpc_id = tencentcloud_vpc.emr_vpc.id
24+
cidr_block = "10.0.20.0/28"
25+
is_multicast = false
26+
}
27+
28+
resource "tencentcloud_security_group" "emr_sg" {
29+
name = "emr-sg"
30+
description = "emr sg"
31+
project_id = 0
32+
}
33+
34+
resource "tencentcloud_emr_cluster" "emr_cluster" {
35+
product_id=4
36+
display_strategy="clusterList"
37+
vpc_settings={
38+
vpc_id=tencentcloud_vpc.emr_vpc.id
39+
subnet_id=tencentcloud_subnet.emr_subnet.id
40+
}
41+
softwares=[
42+
"zookeeper-3.6.1",
43+
]
44+
support_ha=0
45+
instance_name="emr-cluster-test"
46+
resource_spec {
47+
master_resource_spec {
48+
mem_size=8192
49+
cpu=4
50+
disk_size=100
51+
disk_type="CLOUD_PREMIUM"
52+
spec="CVM.${data.tencentcloud_instance_types.cvm4c8m.instance_types.0.family}"
53+
storage_type=5
54+
root_size=50
55+
}
56+
core_resource_spec {
57+
mem_size=8192
58+
cpu=4
59+
disk_size=100
60+
disk_type="CLOUD_PREMIUM"
61+
spec="CVM.${data.tencentcloud_instance_types.cvm4c8m.instance_types.0.family}"
62+
storage_type=5
63+
root_size=50
64+
}
65+
master_count=1
66+
core_count=2
67+
}
68+
login_settings={
69+
password="Tencent@cloud123"
70+
}
71+
time_span=3600
72+
time_unit="s"
73+
pay_mode=0
74+
placement={
75+
zone=var.availability_zone
76+
project_id=0
77+
}
78+
sg_id=tencentcloud_security_group.emr_sg.id
79+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "availability_zone" {
2+
default = "ap-guangzhou-3"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}

0 commit comments

Comments
 (0)