Skip to content

Commit 0098f3b

Browse files
authored
Merge pull request #478 from brickzzhang/master
[new mongodb SDK and standby instance]
2 parents af2e54b + 07d60d4 commit 0098f3b

26 files changed

+4104
-1881
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
## 1.39.1 (Unreleased)
1+
## 1.40.0 (Unreleased)
2+
3+
FEATURES:
4+
5+
* **New Resource**: `tencentcloud_mongodb_standby_instance`
26

37
ENHANCEMENTS:
48

59
* Resource: `tencentcloud_gaap_http_rule` argument `realservers` now is optional.
610
* Resource: `tencentcloud_kubernetes_cluster` supports multiple `availability_zone`.
11+
* Data Source: `tencentcloud_mongodb_instances` add new argument `charge_type` and `auto_renew_flag` to support prepaid type.
12+
* Resource: `tencentcloud_mongodb_instance` supports prepaid type, new mongodb SDK version `2019-07-25` and standby instance.
13+
* Resource: `tencentcloud_mongodb_sharding_instance` supports prepaid type, new mongodb SDK version `2019-07-25` and standby instance.
714

815

916
## 1.39.0 (July 18, 2020)

examples/tencentcloud-mongodb/main.tf

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1+
provider "tencentcloud" {
2+
region = "ap-guangzhou"
3+
}
4+
5+
provider "tencentcloud" {
6+
alias = "shanghai"
7+
region = "ap-shanghai"
8+
}
9+
110
resource "tencentcloud_mongodb_instance" "mongodb" {
211
instance_name = "tf-mongodb-test"
312
memory = 4
413
volume = 100
5-
engine_version = "MONGO_36_WT"
6-
machine_type = "GIO"
14+
engine_version = "MONGO_40_WT"
15+
machine_type = "HIO10G"
716
available_zone = var.availability_zone
817
project_id = 0
918
password = "test1234"
1019

1120
tags = {
12-
"test" = "test"
21+
test = "test"
1322
}
1423
}
1524

@@ -26,14 +35,31 @@ resource "tencentcloud_mongodb_sharding_instance" "mongodb_sharding" {
2635
password = "test1234"
2736

2837
tags = {
29-
"test" = "test"
38+
test = "test"
3039
}
3140
}
3241

3342
data "tencentcloud_mongodb_instances" "mongodb_instances" {
3443
instance_id = tencentcloud_mongodb_instance.mongodb.id
3544

3645
tags = {
37-
"test" = "test"
46+
test = "test"
3847
}
3948
}
49+
50+
resource "tencentcloud_mongodb_standby_instance" "mongodb" {
51+
provider = tencentcloud.shanghai
52+
instance_name = "tf-mongodb-standby-test"
53+
memory = 4
54+
volume = 100
55+
available_zone = "ap-shanghai-2"
56+
project_id = 0
57+
father_instance_id = tencentcloud_mongodb_instance.mongodb.id
58+
father_instance_region = "ap-guangzhou"
59+
charge_type = "PREPAID"
60+
prepaid_period = 1
61+
62+
tags = {
63+
test = "test"
64+
}
65+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/mattn/go-colorable v0.1.6 // indirect
1616
github.com/mitchellh/go-homedir v1.1.0
1717
github.com/pkg/errors v0.9.1
18-
github.com/tencentcloud/tencentcloud-sdk-go v3.0.196+incompatible
18+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.217+incompatible
1919
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
2020
github.com/zclconf/go-cty v1.4.2 // indirect
2121
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0K
460460
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
461461
github.com/tencentcloud/tencentcloud-sdk-go v3.0.196+incompatible h1:aKWXYPLQ9NARP0tBESEtTfRLes88LaI+4qm3TSRDCjk=
462462
github.com/tencentcloud/tencentcloud-sdk-go v3.0.196+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
463+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.215+incompatible h1:QsJWTxBNUjZjST5ehuyeaU/4YLQ3vwyTy6fI4LJ7pts=
464+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.215+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
465+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.217+incompatible h1:c0N5XTxnRv3e6lgIEw3Ml0RdIV0fA8qDRuVEhQnDViE=
466+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.217+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
463467
github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8=
464468
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
465469
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=

tencentcloud/connectivity/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
dc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc/v20180410"
2323
es "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es/v20180416"
2424
gaap "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529"
25-
mongodb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb/v20180408"
25+
mongodb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb/v20190725"
2626
monitor "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor/v20180724"
2727
postgre "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"
2828
redis "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis/v20180412"

tencentcloud/data_source_tc_mongodb_instances.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ func dataSourceTencentCloudMongodbInstances() *schema.Resource {
152152
Computed: true,
153153
Description: "Tags of the Mongodb instance.",
154154
},
155+
// payment
156+
"charge_type": {
157+
Type: schema.TypeString,
158+
Computed: true,
159+
Description: "The charge type of instance.",
160+
},
161+
"auto_renew_flag": {
162+
Type: schema.TypeInt,
163+
Computed: true,
164+
Description: "Auto renew flag.",
165+
},
155166
},
156167
},
157168
},
@@ -241,11 +252,11 @@ instancesLoop:
241252
}
242253

