Skip to content

Commit 8e1bcdd

Browse files
authored
Merge branch 'master' into master
2 parents 34bc34d + fdea9b3 commit 8e1bcdd

File tree

16 files changed

+3838
-26
lines changed

16 files changed

+3838
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ FEATURES:
44
* **New Resource**: `tencentcloud_postgresql_instance`
55
* **New Data Source**: `tencentcloud_postgresql_instances`
66
* **New Data Source**: `tencentcloud_postgresql_speccodes`
7+
* **New Data Source**: `tencentcloud_sqlserver_zone_config`
78

89
## 1.36.1 (June 12, 2020)
910

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
data "tencentcloud_sqlserver_zone_config" "mysqlserver" {
2+
}

examples/tencentcloud-sqlserver/variable.tf

Whitespace-only changes.
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+
}

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,10 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
454454
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
455455
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0KQWXKNqmwe8vEeSUiUj4Rlee9CMVX2ZUQ=
456456
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
457-
github.com/tencentcloud/tencentcloud-sdk-go v3.0.189+incompatible h1:eLVHwxLW2HFvr48l5sqROircYlq6Lp39EXhyCkK6Jlw=
458-
github.com/tencentcloud/tencentcloud-sdk-go v3.0.189+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
457+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.187+incompatible h1:9hr93p945INwxa67N68EUJuIkUE2iGnMq/YZ6x3JHik=
458+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.187+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
459+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.191+incompatible h1:cycv0fIQDSo9sjWkupzKnKMc+ZT8cKAfoq2WX3b8ozk=
460+
github.com/tencentcloud/tencentcloud-sdk-go v3.0.191+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
459461
github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8=
460462
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
461463
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=

tencentcloud/connectivity/client.go

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
postgre "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"
2828
redis "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis/v20180412"
2929
scf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
30+
sqlserver "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver/v20180328"
3031
sts "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts/v20180813"
3132
tag "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag/v20180813"
3233
tcaplusdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb/v20190823"
@@ -42,30 +43,31 @@ type TencentCloudClient struct {
4243
Protocol string
4344
Domain string
4445

45-
cosConn *s3.S3
46-
mysqlConn *cdb.Client
47-
redisConn *redis.Client
48-
asConn *as.Client
49-
vpcConn *vpc.Client
50-
cbsConn *cbs.Client
51-
cvmConn *cvm.Client
52-
clbConn *clb.Client
53-
dayuConn *dayu.Client
54-
dcConn *dc.Client
55-
tagConn *tag.Client
56-
mongodbConn *mongodb.Client
57-
tkeConn *tke.Client
58-
camConn *cam.Client
59-
stsConn *sts.Client
60-
gaapConn *gaap.Client
61-
sslConn *ssl.Client
62-
cfsConn *cfs.Client
63-
scfConn *scf.Client
64-
tcaplusConn *tcaplusdb.Client
65-
cdnConn *cdn.Client
66-
monitorConn *monitor.Client
67-
esConn *es.Client
68-
postgreConn *postgre.Client
46+
cosConn *s3.S3
47+
mysqlConn *cdb.Client
48+
redisConn *redis.Client
49+
asConn *as.Client
50+
vpcConn *vpc.Client
51+
cbsConn *cbs.Client
52+
cvmConn *cvm.Client
53+
clbConn *clb.Client
54+
dayuConn *dayu.Client
55+
dcConn *dc.Client
56+
tagConn *tag.Client
57+
mongodbConn *mongodb.Client
58+
tkeConn *tke.Client
59+
camConn *cam.Client
60+
stsConn *sts.Client
61+
gaapConn *gaap.Client
62+
sslConn *ssl.Client
63+
cfsConn *cfs.Client
64+
scfConn *scf.Client
65+
tcaplusConn *tcaplusdb.Client
66+
cdnConn *cdn.Client
67+
monitorConn *monitor.Client
68+
esConn *es.Client
69+
sqlserverConn *sqlserver.Client
70+
postgreConn *postgre.Client
6971
}
7072

