@@ -5,40 +5,33 @@ Example Usage
5
5
6
6
```hcl
7
7
resource "tencentcloud_bi_datasource_cloud" "datasource_cloud" {
8
- service_type = "Cloud"
9
- db_type = "Database type."
10
- charset = "utf8"
11
- db_user = "root"
12
- db_pwd = "abc"
13
- db_name = "abc"
14
- source_name = "abc"
15
- project_id = "123"
16
- vip = "1.2.3.4"
17
- vport = "3306"
18
- vpc_id = ""
19
- uniq_vpc_id = ""
20
- region_id = ""
21
- extra_param = ""
22
- data_origin = "abc"
23
- data_origin_project_id = "abc"
24
- data_origin_datasource_id = "abc"
8
+ charset = "utf8"
9
+ db_name = "bi_dev"
10
+ db_type = "MYSQL"
11
+ db_user = "root"
12
+ project_id = "11015056"
13
+ db_pwd = "xxxxxx"
14
+ service_type {
15
+ instance_id = "cdb-12viotu5"
16
+ region = "ap-guangzhou"
17
+ type = "Cloud"
18
+ }
19
+ source_name = "tf-test1"
20
+ vip = "10.0.0.4"
21
+ vport = "3306"
22
+ region_id = "gz"
23
+ vpc_id = 5292713
25
24
}
26
25
```
27
-
28
- Import
29
-
30
- bi datasource_cloud can be imported using the id, e.g.
31
-
32
- ```
33
- terraform import tencentcloud_bi_datasource_cloud.datasource_cloud datasource_cloud_id
34
- ```
35
26
*/
36
27
package tencentcloud
37
28
38
29
import (
39
30
"context"
31
+ "fmt"
40
32
"log"
41
33
"strconv"
34
+ "strings"
42
35
43
36
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
44
37
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -52,20 +45,38 @@ func resourceTencentCloudBiDatasourceCloud() *schema.Resource {
52
45
Read : resourceTencentCloudBiDatasourceCloudRead ,
53
46
Update : resourceTencentCloudBiDatasourceCloudUpdate ,
54
47
Delete : resourceTencentCloudBiDatasourceCloudDelete ,
55
- Importer : & schema.ResourceImporter {
56
- State : schema .ImportStatePassthrough ,
57
- },
48
+
58
49
Schema : map [string ]* schema.Schema {
59
50
"service_type" : {
60
51
Required : true ,
61
- Type : schema .TypeString ,
62
- Description : "Own or Cloud." ,
52
+ Type : schema .TypeList ,
53
+ MaxItems : 1 ,
54
+ Description : "Service type, Own or Cloud." ,
55
+ Elem : & schema.Resource {
56
+ Schema : map [string ]* schema.Schema {
57
+ "type" : {
58
+ Type : schema .TypeString ,
59
+ Required : true ,
60
+ Description : "Service type, Cloud." ,
61
+ },
62
+ "instance_id" : {
63
+ Type : schema .TypeString ,
64
+ Required : true ,
65
+ Description : "Instance Id." ,
66
+ },
67
+ "region" : {
68
+ Type : schema .TypeString ,
69
+ Required : true ,
70
+ Description : "Region." ,
71
+ },
72
+ },
73
+ },
63
74
},
64
75
65
76
"db_type" : {
66
77
Required : true ,
67
78
Type : schema .TypeString ,
68
- Description : "MYSQL." ,
79
+ Description : "` MYSQL`, `TDSQL-C_MYSQL`, `TDSQL_MYSQL`, `MSSQL`, `POSTGRESQL`, `MARIADB` ." ,
69
80
},
70
81
71
82
"charset" : {
@@ -118,7 +129,7 @@ func resourceTencentCloudBiDatasourceCloud() *schema.Resource {
118
129
},
119
130
120
131
"vpc_id" : {
121
- Optional : true ,
132
+ Required : true ,
122
133
Type : schema .TypeString ,
123
134
Description : "Vpc identification." ,
124
135
},
@@ -137,6 +148,7 @@ func resourceTencentCloudBiDatasourceCloud() *schema.Resource {
137
148
138
149
"extra_param" : {
139
150
Optional : true ,
151
+ Computed : true ,
140
152
Type : schema .TypeString ,
141
153
Description : "Extended parameters." ,
142
154
},
@@ -169,12 +181,18 @@ func resourceTencentCloudBiDatasourceCloudCreate(d *schema.ResourceData, meta in
169
181
logId := getLogId (contextNil )
170
182
171
183
var (
172
- request = bi .NewCreateDatasourceCloudRequest ()
173
- response = bi .NewCreateDatasourceCloudResponse ()
174
- id int64
184
+ request = bi .NewCreateDatasourceCloudRequest ()
185
+ response = bi .NewCreateDatasourceCloudResponse ()
186
+ projectId string
187
+ id int64
175
188
)
176
- if v , ok := d .GetOk ("service_type" ); ok {
177
- request .ServiceType = helper .String (v .(string ))
189
+
190
+ if dMap , ok := helper .InterfacesHeadMap (d , "service_type" ); ok {
191
+ v , o := helper .MapToString (dMap )
192
+ if ! o {
193
+ return fmt .Errorf ("ServiceType `%s` format error" , dMap )
194
+ }
195
+ request .ServiceType = & v
178
196
}
179
197
180
198
if v , ok := d .GetOk ("db_type" ); ok {
@@ -202,6 +220,7 @@ func resourceTencentCloudBiDatasourceCloudCreate(d *schema.ResourceData, meta in
202
220
}
203
221
204
222
if v , ok := d .GetOk ("project_id" ); ok {
223
+ projectId = v .(string )
205
224
request .ProjectId = helper .String (v .(string ))
206
225
}
207
226
@@ -257,7 +276,7 @@ func resourceTencentCloudBiDatasourceCloudCreate(d *schema.ResourceData, meta in
257
276
}
258
277
259
278
id = * response .Response .Data .Id
260
- d .SetId (strconv .FormatInt (id , 10 ))
279
+ d .SetId (strings . Join ([] string { projectId , strconv .FormatInt (id , 10 )}, FILED_SP ))
261
280
262
281
return resourceTencentCloudBiDatasourceCloudRead (d , meta )
263
282
}
@@ -272,10 +291,16 @@ func resourceTencentCloudBiDatasourceCloudRead(d *schema.ResourceData, meta inte
272
291
273
292
service := BiService {client : meta .(* TencentCloudClient ).apiV3Conn }
274
293
275
- id := d .Id ()
276
- idint , _ := strconv .Atoi (id )
294
+ idSplit := strings .Split (d .Id (), FILED_SP )
295
+ if len (idSplit ) != 2 {
296
+ return fmt .Errorf ("id is broken,%s" , d .Id ())
297
+ }
298
+ projectId := idSplit [0 ]
299
+ projectIdInt , _ := strconv .ParseInt (projectId , 10 , 64 )
300
+ id := idSplit [1 ]
301
+ idInt , _ := strconv .ParseInt (id , 10 , 64 )
277
302
278
- datasourceCloud , err := service .DescribeBiDatasourceCloudById (ctx , uint64 (idint ))
303
+ datasourceCloud , err := service .DescribeBiDatasourceCloudById (ctx , uint64 (projectIdInt ), uint64 ( idInt ))
279
304
if err != nil {
280
305
return err
281
306
}
@@ -287,7 +312,12 @@ func resourceTencentCloudBiDatasourceCloudRead(d *schema.ResourceData, meta inte
287
312
}
288
313
289
314
if datasourceCloud .ServiceType != nil {
290
- _ = d .Set ("service_type" , datasourceCloud .ServiceType )
315
+ v , err := helper .JsonToMap (* datasourceCloud .ServiceType )
316
+ if err != nil {
317
+ return fmt .Errorf ("ServiceType `%v` format error" , * datasourceCloud .ServiceType )
318
+ }
319
+
320
+ _ = d .Set ("service_type" , []interface {}{v })
291
321
}
292
322
293
323
if datasourceCloud .DbType != nil {
@@ -361,76 +391,64 @@ func resourceTencentCloudBiDatasourceCloudUpdate(d *schema.ResourceData, meta in
361
391
362
392
request := bi .NewModifyDatasourceCloudRequest ()
363
393
364
- id := d .Id ()
365
- idint , _ := strconv .Atoi (id )
366
- idUint64 := uint64 (idint )
394
+ idSplit := strings .Split (d .Id (), FILED_SP )
395
+ if len (idSplit ) != 2 {
396
+ return fmt .Errorf ("id is broken,%s" , d .Id ())
397
+ }
398
+ projectId := idSplit [0 ]
399
+ id := idSplit [1 ]
400
+ idInt , _ := strconv .ParseInt (id , 10 , 64 )
401
+ idUint64 := uint64 (idInt )
367
402
368
403
request .Id = & idUint64
404
+ request .ProjectId = & projectId
369
405
370
- if d .HasChange ("service_type" ) {
371
- if v , ok := d .GetOk ("service_type" ); ok {
372
- request .ServiceType = helper .String (v .(string ))
406
+ if dMap , ok := helper .InterfacesHeadMap (d , "service_type" ); ok {
407
+ v , o := helper .MapToString (dMap )
408
+ if ! o {
409
+ return fmt .Errorf ("ServiceType `%s` format error" , dMap )
373
410
}
411
+ request .ServiceType = & v
374
412
}
375
413
376
- if d .HasChange ("db_type" ) {
377
- if v , ok := d .GetOk ("db_type" ); ok {
378
- request .DbType = helper .String (v .(string ))
379
- }
414
+ if v , ok := d .GetOk ("db_type" ); ok {
415
+ request .DbType = helper .String (v .(string ))
380
416
}
381
417
382
- if d .HasChange ("charset" ) {
383
- if v , ok := d .GetOk ("charset" ); ok {
384
- request .Charset = helper .String (v .(string ))
385
- }
418
+ if v , ok := d .GetOk ("charset" ); ok {
419
+ request .Charset = helper .String (v .(string ))
386
420
}
387
421
388
- if d .HasChange ("db_user" ) {
389
- if v , ok := d .GetOk ("db_user" ); ok {
390
- request .DbUser = helper .String (v .(string ))
391
- }
422
+ if v , ok := d .GetOk ("db_user" ); ok {
423
+ request .DbUser = helper .String (v .(string ))
392
424
}
393
425
394
- if d .HasChange ("db_pwd" ) {
395
- if v , ok := d .GetOk ("db_pwd" ); ok {
396
- request .DbPwd = helper .String (v .(string ))
397
- }
426
+ if v , ok := d .GetOk ("db_pwd" ); ok {
427
+ request .DbPwd = helper .String (v .(string ))
398
428
}
399
429
400
- if d .HasChange ("db_name" ) {
401
- if v , ok := d .GetOk ("db_name" ); ok {
402
- request .DbName = helper .String (v .(string ))
403
- }
430
+ if v , ok := d .GetOk ("db_name" ); ok {
431
+ request .DbName = helper .String (v .(string ))
404
432
}
405
433
406
- if d .HasChange ("source_name" ) {
407
- if v , ok := d .GetOk ("source_name" ); ok {
408
- request .SourceName = helper .String (v .(string ))
409
- }
434
+ if v , ok := d .GetOk ("source_name" ); ok {
435
+ request .SourceName = helper .String (v .(string ))
410
436
}
411
437
412
- if d .HasChange ("project_id" ) {
413
- if v , ok := d .GetOk ("project_id" ); ok {
414
- request .ProjectId = helper .String (v .(string ))
415
- }
438
+ if v , ok := d .GetOk ("vip" ); ok {
439
+ request .Vip = helper .String (v .(string ))
416
440
}
417
441
418
- if d .HasChange ("vip" ) {
419
- if v , ok := d .GetOk ("vip" ); ok {
420
- request .Vip = helper .String (v .(string ))
421
- }
442
+ if v , ok := d .GetOk ("vport" ); ok {
443
+ request .Vport = helper .String (v .(string ))
422
444
}
423
445
424
- if d .HasChange ("vport" ) {
425
- if v , ok := d .GetOk ("vport" ); ok {
426
- request .Vport = helper .String (v .(string ))
427
- }
446
+ if v , ok := d .GetOk ("region_id" ); ok {
447
+ request .RegionId = helper .String (v .(string ))
428
448
}
429
449
430
- if d .HasChange ("vpc_id" ) {
431
- if v , ok := d .GetOk ("vpc_id" ); ok {
432
- request .VpcId = helper .String (v .(string ))
433
- }
450
+ if v , ok := d .GetOk ("vpc_id" ); ok {
451
+ request .VpcId = helper .String (v .(string ))
434
452
}
435
453
436
454
if d .HasChange ("uniq_vpc_id" ) {
@@ -439,12 +457,6 @@ func resourceTencentCloudBiDatasourceCloudUpdate(d *schema.ResourceData, meta in
439
457
}
440
458
}
441
459
442
- if d .HasChange ("region_id" ) {
443
- if v , ok := d .GetOk ("region_id" ); ok {
444
- request .RegionId = helper .String (v .(string ))
445
- }
446
- }
447
-
448
460
if d .HasChange ("extra_param" ) {
449
461
if v , ok := d .GetOk ("extra_param" ); ok {
450
462
request .ExtraParam = helper .String (v .(string ))
@@ -494,10 +506,16 @@ func resourceTencentCloudBiDatasourceCloudDelete(d *schema.ResourceData, meta in
494
506
ctx := context .WithValue (context .TODO (), logIdKey , logId )
495
507
496
508
service := BiService {client : meta .(* TencentCloudClient ).apiV3Conn }
497
- id := d .Id ()
498
- idint , _ := strconv .Atoi (id )
509
+ idSplit := strings .Split (d .Id (), FILED_SP )
510
+ if len (idSplit ) != 2 {
511
+ return fmt .Errorf ("id is broken,%s" , d .Id ())
512
+ }
513
+ projectId := idSplit [0 ]
514
+ projectIdInt , _ := strconv .ParseInt (projectId , 10 , 64 )
515
+ id := idSplit [1 ]
516
+ idInt , _ := strconv .ParseInt (id , 10 , 64 )
499
517
500
- if err := service .DeleteBiDatasourceCloudById (ctx , uint64 (idint )); err != nil {
518
+ if err := service .DeleteBiDatasourceCloudById (ctx , uint64 (projectIdInt ), uint64 ( idInt )); err != nil {
501
519
return err
502
520
}
503
521
0 commit comments