243254
switch *mongo.MachineType {
244-
case "HIO10G":
245-
*mongo.MachineType = MONGODB_MACHINE_TYPE_TGIO
255+
case MONGODB_MACHINE_TYPE_TGIO:
256+
*mongo.MachineType = MONGODB_MACHINE_TYPE_HIO10G
246257

247-
case "HIO":
248-
*mongo.MachineType = MONGODB_MACHINE_TYPE_GIO
258+
case MONGODB_MACHINE_TYPE_GIO:
259+
*mongo.MachineType = MONGODB_MACHINE_TYPE_HIO
249260
}
250261

251262
clusterType := MONGODB_CLUSTER_TYPE_REPLSET
@@ -272,6 +283,10 @@ instancesLoop:
272283
"machine_type": mongo.MachineType,
273284
"shard_quantity": mongo.ReplicationSetNum,
274285
"tags": respTags,
286+
"charge_type": MONGODB_CHARGE_TYPE[*mongo.PayMode],
287+
}
288+
if MONGODB_CHARGE_TYPE[*mongo.PayMode] == MONGODB_CHARGE_TYPE_PREPAID {
289+
_ = d.Set("auto_renew_flag", *mongo.AutoRenewFlag)
275290
}
276291
instanceList = append(instanceList, instance)
277292
ids = append(ids, *mongo.InstanceId)

tencentcloud/data_source_tc_mongodb_instances_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ func TestAccTencentCloudMongodbInstancesDataSource(t *testing.T) {
3232
resource.TestCheckResourceAttrSet("data.tencentcloud_mongodb_instances.mongodb_instances", "instance_list.0.cpu"),
3333
resource.TestCheckResourceAttr("data.tencentcloud_mongodb_instances.mongodb_instances", "instance_list.0.memory", "4"),
3434
resource.TestCheckResourceAttr("data.tencentcloud_mongodb_instances.mongodb_instances", "instance_list.0.volume", "100"),
35-
resource.TestCheckResourceAttr("data.tencentcloud_mongodb_instances.mongodb_instances", "instance_list.0.machine_type", "TGIO"),
35+
resource.TestCheckResourceAttr("data.tencentcloud_mongodb_instances.mongodb_instances", "instance_list.0.machine_type", MONGODB_MACHINE_TYPE_HIO10G),
3636
resource.TestCheckResourceAttrSet("data.tencentcloud_mongodb_instances.mongodb_instances", "instance_list.0.shard_quantity"),
3737
resource.TestCheckResourceAttr("data.tencentcloud_mongodb_instances.mongodb_instances", "instance_list.0.tags.test", "test"),
38+
resource.TestCheckResourceAttr("data.tencentcloud_mongodb_instances.mongodb_instances", "instance_list.0.charge_type", "POSTPAID"),
3839
),
3940
},
4041
},

tencentcloud/extension_mongodb.go

Lines changed: 176 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package tencentcloud
22