7173
// NewClientProfile returns a new ClientProfile
@@ -413,3 +415,16 @@ func (me *TencentCloudClient) UsePostgresqlClient() *postgre.Client {
413415

414416
return me.postgreConn
415417
}
418+
419+
// UseSqlserverClient returns sqlserver client for service
420+
func (me *TencentCloudClient) UseSqlserverClient() *sqlserver.Client {
421+
if me.sqlserverConn != nil {
422+
return me.sqlserverConn
423+
}
424+
425+
cpf := me.NewClientProfile(300)
426+
me.sqlserverConn, _ = sqlserver.NewClient(me.Credential, me.Region, cpf)
427+
me.sqlserverConn.WithHttpTransport(&LogRoundTripper{})
428+
429+
return me.sqlserverConn
430+
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
Use this data source to query purchasable specification configuration for each availability zone in this specific region.
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_sqlserver_zone_config" "mysqlserver" {
8+
}
9+
```
10+
*/
11+
package tencentcloud
12+
13+
import (
14+
"context"
15+
"fmt"
16+
"log"
17+
18+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
19+
)
20+
21+
func dataSourceTencentSqlserverZoneConfig() *schema.Resource {
22+
return &schema.Resource{
23+
Read: dataSourceTencentSqlserverZoneConfigRead,
24+
Schema: map[string]*schema.Schema{
25+
"result_output_file": {
26+
Type: schema.TypeString,
27+
Optional: true,
28+
Description: "Used to store results.",
29+
},
30+
"zone_list": {
31+
Type: schema.TypeList,
32+
Computed: true,
33+
Description: "A list of availability zones. Each element contains the following attributes:",
34+
Elem: &schema.Resource{
35+
Schema: map[string]*schema.Schema{
36+
"availability_zone": {
37+
Type: schema.TypeString,
38+
Computed: true,
39+
Description: "Alphabet ID of availability zone.",
40+
},
41+
"zone_id": {
42+
Type: schema.TypeInt,
43+
Computed: true,
44+
Description: "Number ID of availability zone.",
45+
},
46+
"specinfo_list": {
47+
Type: schema.TypeList,
48+
Computed: true,
49+
Description: "A list of specinfo configurations for the specific availability zone. Each element contains the following attributes:",
50+
Elem: &schema.Resource{
51+
Schema: map[string]*schema.Schema{
52+
"spec_id": {
53+
Type: schema.TypeInt,
54+
Computed: true,
55+
Description: "Instance specification ID.",
56+
},
57+
"machine_type": {
58+
Type: schema.TypeString,
59+
Computed: true,
60+
Description: "Model ID.",
61+
},
62+
"db_version": {
63+
Type: schema.TypeString,
64+
Computed: true,
65+
Description: "Database version information. Valid values: `2008R2 (SQL Server 2008 Enterprise)`, `2012SP3 (SQL Server 2012 Enterprise)`, `2016SP1 (SQL Server 2016 Enterprise)`, `201602 (SQL Server 2016 Standard)`, `2017 (SQL Server 2017 Enterprise)`.",
66+
},
67+
"db_version_name": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
Description: "Version name corresponding to the `db_version` field.",
71+
},
72+
"memory": {
73+
Type: schema.TypeInt,
74+
Computed: true,
75+
Description: "Memory size in GB.",
76+
},
77+
"cpu": {
78+
Type: schema.TypeInt,
79+
Computed: true,
80+
Description: "Number of CPU cores.",
81+
},
82+
"min_storage_size": {
83+
Type: schema.TypeInt,
84+
Computed: true,
85+
Description: "Minimum disk size under this specification in GB.",
86+
},
87+
"max_storage_size": {
88+
Type: schema.TypeInt,
89+
Computed: true,
90+
Description: "Maximum disk size under this specification in GB.",
91+
},
92+
"qps": {
93+
Type: schema.TypeInt,
94+
Computed: true,
95+
Description: "QPS of this specification.",
96+
},
97+
"charge_type": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
Description: "Billing mode under this specification. Valid values are `POSTPAID_BY_HOUR`, `PREPAID` and `ALL` which means both POSTPAID_BY_HOUR and PREPAID.",
101+
},
102+
},
103+
},
104+
},
105+
},
106+
},
107+
},
108+
},
109+
}
110+
}
111+
112+
func dataSourceTencentSqlserverZoneConfigRead(d *schema.ResourceData, meta interface{}) error {
113+
defer logElapsed("data_source.tencent_sqlserver_zone_config.read")()
114+
115+
logId := getLogId(contextNil)
116+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
117+
118+
sqlserverService := SqlserverService{client: meta.(*TencentCloudClient).apiV3Conn}
119+
120+
// get zoneinfo
121+
zoneInfoList, err := sqlserverService.DescribeZones(ctx)
122+
if err != nil {
123+
return fmt.Errorf("api[DescribeZones]fail, return %s", err.Error())
124+
}
125+
zoneSet := make(map[string]map[string]interface{})
126+
for _, zoneInfo := range zoneInfoList {
127+
zoneSetInfo := make(map[string]interface{}, 1)
128+
zoneSetInfo["id"] = zoneInfo.ZoneId
129+
zoneSet[*zoneInfo.Zone] = zoneSetInfo
130+
}
131+
132+
var zoneList []interface{}
133+
for k, v := range zoneSet {
134+
var zoneListItem = make(map[string]interface{})
135+
zoneListItem["availability_zone"] = k
136+
zoneListItem["zone_id"] = v["id"]
137+
138+
// get specinfo for each zone
139+
specinfoList, err := sqlserverService.DescribeProductConfig(ctx, k)
140+
if err != nil {
141+
return fmt.Errorf("api[DescribeProductConfig]fail, return %s", err.Error())
142+
}
143+
var specinfoConfigs []interface{}
144+
for _, specinfoItem := range specinfoList {
145+
var specinfoConfig = make(map[string]interface{})
146+
specinfoConfig["spec_id"] = specinfoItem.SpecId
147+
specinfoConfig["machine_type"] = specinfoItem.MachineType
148+
specinfoConfig["db_version"] = specinfoItem.Version
149+
specinfoConfig["db_version_name"] = specinfoItem.VersionName
150+
specinfoConfig["memory"] = specinfoItem.Memory
151+
specinfoConfig["cpu"] = specinfoItem.CPU
152+
specinfoConfig["min_storage_size"] = specinfoItem.MinStorage
153+
specinfoConfig["max_storage_size"] = specinfoItem.MaxStorage
154+
specinfoConfig["qps"] = specinfoItem.QPS
155+
specinfoConfig["charge_type"] = SQLSERVER_CHARGE_TYPE_NAME[*specinfoItem.PayModeStatus]
156+
157+
specinfoConfigs = append(specinfoConfigs, specinfoConfig)
158+
}
159+
zoneListItem["specinfo_list"] = specinfoConfigs
160+
zoneList = append(zoneList, zoneListItem)
161+
}
162+
163+
// set zone_list
164+
if err := d.Set("zone_list", zoneList); err != nil {
165+
return fmt.Errorf("[CRITAL]%s provider set zone_list fail, reason:%s\n ", logId, err.Error())
166+
}
167+
168+
d.SetId("zone_config")
169+
170+
if output, ok := d.GetOk("result_output_file"); ok && output.(string) != "" {
171+
if err := writeToFile(output.(string), zoneList); err != nil {
172+
log.Printf("[CRITAL]%s output file[%s] fail, reason[%s]\n",
173+
logId, output.(string), err.Error())
174+
}
175+
176+
}
177+
return nil
178+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccDataSourceTencentCloudSqlserverZoneConfig_basic(t *testing.T) {
10+
resource.Test(t, resource.TestCase{
11+
PreCheck: func() { testAccPreCheck(t) },
12+
Providers: testAccProviders,
13+
Steps: []resource.TestStep{
14+
{
15+
Config: TestAccDataSourceTencentCloudSqlserverZoneConfig,
16+
Check: resource.ComposeTestCheckFunc(
17+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_sqlserver_zone_config.foo"),
18+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.availability_zone"),
19+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.zone_id"),
20+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.spec_id"),
21+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.machine_type"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.db_version"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.db_version_name"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.memory"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.cpu"),
26+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.min_storage_size"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.max_storage_size"),
28+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.qps"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_sqlserver_zone_config.foo", "zone_list.0.specinfo_list.0.charge_type"),
30+
),
31+
},
32+
},
33+
})
34+
}
35+
36+
const TestAccDataSourceTencentCloudSqlserverZoneConfig = `
37+
data "tencentcloud_sqlserver_zone_config" "foo" {
38+
}
39+
`
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package tencentcloud
2+
3+
const (
4+
SQLSERVER_CHARGE_TYPE_PREPAID = "PREPAID"
5+
SQLSERVER_CHARGE_TYPE_POSTPAID = "POSTPAID_BY_HOUR"
6+
)
7+
8+
var SQLSERVER_CHARGE_TYPE_NAME = map[string]string{
9+
"PRE": SQLSERVER_CHARGE_TYPE_PREPAID,
10+
"POST": SQLSERVER_CHARGE_TYPE_POSTPAID,
11+
"ALL": "ALL",
12+
}

tencentcloud/provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ Serverless Cloud Function(SCF)
311311
tencentcloud_scf_function
312312
tencentcloud_scf_namespace
313313
314+
SQLServer
315+
Data Source
316+
tencentcloud_sqlserver_zone_config
317+
314318
SSL Certificates
315319
Data Source
316320
tencentcloud_ssl_certificates
@@ -592,6 +596,7 @@ func Provider() terraform.ResourceProvider {
592596
"tencentcloud_elasticsearch_instances": dataSourceTencentCloudElasticsearchInstances(),
593597
"tencentcloud_postgresql_instances": dataSourceTencentCloudPostgresqlInstances(),
594598
"tencentcloud_postgresql_specinfos": dataSourceTencentCloudPostgresqlSpecinfos(),
599+
"tencentcloud_sqlserver_zone_config": dataSourceTencentSqlserverZoneConfig(),
595600
},
596601

597602
ResourcesMap: map[string]*schema.Resource{

0 commit comments

Comments
 (0)