-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathresource_tc_ckafka_connect_resource.go
1715 lines (1543 loc) · 55.7 KB
/
resource_tc_ckafka_connect_resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package ckafka
import (
"context"
"log"
"time"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
ckafka "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka/v20190819"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
func ResourceTencentCloudCkafkaConnectResource() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudCkafkaConnectResourceCreate,
Read: resourceTencentCloudCkafkaConnectResourceRead,
Update: resourceTencentCloudCkafkaConnectResourceUpdate,
Delete: resourceTencentCloudCkafkaConnectResourceDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"resource_name": {
Required: true,
Type: schema.TypeString,
Description: "connection source name.",
},
"type": {
Required: true,
Type: schema.TypeString,
ForceNew: true,
Description: "connection source type.",
},
"description": {
Optional: true,
Type: schema.TypeString,
Description: "Connection source description.",
},
"dts_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Dts configuration, required when Type is DTS.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "Dts port.",
},
"group_id": {
Type: schema.TypeString,
Required: true,
Description: "Id of the Dts consumption group.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "The account number of the Dts consumption group.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "The password of the Dts consumption group.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "Dts instance Id.",
},
"topic": {
Type: schema.TypeString,
Required: true,
Description: "Topic subscribed by Dts.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Datahub task, default: false.",
},
},
},
},
"mongodb_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Mongo DB configuration, required when Type is MONGODB.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "MongoDB port.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "The username of the Mongo DB connection source.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "Password for the source of the Mongo DB connection.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "Instance resource of Mongo DB connection source.",
},
"self_built": {
Type: schema.TypeBool,
Required: true,
Description: "Whether the Mongo DB connection source is a self-built cluster.",
},
"service_vip": {
Type: schema.TypeString,
Optional: true,
Description: "The instance VIP of the Mongo DB connection source, when it is a Tencent Cloud instance, it is required.",
},
"uniq_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "The vpc Id of the Mongo DB connection source, which is required when it is a Tencent Cloud instance.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Datahub task, default: false.",
},
},
},
},
"es_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Es configuration, required when Type is ES.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "Es port.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "Es The username of the connection source.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "Es The password of the connection source.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "Instance resource of Es connection source.",
},
"self_built": {
Type: schema.TypeBool,
Required: true,
Description: "Whether the Es connection source is a self-built cluster.",
},
"service_vip": {
Type: schema.TypeString,
Optional: true,
Description: "The instance vip of the Es connection source, when it is a Tencent Cloud instance, it is required.",
},
"uniq_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "The vpc Id of the Es connection source, when it is a Tencent Cloud instance, it is required.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Datahub task, default: false.",
},
},
},
},
"clickhouse_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "ClickHouse configuration, required when Type is CLICKHOUSE.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "Clickhouse connection port.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "The username of the clickhouse connection source.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "Password for Clickhouse connection source.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "Instance resources for Click House connection sources.",
},
"self_built": {
Type: schema.TypeBool,
Required: true,
Description: "Whether the Clickhouse connection source is a self-built cluster.",
},
"service_vip": {
Type: schema.TypeString,
Optional: true,
Description: "Instance VIP of the ClickHouse connection source, when it is a Tencent Cloud instance, it is required.",
},
"uniq_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "The vpc Id of the source of the ClickHouse connection, when it is a Tencent Cloud instance, it is required.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Datahub task, default: false.",
},
},
},
},
"mysql_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "MySQL configuration, required when Type is MYSQL or TDSQL C_MYSQL.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "MySQL port.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "Username of Mysql connection source.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "Mysql connection source password.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "Instance resource of My SQL connection source.",
},
"service_vip": {
Type: schema.TypeString,
Optional: true,
Description: "The instance vip of the MySQL connection source, when it is a Tencent Cloud instance, it is required.",
},
"uniq_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "The vpc Id of the My SQL connection source, when it is a Tencent Cloud instance, it is required.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Datahub task, default: false.",
},
"cluster_id": {
Type: schema.TypeString,
Optional: true,
Description: "Required when type is TDSQL C_MYSQL.",
},
"self_built": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Mysql Whether the connection source is a self-built cluster, default: false.",
},
},
},
},
"postgresql_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Postgresql configuration, required when Type is POSTGRESQL or TDSQL C POSTGRESQL.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "PostgreSQL port.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "PostgreSQL The username of the connection source.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "PostgreSQL password.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "PostgreSQL instanceId.",
},
"service_vip": {
Type: schema.TypeString,
Optional: true,
Description: "The instance VIP of the Postgresql connection source, when it is a Tencent Cloud instance, it is required.",
},
"uniq_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "The instance vpcId of the Postgresql connection source, when it is a Tencent Cloud instance, it is required.",
},
"cluster_id": {
Type: schema.TypeString,
Optional: true,
Description: "Required when type is TDSQL C_POSTGRESQL.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Datahub task, default: false.",
},
"self_built": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "PostgreSQL Whether the connection source is a self-built cluster, default: false.",
},
},
},
},
"mariadb_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Maria DB configuration, required when Type is MARIADB.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "MariaDB port.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "MariaDB The username of the connection source.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "MariaDB password.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "MariaDB instanceId.",
},
"service_vip": {
Type: schema.TypeString,
Optional: true,
Description: "The instance vip of the Maria DB connection source, when it is a Tencent Cloud instance, it is required.",
},
"uniq_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "MariaDB vpcId, When it is a Tencent Cloud instance, it is required.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Datahub task, default: false.",
},
},
},
},
"sqlserver_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "SQLServer configuration, required when Type is SQLSERVER.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "SQLServer port.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "SQLServer The username of the connection source.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "SQLServer password.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "SQLServer instanceId.",
},
"service_vip": {
Type: schema.TypeString,
Optional: true,
Description: "SQLServer instance vip, When it is a Tencent Cloud instance, it is required.",
},
"uniq_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "SQLServer vpcId, When it is a Tencent Cloud instance, it is required.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Dip task, default: false.",
},
},
},
},
"doris_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Doris configuration, required when Type is DORIS.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "Doris jdbc CLB port, Usually mapped to port 9030 of fe.",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "Doris The username of the connection source.",
},
"password": {
Type: schema.TypeString,
Required: true,
Description: "Doris password.",
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "Doris instanceId.",
},
"service_vip": {
Type: schema.TypeString,
Optional: true,
Description: "Doris vip, When it is a Tencent Cloud instance, it is required.",
},
"uniq_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "Doris vpcId, When it is a Tencent Cloud instance, it is required.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Datahub task, default: false.",
},
"self_built": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Doris Whether the connection source is a self-built cluster, default: false.",
},
"be_port": {
Type: schema.TypeInt,
Optional: true,
Description: "Doris http CLB port, Usually mapped to port 8040 of be.",
},
},
},
},
"kafka_connect_param": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Kafka configuration, required when Type is KAFKA.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"resource": {
Type: schema.TypeString,
Optional: true,
Description: "Kafka instanceId, When it is a Tencent Cloud instance, it is required.",
},
"self_built": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether it is a self-built cluster, default: false.",
},
"is_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to update to the associated Dip task, default: false.",
},
"broker_address": {
Type: schema.TypeString,
Optional: true,
Description: "Kafka broker ip, Mandatory when self-built.",
},
"region": {
Type: schema.TypeString,
Optional: true,
Description: "CKafka instanceId region, Required when crossing regions.",
},
},
},
},
},
}
}
func resourceTencentCloudCkafkaConnectResourceCreate(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_ckafka_connect_resource.create")()
defer tccommon.InconsistentCheck(d, meta)()
logId := tccommon.GetLogId(tccommon.ContextNil)
var (
request = ckafka.NewCreateConnectResourceRequest()
response = ckafka.NewCreateConnectResourceResponse()
resourceId string
)
if v, ok := d.GetOk("resource_name"); ok {
request.ResourceName = helper.String(v.(string))
}
if v, ok := d.GetOk("type"); ok {
request.Type = helper.String(v.(string))
}
if v, ok := d.GetOk("description"); ok {
request.Description = helper.String(v.(string))
}
if dMap, ok := helper.InterfacesHeadMap(d, "dts_connect_param"); ok {
dtsConnectParam := ckafka.DtsConnectParam{}
if v, ok := dMap["port"]; ok {
dtsConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["group_id"]; ok {
dtsConnectParam.GroupId = helper.String(v.(string))
}
if v, ok := dMap["user_name"]; ok {
dtsConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
dtsConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
dtsConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["topic"]; ok {
dtsConnectParam.Topic = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
dtsConnectParam.IsUpdate = helper.Bool(v.(bool))
}
request.DtsConnectParam = &dtsConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "mongodb_connect_param"); ok {
mongoDBConnectParam := ckafka.MongoDBConnectParam{}
if v, ok := dMap["port"]; ok {
mongoDBConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["user_name"]; ok {
mongoDBConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
mongoDBConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
mongoDBConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["self_built"]; ok {
mongoDBConnectParam.SelfBuilt = helper.Bool(v.(bool))
}
if v, ok := dMap["service_vip"]; ok {
mongoDBConnectParam.ServiceVip = helper.String(v.(string))
}
if v, ok := dMap["uniq_vpc_id"]; ok {
mongoDBConnectParam.UniqVpcId = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
mongoDBConnectParam.IsUpdate = helper.Bool(v.(bool))
}
request.MongoDBConnectParam = &mongoDBConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "es_connect_param"); ok {
esConnectParam := ckafka.EsConnectParam{}
if v, ok := dMap["port"]; ok {
esConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["user_name"]; ok {
esConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
esConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
esConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["self_built"]; ok {
esConnectParam.SelfBuilt = helper.Bool(v.(bool))
}
if v, ok := dMap["service_vip"]; ok {
esConnectParam.ServiceVip = helper.String(v.(string))
}
if v, ok := dMap["uniq_vpc_id"]; ok {
esConnectParam.UniqVpcId = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
esConnectParam.IsUpdate = helper.Bool(v.(bool))
}
request.EsConnectParam = &esConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "clickhouse_connect_param"); ok {
clickHouseConnectParam := ckafka.ClickHouseConnectParam{}
if v, ok := dMap["port"]; ok {
clickHouseConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["user_name"]; ok {
clickHouseConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
clickHouseConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
clickHouseConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["self_built"]; ok {
clickHouseConnectParam.SelfBuilt = helper.Bool(v.(bool))
}
if v, ok := dMap["service_vip"]; ok {
clickHouseConnectParam.ServiceVip = helper.String(v.(string))
}
if v, ok := dMap["uniq_vpc_id"]; ok {
clickHouseConnectParam.UniqVpcId = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
clickHouseConnectParam.IsUpdate = helper.Bool(v.(bool))
}
request.ClickHouseConnectParam = &clickHouseConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "mysql_connect_param"); ok {
mySQLConnectParam := ckafka.MySQLConnectParam{}
if v, ok := dMap["port"]; ok {
mySQLConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["user_name"]; ok {
mySQLConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
mySQLConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
mySQLConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["service_vip"]; ok {
mySQLConnectParam.ServiceVip = helper.String(v.(string))
}
if v, ok := dMap["uniq_vpc_id"]; ok {
mySQLConnectParam.UniqVpcId = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
mySQLConnectParam.IsUpdate = helper.Bool(v.(bool))
}
if v, ok := dMap["cluster_id"]; ok {
mySQLConnectParam.ClusterId = helper.String(v.(string))
}
if v, ok := dMap["self_built"]; ok {
mySQLConnectParam.SelfBuilt = helper.Bool(v.(bool))
}
request.MySQLConnectParam = &mySQLConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "postgresql_connect_param"); ok {
postgreSQLConnectParam := ckafka.PostgreSQLConnectParam{}
if v, ok := dMap["port"]; ok {
postgreSQLConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["user_name"]; ok {
postgreSQLConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
postgreSQLConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
postgreSQLConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["service_vip"]; ok {
postgreSQLConnectParam.ServiceVip = helper.String(v.(string))
}
if v, ok := dMap["uniq_vpc_id"]; ok {
postgreSQLConnectParam.UniqVpcId = helper.String(v.(string))
}
if v, ok := dMap["cluster_id"]; ok {
postgreSQLConnectParam.ClusterId = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
postgreSQLConnectParam.IsUpdate = helper.Bool(v.(bool))
}
if v, ok := dMap["self_built"]; ok {
postgreSQLConnectParam.SelfBuilt = helper.Bool(v.(bool))
}
request.PostgreSQLConnectParam = &postgreSQLConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "mariadb_connect_param"); ok {
mariaDBConnectParam := ckafka.MariaDBConnectParam{}
if v, ok := dMap["port"]; ok {
mariaDBConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["user_name"]; ok {
mariaDBConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
mariaDBConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
mariaDBConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["service_vip"]; ok {
mariaDBConnectParam.ServiceVip = helper.String(v.(string))
}
if v, ok := dMap["uniq_vpc_id"]; ok {
mariaDBConnectParam.UniqVpcId = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
mariaDBConnectParam.IsUpdate = helper.Bool(v.(bool))
}
request.MariaDBConnectParam = &mariaDBConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "sqlserver_connect_param"); ok {
sQLServerConnectParam := ckafka.SQLServerConnectParam{}
if v, ok := dMap["port"]; ok {
sQLServerConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["user_name"]; ok {
sQLServerConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
sQLServerConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
sQLServerConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["service_vip"]; ok {
sQLServerConnectParam.ServiceVip = helper.String(v.(string))
}
if v, ok := dMap["uniq_vpc_id"]; ok {
sQLServerConnectParam.UniqVpcId = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
sQLServerConnectParam.IsUpdate = helper.Bool(v.(bool))
}
request.SQLServerConnectParam = &sQLServerConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "doris_connect_param"); ok {
dorisConnectParam := ckafka.DorisConnectParam{}
if v, ok := dMap["port"]; ok {
dorisConnectParam.Port = helper.IntInt64(v.(int))
}
if v, ok := dMap["user_name"]; ok {
dorisConnectParam.UserName = helper.String(v.(string))
}
if v, ok := dMap["password"]; ok {
dorisConnectParam.Password = helper.String(v.(string))
}
if v, ok := dMap["resource"]; ok {
dorisConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["service_vip"]; ok {
dorisConnectParam.ServiceVip = helper.String(v.(string))
}
if v, ok := dMap["uniq_vpc_id"]; ok {
dorisConnectParam.UniqVpcId = helper.String(v.(string))
}
if v, ok := dMap["is_update"]; ok {
dorisConnectParam.IsUpdate = helper.Bool(v.(bool))
}
if v, ok := dMap["self_built"]; ok {
dorisConnectParam.SelfBuilt = helper.Bool(v.(bool))
}
if v, ok := dMap["be_port"]; ok {
dorisConnectParam.BePort = helper.IntInt64(v.(int))
}
request.DorisConnectParam = &dorisConnectParam
}
if dMap, ok := helper.InterfacesHeadMap(d, "kafka_connect_param"); ok {
kafkaConnectParam := ckafka.KafkaConnectParam{}
if v, ok := dMap["resource"]; ok {
kafkaConnectParam.Resource = helper.String(v.(string))
}
if v, ok := dMap["self_built"]; ok {
kafkaConnectParam.SelfBuilt = helper.Bool(v.(bool))
}
if v, ok := dMap["is_update"]; ok {
kafkaConnectParam.IsUpdate = helper.Bool(v.(bool))
}
if v, ok := dMap["broker_address"]; ok {
kafkaConnectParam.BrokerAddress = helper.String(v.(string))
}
if v, ok := dMap["region"]; ok {
kafkaConnectParam.Region = helper.String(v.(string))
}
request.KafkaConnectParam = &kafkaConnectParam
}
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCkafkaClient().CreateConnectResource(request)
if e != nil {
return tccommon.RetryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}
response = result
return nil
})
if err != nil {
log.Printf("[CRITAL]%s create ckafka connectResource failed, reason:%+v", logId, err)
return err
}
resourceId = *response.Response.Result.ResourceId
d.SetId(resourceId)
service := CkafkaService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
conf := tccommon.BuildStateChangeConf([]string{}, []string{"1"}, 2*tccommon.ReadRetryTimeout, time.Second, service.CkafkaConnectResourceStateRefreshFunc(d.Id(), []string{}))
if _, e := conf.WaitForState(); e != nil {
return e
}
return resourceTencentCloudCkafkaConnectResourceRead(d, meta)
}
func resourceTencentCloudCkafkaConnectResourceRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_ckafka_connect_resource.read")()
defer tccommon.InconsistentCheck(d, meta)()
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service := CkafkaService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
resourceId := d.Id()
connectResource, err := service.DescribeCkafkaConnectResourceById(ctx, resourceId)
if err != nil {
return err
}
if connectResource == nil {
d.SetId("")
log.Printf("[WARN]%s resource `CkafkaConnectResource` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
return nil
}
if connectResource.ResourceName != nil {
_ = d.Set("resource_name", connectResource.ResourceName)
}
if connectResource.Type != nil {
_ = d.Set("type", connectResource.Type)
}
if connectResource.Description != nil {
_ = d.Set("description", connectResource.Description)
}
if connectResource.DtsConnectParam != nil {
dtsConnectParamMap := map[string]interface{}{}
if connectResource.DtsConnectParam.Port != nil {
dtsConnectParamMap["port"] = connectResource.DtsConnectParam.Port
}
if connectResource.DtsConnectParam.GroupId != nil {
dtsConnectParamMap["group_id"] = connectResource.DtsConnectParam.GroupId
}
if connectResource.DtsConnectParam.UserName != nil {
dtsConnectParamMap["user_name"] = connectResource.DtsConnectParam.UserName
}
password := connectResource.DtsConnectParam.Password
if password != nil && *password != "" {
dtsConnectParamMap["password"] = password
} else {
key := "dts_connect_param.0.password"
if v, ok := d.GetOk(key); ok {
dtsConnectParamMap["password"] = helper.String(v.(string))
}
}
if connectResource.DtsConnectParam.Resource != nil {
dtsConnectParamMap["resource"] = connectResource.DtsConnectParam.Resource
}
if connectResource.DtsConnectParam.Topic != nil {
dtsConnectParamMap["topic"] = connectResource.DtsConnectParam.Topic
}
if connectResource.DtsConnectParam.IsUpdate != nil {
dtsConnectParamMap["is_update"] = connectResource.DtsConnectParam.IsUpdate
}
_ = d.Set("dts_connect_param", []interface{}{dtsConnectParamMap})
}
if connectResource.MongoDBConnectParam != nil {
mongoDBConnectParamMap := map[string]interface{}{}
if connectResource.MongoDBConnectParam.Port != nil {
mongoDBConnectParamMap["port"] = connectResource.MongoDBConnectParam.Port
}
if connectResource.MongoDBConnectParam.UserName != nil {
mongoDBConnectParamMap["user_name"] = connectResource.MongoDBConnectParam.UserName
}
password := connectResource.MongoDBConnectParam.Password
if password != nil && *password != "" {
mongoDBConnectParamMap["password"] = password
} else {
key := "mongodb_connect_param.0.password"
if v, ok := d.GetOk(key); ok {
mongoDBConnectParamMap["password"] = helper.String(v.(string))
}
}
if connectResource.MongoDBConnectParam.Resource != nil {
mongoDBConnectParamMap["resource"] = connectResource.MongoDBConnectParam.Resource
}
if connectResource.MongoDBConnectParam.SelfBuilt != nil {
mongoDBConnectParamMap["self_built"] = connectResource.MongoDBConnectParam.SelfBuilt
}
if connectResource.MongoDBConnectParam.ServiceVip != nil {
mongoDBConnectParamMap["service_vip"] = connectResource.MongoDBConnectParam.ServiceVip
}
if connectResource.MongoDBConnectParam.UniqVpcId != nil {
mongoDBConnectParamMap["uniq_vpc_id"] = connectResource.MongoDBConnectParam.UniqVpcId