3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
5+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
6+
)
7+
38
const (
49
MONGODB_INSTANCE_STATUS_INITIAL = 0
510
MONGODB_INSTANCE_STATUS_PROCESSING = 1
611
MONGODB_INSTANCE_STATUS_RUNNING = 2
12+
MONGODB_INSTANCE_STATUS_EXPIRED = -2
713

814
MONGODB_ENGINE_VERSION_3_WT = "MONGO_3_WT"
915
MONGODB_ENGINE_VERSION_36_WT = "MONGO_36_WT"
1016
MONGODB_ENGINE_VERSION_3_ROCKS = "MONGO_3_ROCKS"
17+
MONGODB_ENGINE_VERSION_4_WT = "MONGO_40_WT"
1118

1219
MONGODB_MACHINE_TYPE_GIO = "GIO"
1320
MONGODB_MACHINE_TYPE_TGIO = "TGIO"
@@ -16,20 +23,179 @@ const (
1623

1724
MONGODB_CLUSTER_TYPE_REPLSET = "REPLSET"
1825
MONGODB_CLUSTER_TYPE_SHARD = "SHARD"
26+
27+
MONGO_INSTANCE_TYPE_FORMAL = 1
28+
MONGO_INSTANCE_TYPE_READONLY = 3
29+
MONGO_INSTANCE_TYPE_STANDBY = 4
1930
)
2031

21-
var MONGODB_ENGINE_VERSION = []string{
22-
MONGODB_ENGINE_VERSION_3_WT,
23-
MONGODB_ENGINE_VERSION_36_WT,
24-
MONGODB_ENGINE_VERSION_3_ROCKS,
32+
var MONGODB_CLUSTER_TYPE = []string{
33+
MONGODB_CLUSTER_TYPE_REPLSET,
34+
MONGODB_CLUSTER_TYPE_SHARD,
2535
}
2636

27-
var MONGODB_MACHINE_TYPE = []string{
28-
MONGODB_MACHINE_TYPE_GIO,
29-
MONGODB_MACHINE_TYPE_TGIO,
37+
const (
38+
MONGODB_DEFAULT_LIMIT = 20
39+
MONGODB_MAX_LIMIT = 100
40+
MONGODB_DEFAULT_OFFSET = 0
41+
)
42+
43+
const (
44+
MONGODB_CHARGE_TYPE_POSTPAID = COMMON_PAYTYPE_POSTPAID
45+
MONGODB_CHARGE_TYPE_PREPAID = COMMON_PAYTYPE_PREPAID
46+
)
47+
48+
var MONGODB_CHARGE_TYPE = map[uint64]string{
49+
0: MONGODB_CHARGE_TYPE_POSTPAID,
50+
1: MONGODB_CHARGE_TYPE_PREPAID,
3051
}
3152

32-
var MONGODB_CLUSTER_TYPE = []string{
33-
MONGODB_CLUSTER_TYPE_REPLSET,
34-
MONGODB_CLUSTER_TYPE_SHARD,
53+
var MONGODB_AUTO_RENEW_FLAG = map[int]string{
54+
0: "NOTIFY_AND_MANUAL_RENEW",
55+
1: "NOTIFY_AND_AUTO_RENEW",
56+
2: "DISABLE_NOTIFY_AND_MANUAL_RENEW",
57+
}
58+
59+
var MONGODB_PREPAID_PERIOD = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36}
60+
61+
const (
62+
MONGODB_TASK_FAILED = "failed"
63+
MONGODB_TASK_PAUSED = "paused"
64+
MONGODB_TASK_RUNNING = "running"
65+
MONGODB_TASK_SUCCESS = "success"
66+
)
67+
68+
func TencentMongodbBasicInfo() map[string]*schema.Schema {
69+
return map[string]*schema.Schema{
70+
"instance_name": {
71+
Type: schema.TypeString,
72+
Required: true,
73+
ValidateFunc: validateStringLengthInRange(2, 35),
74+
Description: "Name of the Mongodb instance.",
75+
},
76+
"memory": {
77+
Type: schema.TypeInt,
78+
Required: true,
79+
ValidateFunc: validateIntegerMin(2),
80+
Description: "Memory size. The minimum value is 2, and unit is GB. Memory and volume must be upgraded or degraded simultaneously.",
81+
},
82+
"volume": {
83+
Type: schema.TypeInt,
84+
Required: true,
85+
ValidateFunc: validateIntegerMin(25),
86+
Description: "Disk size. The minimum value is 25, and unit is GB. Memory and volume must be upgraded or degraded simultaneously.",
87+
},
88+
"engine_version": {
89+
Type: schema.TypeString,
90+
Required: true,
91+
ForceNew: true,
92+
Description: "Version of the Mongodb, and available values include `MONGO_3_WT`, `MONGO_3_ROCKS`, `MONGO_36_WT` and `MONGO_40_WT`.",
93+
},
94+
"machine_type": {
95+
Type: schema.TypeString,
96+
Required: true,
97+
ForceNew: true,
98+
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
99+
if (olds == MONGODB_MACHINE_TYPE_GIO && news == MONGODB_MACHINE_TYPE_HIO) ||
100+
(olds == MONGODB_MACHINE_TYPE_HIO && news == MONGODB_MACHINE_TYPE_GIO) {
101+
return true
102+
} else if (olds == MONGODB_MACHINE_TYPE_TGIO && news == MONGODB_MACHINE_TYPE_HIO10G) ||
103+
(olds == MONGODB_MACHINE_TYPE_HIO10G && news == MONGODB_MACHINE_TYPE_TGIO) {
104+
return true
105+
}
106+
return olds == news
107+
},
108+
Description: "Type of Mongodb instance, and available values include `HIO`(or `GIO` which will be deprecated) and `HIO10G`(or `TGIO` which will be deprecated).",
109+
},
110+
"available_zone": {
111+
Type: schema.TypeString,
112+
Required: true,
113+
ForceNew: true,
114+
Description: "The available zone of the Mongodb.",
115+
},
116+
"vpc_id": {
117+
Type: schema.TypeString,
118+
Optional: true,
119+
ForceNew: true,
120+
Default: "",
121+
Description: "ID of the VPC.",
122+
},
123+
"subnet_id": {
124+
Type: schema.TypeString,
125+
Optional: true,
126+
ForceNew: true,
127+
Description: "ID of the subnet within this VPC. The value is required if `vpc_id` is set.",
128+
},
129+
"project_id": {
130+
Type: schema.TypeInt,
131+
Optional: true,
132+
Default: 0,
133+
Description: "ID of the project which the instance belongs.",
134+
},
135+
"security_groups": {
136+
Type: schema.TypeSet,
137+
Optional: true,
138+
ForceNew: true,
139+
Elem: &schema.Schema{
140+
Type: schema.TypeString,
141+
},
142+
Set: func(v interface{}) int {
143+
return hashcode.String(v.(string))
144+
},
145+
Description: "ID of the security group. NOTE: for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported.",
146+
},
147+
"password": {
148+
Type: schema.TypeString,
149+
Required: true,
150+
Sensitive: true,
151+
Description: "Password of this Mongodb account.",
152+
},
153+
"tags": {
154+
Type: schema.TypeMap,
155+
Optional: true,
156+
Description: "The tags of the Mongodb.",
157+
},
158+
// payment
159+
"charge_type": {
160+
Type: schema.TypeString,
161+
Optional: true,
162+
ForceNew: true,
163+
Default: MONGODB_CHARGE_TYPE_POSTPAID,
164+
ValidateFunc: validateAllowedStringValue([]string{MONGODB_CHARGE_TYPE_POSTPAID, MONGODB_CHARGE_TYPE_PREPAID}),
165+
Description: "The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. Default value is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. Caution that update operation on this field will delete old instances and create new one with new charge type.",
166+
},
167+
"prepaid_period": {
168+
Type: schema.TypeInt,
169+
Optional: true,
170+
ValidateFunc: validateAllowedIntValue(MONGODB_PREPAID_PERIOD),
171+
Description: "The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.",
172+
},
173+
"auto_renew_flag": {
174+
Type: schema.TypeInt,
175+
Optional: true,
176+
Default: 0,
177+
Description: "Auto renew flag. Valid values are `0`(NOTIFY_AND_MANUAL_RENEW), `1`(NOTIFY_AND_AUTO_RENEW) and `2`(DISABLE_NOTIFY_AND_MANUAL_RENEW). Default value is `0`. Note: only works for PREPAID instance. Only supports`0` and `1` for creation.",
178+
},
179+
// Computed
180+
"status": {
181+
Type: schema.TypeInt,
182+
Computed: true,
183+
Description: "Status of the Mongodb instance, and available values include pending initialization(expressed with 0), processing(expressed with 1), running(expressed with 2) and expired(expressed with -2).",
184+
},
185+
"vip": {
186+
Type: schema.TypeString,
187+
Computed: true,
188+
Description: "IP of the Mongodb instance.",
189+
},
190+
"vport": {
191+
Type: schema.TypeInt,
192+
Computed: true,
193+
Description: "IP port of the Mongodb instance.",
194+
},
195+
"create_time": {
196+
Type: schema.TypeString,
197+
Computed: true,
198+
Description: "Creation time of the Mongodb instance.",
199+
},
200+
}
35201
}

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ MongoDB
257257
Resource
258258
tencentcloud_mongodb_instance
259259
tencentcloud_mongodb_sharding_instance
260+
tencentcloud_mongodb_standby_instance
260261
261262
MySQL
262263
Data Source
@@ -712,6 +713,7 @@ func Provider() terraform.ResourceProvider {
712713
"tencentcloud_monitor_binding_receiver": resourceTencentMonitorBindingAlarmReceiver(),
713714
"tencentcloud_elasticsearch_instance": resourceTencentCloudElasticsearchInstance(),
714715
"tencentcloud_postgresql_instance": resourceTencentCloudPostgresqlInstance(),
716+
"tencentcloud_mongodb_standby_instance": resourceTencentCloudMongodbStandbyInstance(),
715717
},
716718

717719
ConfigureFunc: providerConfigure,

0 commit comments

Comments
 (0)