-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathresource_tc_api_gateway_api.go
1979 lines (1799 loc) · 75.1 KB
/
resource_tc_api_gateway_api.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 apigateway
import (
"context"
"fmt"
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"
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit"
)
func ResourceTencentCloudAPIGatewayAPI() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudAPIGatewayAPICreate,
Read: resourceTencentCloudAPIGatewayAPIRead,
Update: resourceTencentCloudAPIGatewayAPIUpdate,
Delete: resourceTencentCloudAPIGatewayAPIDelete,
Schema: map[string]*schema.Schema{
"service_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The unique ID of the service where the API is located. Refer to resource `tencentcloud_api_gateway_service`.",
},
"api_name": {
Type: schema.TypeString,
Required: true,
Description: "Custom API name.",
},
"api_desc": {
Type: schema.TypeString,
Optional: true,
Description: "Custom API description.",
},
"api_type": {
Optional: true,
Type: schema.TypeString,
Default: API_GATEWAY_API_TYPE_NORMAL,
ValidateFunc: tccommon.ValidateAllowedStringValue(API_GATEWAY_APT_TYPES),
Description: "API type, supports NORMAL (regular API) and TSF (microservice API), defaults to NORMAL.",
},
"auth_type": {
Type: schema.TypeString,
Optional: true,
Default: API_GATEWAY_AUTH_TYPE_NONE,
ValidateFunc: tccommon.ValidateAllowedStringValue(API_GATEWAY_AUTH_TYPES),
Description: "API authentication type. Support SECRET (Key Pair Authentication), NONE (Authentication Exemption), OAUTH, APP (Application Authentication). The default is NONE.",
},
"protocol": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: API_GATEWAY_API_PROTOCOL_HTTP,
ValidateFunc: tccommon.ValidateAllowedStringValue(API_GATEWAY_API_PROTOCOLS),
Description: "API frontend request type. Valid values: `HTTP`, `WEBSOCKET`. Default value: `HTTP`.",
},
"enable_cors": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Whether to enable CORS. Default value: `true`.",
},
"request_config_path": {
Type: schema.TypeString,
Required: true,
Description: "Request frontend path configuration. Like `/user/getinfo`.",
},
"request_config_method": {
Type: schema.TypeString,
Optional: true,
Default: "GET",
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"GET", "POST", "PUT", "DELETE", "HEAD", "ANY"}),
Description: "Request frontend method configuration. Valid values: `GET`,`POST`,`PUT`,`DELETE`,`HEAD`,`ANY`. Default value: `GET`.",
},
"constant_parameters": {
Optional: true,
Type: schema.TypeSet,
Description: "Constant parameter.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Constant parameter name. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Description: "Constant parameter description. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"position": {
Type: schema.TypeString,
Optional: true,
Description: "Constant parameter position. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"default_value": {
Type: schema.TypeString,
Optional: true,
Description: "Default value for constant parameters. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
},
},
},
"request_parameters": {
Type: schema.TypeSet,
Optional: true,
Description: "Frontend request parameters.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Parameter name.",
},
"position": {
Type: schema.TypeString,
Required: true,
Description: "Parameter location.",
},
"type": {
Type: schema.TypeString,
Required: true,
Description: "Parameter type.",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Description: "Parameter description.",
},
"default_value": {
Type: schema.TypeString,
Optional: true,
Description: "Parameter default value.",
},
"required": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If this parameter required. Default value: `false`.",
},
},
},
},
"micro_services": {
Optional: true,
Type: schema.TypeSet,
Description: "API bound microservice list.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cluster_id": {
Type: schema.TypeString,
Required: true,
Description: "Micro service cluster.",
},
"namespace_id": {
Type: schema.TypeString,
Required: true,
Description: "Microservice namespace.",
},
"micro_service_name": {
Type: schema.TypeString,
Required: true,
Description: "Microservice name.",
},
},
},
},
"service_tsf_load_balance_conf": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Load balancing configuration for microservices.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"is_load_balance": {
Type: schema.TypeBool,
Optional: true,
Description: "Is load balancing enabled.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"method": {
Type: schema.TypeString,
Optional: true,
Description: "Load balancing method.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"session_stick_required": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether to enable session persistence.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"session_stick_timeout": {
Type: schema.TypeInt,
Optional: true,
Description: "Session hold timeout.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
},
},
},
"service_tsf_health_check_conf": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Health check configuration for microservices.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"is_health_check": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether to initiate a health check.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"request_volume_threshold": {
Type: schema.TypeInt,
Optional: true,
Description: "Health check threshold.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"sleep_window_in_milliseconds": {
Type: schema.TypeInt,
Optional: true,
Description: "Window size.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"error_threshold_percentage": {
Type: schema.TypeInt,
Optional: true,
Description: "Threshold percentage.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
},
},
},
"target_services": {
Optional: true,
Type: schema.TypeList,
Description: "Target type backend resource information. (Internal testing stage).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vm_ip": {
Type: schema.TypeString,
Required: true,
Description: "vm ip.",
},
"vpc_id": {
Type: schema.TypeString,
Required: true,
Description: "vpc id.",
},
"vm_port": {
Type: schema.TypeInt,
Required: true,
Description: "vm port.",
},
"host_ip": {
Type: schema.TypeString,
Required: true,
Description: "Host IP of the CVM.",
},
"docker_ip": {
Type: schema.TypeString,
Optional: true,
Description: "docker ip.",
},
},
},
},
"target_services_load_balance_conf": {
Optional: true,
Type: schema.TypeInt,
Description: "Target type load balancing configuration. (Internal testing stage).",
},
"target_services_health_check_conf": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Target health check configuration. (Internal testing stage).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"is_health_check": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether to initiate a health check.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"request_volume_threshold": {
Type: schema.TypeInt,
Optional: true,
Description: "Health check threshold.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"sleep_window_in_milliseconds": {
Type: schema.TypeInt,
Optional: true,
Description: "Window size.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"error_threshold_percentage": {
Type: schema.TypeInt,
Optional: true,
Description: "Threshold percentage.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
},
},
},
"api_business_type": {
Optional: true,
Computed: true,
Type: schema.TypeString,
Description: "When `auth_type` is OAUTH, this field is valid, NORMAL: Business API, OAUTH: Authorization API.",
},
"service_config_type": {
Type: schema.TypeString,
Optional: true,
Default: API_GATEWAY_SERVICE_TYPE_HTTP,
ValidateFunc: tccommon.ValidateAllowedStringValue(API_GATEWAY_SERVICE_TYPES),
Description: "The backend service type of the API. Supports HTTP, MOCK, TSF, SCF, WEBSOCKET, COS, TARGET (internal testing).",
},
"service_config_timeout": {
Type: schema.TypeInt,
Optional: true,
Default: 5,
Description: "API backend service timeout period in seconds. Default value: `5`.",
},
"service_config_product": {
Type: schema.TypeString,
Optional: true,
Description: "Backend type. Effective when enabling vpc, currently supported types are clb, cvm, and upstream.",
},
"service_config_vpc_id": {
Type: schema.TypeString,
Optional: true,
Description: "Unique VPC ID.",
},
"service_config_url": {
Type: schema.TypeString,
Optional: true,
Description: "The backend service URL of the API. If the ServiceType is HTTP, this parameter must be passed.",
},
"service_config_path": {
Type: schema.TypeString,
Optional: true,
Description: "API backend service path, such as /path. If `service_config_type` is `HTTP`, this parameter will be required. The frontend `request_config_path` and backend path `service_config_path` can be different.",
},
"service_config_method": {
Type: schema.TypeString,
Optional: true,
Description: "API backend service request method, such as `GET`. If `service_config_type` is `HTTP`, this parameter will be required. The frontend `request_config_method` and backend method `service_config_method` can be different.",
},
"service_config_upstream_id": {
Type: schema.TypeString,
Optional: true,
Description: "Only required when binding to VPC channelsNote: This field may return null, indicating that a valid value cannot be obtained.",
},
"service_config_cos_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "API backend COS configuration. If ServiceType is COS, then this parameter must be passed.Note: This field may return null, indicating that a valid value cannot be obtained.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action": {
Type: schema.TypeString,
Required: true,
Description: "The API calls the backend COS method, and the optional values for the front-end request method and Action are:GET: GetObjectPUT: PutObjectPOST: PostObject, AppendObjectHEAD: HeadObjectDELETE: DeleteObject.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"bucket_name": {
Type: schema.TypeString,
Required: true,
Description: "The bucket name of the API backend COS.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"authorization": {
Type: schema.TypeBool,
Optional: true,
Description: "The API calls the signature switch of the backend COS, which defaults to false.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"path_match_mode": {
Type: schema.TypeString,
Optional: true,
Description: "Path matching mode for API backend COS, optional values:BackEndPath: Backend path matchingFullPath: Full Path MatchingThe default value is: BackEndPathNote: This field may return null, indicating that a valid value cannot be obtained.",
},
},
},
},
"service_config_scf_function_name": {
Type: schema.TypeString,
Optional: true,
Description: "SCF function name. This parameter takes effect when `service_config_type` is `SCF`.",
},
"service_config_scf_function_namespace": {
Type: schema.TypeString,
Optional: true,
Description: "SCF function namespace. This parameter takes effect when `service_config_type` is `SCF`.",
},
"service_config_scf_function_qualifier": {
Type: schema.TypeString,
Optional: true,
Description: "SCF function version. This parameter takes effect when `service_config_type` is `SCF`.",
},
"service_config_scf_function_type": {
Optional: true,
Type: schema.TypeString,
Description: "Scf function type. Effective when the backend type is SCF. Support Event Triggering (EVENT) and HTTP Direct Cloud Function (HTTP).",
},
"service_config_scf_is_integrated_response": {
Optional: true,
Type: schema.TypeBool,
Description: "Whether to enable response integration. Effective when the backend type is SCF.",
},
"service_config_mock_return_message": {
Type: schema.TypeString,
Optional: true,
Description: "Returned information of API backend mocking. This parameter is required when `service_config_type` is `MOCK`.",
},
"service_config_websocket_register_function_name": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket registration function. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"service_config_websocket_cleanup_function_name": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket cleaning function. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"service_config_websocket_transport_function_name": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket transfer function. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"service_config_websocket_register_function_namespace": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket registers function namespaces. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"service_config_websocket_register_function_qualifier": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket transfer function version. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"service_config_websocket_transport_function_namespace": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket transfer function namespace. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"service_config_websocket_transport_function_qualifier": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket transfer function version. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"service_config_websocket_cleanup_function_namespace": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket cleans up the function namespace. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"service_config_websocket_cleanup_function_qualifier": {
Optional: true,
Type: schema.TypeString,
Description: "Scf websocket cleaning function version. It takes effect when the current end type is WEBSOCKET and the backend type is SCF.",
},
"is_debug_after_charge": {
Optional: true,
Computed: true,
Type: schema.TypeBool,
Description: "Charge after starting debugging. (Cloud Market Reserved Fields).",
},
"is_delete_response_error_codes": {
Optional: true,
Computed: true,
Type: schema.TypeBool,
Description: "Do you want to delete the custom response configuration error code? If it is not passed or False is passed, it will not be deleted. If True is passed, all custom response configuration error codes for this API will be deleted.",
},
"response_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: tccommon.ValidateAllowedStringValue(API_GATEWAY_API_RESPONSE_TYPES),
Description: "Return type. Valid values: `HTML`, `JSON`, `TEXT`, `BINARY`, `XML`. Default value: `HTML`.",
},
"response_success_example": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Successful response sample of custom response configuration.",
},
"response_fail_example": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Response failure sample of custom response configuration.",
},
"response_error_codes": {
Type: schema.TypeSet,
Optional: true,
Description: "Custom error code configuration. Must keep at least one after set.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"code": {
Type: schema.TypeInt,
Required: true,
Description: "Custom response configuration error code.",
},
"msg": {
Type: schema.TypeString,
Required: true,
Description: "Custom response configuration error message.",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Description: "Parameter description.",
},
"converted_code": {
Type: schema.TypeInt,
Optional: true,
Description: "Custom error code conversion.",
},
"need_convert": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to enable error code conversion. Default value: `false`.",
},
},
},
},
"auth_relation_api_id": {
Optional: true,
Computed: true,
Type: schema.TypeString,
Description: "The unique ID of the associated authorization API takes effect when AuthType is OAUTH and ApiBusinessType is NORMAL. The unique ID of the oauth2.0 authorized API that identifies the business API binding.",
},
"service_parameters": {
Optional: true,
Type: schema.TypeList,
Description: "The backend service parameters of the API.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The backend service parameter name of the API. This parameter is only used when ServiceType is HTTP. The front and rear parameter names can be different.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"position": {
Type: schema.TypeString,
Optional: true,
Description: "The backend service parameter location of the API, such as head. This parameter is only used when ServiceType is HTTP. The parameter positions at the front and rear ends can be configured differently.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"relevant_request_parameter_position": {
Type: schema.TypeString,
Optional: true,
Description: "The location of the front-end parameters corresponding to the backend service parameters of the API, such as head. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"relevant_request_parameter_name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the front-end parameter corresponding to the backend service parameter of the API. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"default_value": {
Type: schema.TypeString,
Optional: true,
Description: "The default value for the backend service parameters of the API. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"relevant_request_parameter_desc": {
Type: schema.TypeString,
Optional: true,
Description: "Remarks on the backend service parameters of the API. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"relevant_request_parameter_type": {
Type: schema.TypeString,
Optional: true,
Description: "The backend service parameter type of the API. This parameter is only used when ServiceType is HTTP.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
},
},
},
"oauth_config": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "OAuth configuration. Effective when AuthType is OAUTH.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"public_key": {
Type: schema.TypeString,
Required: true,
Description: "Public key, used to verify user tokens.",
},
"token_location": {
Type: schema.TypeString,
Required: true,
Description: "Token passes the position.",
},
"login_redirect_url": {
Type: schema.TypeString,
Optional: true,
Description: "Redirect address, used to guide users in login operations.",
},
},
},
},
"target_namespace_id": {
Optional: true,
Type: schema.TypeString,
Description: "Tsf serverless namespace ID. (In internal testing).",
},
"user_type": {
Optional: true,
Type: schema.TypeString,
Description: "User type.",
},
"is_base64_encoded": {
Optional: true,
Computed: true,
Type: schema.TypeBool,
Description: "Whether to enable Base64 encoding will only take effect when the backend is scf.",
},
"event_bus_id": {
Optional: true,
Type: schema.TypeString,
Description: "Event bus ID.",
},
"eiam_app_type": {
Optional: true,
Type: schema.TypeString,
Description: "EIAM application type.",
},
"eiam_auth_type": {
Optional: true,
Type: schema.TypeString,
Description: "The EIAM application authentication type supports AuthenticationOnly, Authentication, and Authorization.",
},
"eiam_app_id": {
Optional: true,
Type: schema.TypeString,
Description: "EIAM application ID.",
},
"token_timeout": {
Optional: true,
Type: schema.TypeInt,
Description: "The effective time of the EIAM application token, measured in seconds, defaults to 7200 seconds.",
},
"owner": {
Optional: true,
Type: schema.TypeString,
Description: "Owner of resources.",
},
"release_limit": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "API QPS value. Enter a positive number to limit the API query rate per second `QPS`.",
},
"pre_limit": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "API QPS value. Enter a positive number to limit the API query rate per second `QPS`.",
},
"test_limit": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "API QPS value. Enter a positive number to limit the API query rate per second `QPS`.",
},
// Computed values.
"update_time": {
Type: schema.TypeString,
Computed: true,
Description: "Last modified time in the format of YYYY-MM-DDThh:mm:ssZ according to ISO 8601 standard. UTC time is used.",
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time in the format of YYYY-MM-DDThh:mm:ssZ according to ISO 8601 standard. UTC time is used.",
},
},
}
}
func resourceTencentCloudAPIGatewayAPICreate(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_api_gateway_api.create")()
var (
apiGatewayService = APIGatewayService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
err error
response = apigateway.NewCreateApiResponse()
request = apigateway.NewCreateApiRequest()
serviceId = d.Get("service_id").(string)
has bool
releaseLimit int
preLimit int
testLimit int
)
request.ServiceId = &serviceId
request.ApiName = helper.String(d.Get("api_name").(string))
if object, ok := d.GetOk("api_desc"); ok {
request.ApiDesc = helper.String(object.(string))
}
request.ApiType = helper.String(d.Get("api_type").(string))
request.AuthType = helper.String(d.Get("auth_type").(string))
request.Protocol = helper.String(d.Get("protocol").(string))
request.EnableCORS = helper.Bool(d.Get("enable_cors").(bool))
request.RequestConfig =
&apigateway.ApiRequestConfig{Path: helper.String(d.Get("request_config_path").(string)),
Method: helper.String(d.Get("request_config_method").(string))}
if v, ok := d.GetOk("constant_parameters"); ok {
constantParameters := v.(*schema.Set).List()
request.ConstantParameters = make([]*apigateway.ConstantParameter, 0, len(constantParameters))
for _, item := range constantParameters {
dMap := item.(map[string]interface{})
constantParameter := apigateway.ConstantParameter{}
if v, ok := dMap["name"]; ok {
constantParameter.Name = helper.String(v.(string))
}
if v, ok := dMap["desc"]; ok {
constantParameter.Desc = helper.String(v.(string))
}
if v, ok := dMap["position"]; ok {
constantParameter.Position = helper.String(v.(string))
}
if v, ok := dMap["default_value"]; ok {
constantParameter.DefaultValue = helper.String(v.(string))
}
request.ConstantParameters = append(request.ConstantParameters, &constantParameter)
}
}
if object, ok := d.GetOk("request_parameters"); ok {
parameters := object.(*schema.Set).List()
request.RequestParameters = make([]*apigateway.RequestParameter, 0, len(parameters))
for _, parameter := range parameters {
parameterMap := parameter.(map[string]interface{})
requestParameter := &apigateway.RequestParameter{
Name: helper.String(parameterMap["name"].(string)),
Position: helper.String(parameterMap["position"].(string)),
Type: helper.String(parameterMap["type"].(string)),
Required: helper.Bool(parameterMap["required"].(bool)),
}
if parameterMap["desc"] != nil {
requestParameter.Desc = helper.String(parameterMap["desc"].(string))
}
if parameterMap["default_value"] != nil {
requestParameter.DefaultValue = helper.String(parameterMap["default_value"].(string))
}
request.RequestParameters = append(request.RequestParameters, requestParameter)
}
}
if v, ok := d.GetOk("micro_services"); ok {
microServices := v.(*schema.Set).List()
request.MicroServices = make([]*apigateway.MicroServiceReq, 0, len(microServices))
for _, item := range microServices {
dMap := item.(map[string]interface{})
microServiceReq := apigateway.MicroServiceReq{}
if v, ok := dMap["cluster_id"]; ok {
microServiceReq.ClusterId = helper.String(v.(string))
}
if v, ok := dMap["namespace_id"]; ok {
microServiceReq.NamespaceId = helper.String(v.(string))
}
if v, ok := dMap["micro_service_name"]; ok {
microServiceReq.MicroServiceName = helper.String(v.(string))
}
request.MicroServices = append(request.MicroServices, µServiceReq)
}
}
if dMap, ok := helper.InterfacesHeadMap(d, "service_tsf_load_balance_conf"); ok {
tsfLoadBalanceConfResp := apigateway.TsfLoadBalanceConfResp{}
if v, ok := dMap["is_load_balance"]; ok {
tsfLoadBalanceConfResp.IsLoadBalance = helper.Bool(v.(bool))
}
if v, ok := dMap["method"]; ok {
tsfLoadBalanceConfResp.Method = helper.String(v.(string))
}
if v, ok := dMap["session_stick_required"]; ok {
tsfLoadBalanceConfResp.SessionStickRequired = helper.Bool(v.(bool))
}
if v, ok := dMap["session_stick_timeout"]; ok {
tsfLoadBalanceConfResp.SessionStickTimeout = helper.IntInt64(v.(int))
}
request.ServiceTsfLoadBalanceConf = &tsfLoadBalanceConfResp
}
if dMap, ok := helper.InterfacesHeadMap(d, "service_tsf_health_check_conf"); ok {
healthCheckConf := apigateway.HealthCheckConf{}
if v, ok := dMap["is_health_check"]; ok {
healthCheckConf.IsHealthCheck = helper.Bool(v.(bool))
}
if v, ok := dMap["request_volume_threshold"]; ok {
healthCheckConf.RequestVolumeThreshold = helper.IntInt64(v.(int))
}
if v, ok := dMap["sleep_window_in_milliseconds"]; ok {
healthCheckConf.SleepWindowInMilliseconds = helper.IntInt64(v.(int))
}
if v, ok := dMap["error_threshold_percentage"]; ok {
healthCheckConf.ErrorThresholdPercentage = helper.IntInt64(v.(int))
}
request.ServiceTsfHealthCheckConf = &healthCheckConf
}
if v, ok := d.GetOk("target_services"); ok {
targetServices := v.(*schema.Set).List()
request.TargetServices = make([]*apigateway.TargetServicesReq, 0, len(targetServices))
for _, item := range targetServices {
dMap := item.(map[string]interface{})
targetServicesReq := apigateway.TargetServicesReq{}
if v, ok := dMap["vm_ip"]; ok {
targetServicesReq.VmIp = helper.String(v.(string))
}
if v, ok := dMap["vpc_id"]; ok {
targetServicesReq.VpcId = helper.String(v.(string))
}
if v, ok := dMap["vm_port"]; ok {
targetServicesReq.VmPort = helper.IntInt64(v.(int))
}
if v, ok := dMap["host_ip"]; ok {
targetServicesReq.HostIp = helper.String(v.(string))
}
if v, ok := dMap["docker_ip"]; ok {
targetServicesReq.DockerIp = helper.String(v.(string))
}
request.TargetServices = append(request.TargetServices, &targetServicesReq)
}
}
if v, ok := d.GetOkExists("target_services_load_balance_conf"); ok {
request.TargetServicesLoadBalanceConf = helper.IntInt64(v.(int))
}
if dMap, ok := helper.InterfacesHeadMap(d, "target_services_health_check_conf"); ok {
healthCheckConf := apigateway.HealthCheckConf{}
if v, ok := dMap["is_health_check"]; ok {
healthCheckConf.IsHealthCheck = helper.Bool(v.(bool))
}
if v, ok := dMap["request_volume_threshold"]; ok {
healthCheckConf.RequestVolumeThreshold = helper.IntInt64(v.(int))
}
if v, ok := dMap["sleep_window_in_milliseconds"]; ok {
healthCheckConf.SleepWindowInMilliseconds = helper.IntInt64(v.(int))
}
if v, ok := dMap["error_threshold_percentage"]; ok {
healthCheckConf.ErrorThresholdPercentage = helper.IntInt64(v.(int))
}
request.TargetServicesHealthCheckConf = &healthCheckConf
}
if *request.AuthType == "OAUTH" {
if v, ok := d.GetOk("api_business_type"); ok {
request.ApiBusinessType = helper.String(v.(string))
}
}
var serviceType = d.Get("service_config_type").(string)
request.ServiceType = &serviceType
request.ServiceTimeout = helper.IntInt64(d.Get("service_config_timeout").(int))
switch serviceType {
case API_GATEWAY_SERVICE_TYPE_WEBSOCKET, API_GATEWAY_SERVICE_TYPE_HTTP:
serviceConfigProduct := d.Get("service_config_product").(string)
serviceConfigVpcId := d.Get("service_config_vpc_id").(string)
serviceConfigUrl := d.Get("service_config_url").(string)
serviceConfigPath := d.Get("service_config_path").(string)
serviceConfigMethod := d.Get("service_config_method").(string)
serviceConfigUpstreamId := d.Get("service_config_upstream_id").(string)
if serviceConfigProduct != "" {
if serviceConfigVpcId == "" {
return fmt.Errorf("`service_config_product` need param `service_config_vpc_id`")
}
}
if serviceConfigUrl == "" || serviceConfigPath == "" || serviceConfigMethod == "" {
return fmt.Errorf("`service_config_url`,`service_config_path`,`service_config_method` is needed if `service_config_type` is `WEBSOCKET` or `HTTP`")
}
request.ServiceConfig = &apigateway.ServiceConfig{}
if serviceConfigProduct != "" {
request.ServiceConfig.Product = &serviceConfigProduct
}
if serviceConfigVpcId != "" {
request.ServiceConfig.UniqVpcId = &serviceConfigVpcId
}
if serviceConfigUpstreamId != "" {
request.ServiceConfig.UpstreamId = &serviceConfigUpstreamId
}
request.ServiceConfig.Url = &serviceConfigUrl
request.ServiceConfig.Path = &serviceConfigPath
request.ServiceConfig.Method = &serviceConfigMethod
case API_GATEWAY_SERVICE_TYPE_MOCK:
serviceConfigMockReturnMessage := d.Get("service_config_mock_return_message").(string)
if serviceConfigMockReturnMessage == "" {
return fmt.Errorf("`service_config_mock_return_message` is needed if `service_config_type` is `MOCK`")
}
request.ServiceMockReturnMessage = &serviceConfigMockReturnMessage
case API_GATEWAY_SERVICE_TYPE_SCF:
scfFunctionName := d.Get("service_config_scf_function_name").(string)
scfFunctionNamespace := d.Get("service_config_scf_function_namespace").(string)
scfFunctionQualifier := d.Get("service_config_scf_function_qualifier").(string)
scfFunctionType := d.Get("service_config_scf_function_type").(string)
scfFunctionIntegratedResponse := d.Get("service_config_scf_is_integrated_response").(bool)
if scfFunctionName == "" || scfFunctionNamespace == "" || scfFunctionQualifier == "" || scfFunctionType == "" {
return fmt.Errorf("`service_config_scf_function_name`,`service_config_scf_function_namespace`,`service_config_scf_function_qualifier`, `service_config_scf_function_type` is needed if `service_config_type` is `SCF`")
}
request.ServiceScfFunctionName = &scfFunctionName
request.ServiceScfFunctionNamespace = &scfFunctionNamespace
request.ServiceScfFunctionQualifier = &scfFunctionQualifier
request.ServiceScfFunctionType = &scfFunctionType
request.ServiceScfIsIntegratedResponse = &scfFunctionIntegratedResponse
case API_GATEWAY_SERVICE_TYPE_COS:
if dMap, ok := helper.InterfacesHeadMap(d, "service_config_cos_config"); ok {
cosConfig := apigateway.ServiceConfig{}.CosConfig
if v, ok := dMap["action"]; ok {
cosConfig.Action = helper.String(v.(string))
}
if v, ok := dMap["bucket_name"]; ok {
cosConfig.BucketName = helper.String(v.(string))
}
if v, ok := dMap["authorization"]; ok {
cosConfig.Authorization = helper.Bool(v.(bool))
}
if v, ok := dMap["path_match_mode"]; ok {
cosConfig.PathMatchMode = helper.String(v.(string))
}
request.ServiceConfig.CosConfig = cosConfig
}
case API_GATEWAY_SERVICE_TYPE_TSF:
serviceWebsocketRegisterFunctionName := d.Get("service_config_websocket_register_function_name").(string)
serviceWebsocketRegisterFunctionNamespace := d.Get("service_config_websocket_register_function_namespace").(string)
serviceWebsocketRegisterFunctionQualifier := d.Get("service_config_websocket_register_function_qualifier").(string)
serviceWebsocketCleanupFunctionName := d.Get("service_config_websocket_cleanup_function_name").(string)
serviceWebsocketCleanupFunctionNamespace := d.Get("service_config_websocket_cleanup_function_namespace").(string)
serviceWebsocketCleanupFunctionQualifier := d.Get("service_config_websocket_cleanup_function_qualifier").(string)
serviceWebsocketTransportFunctionName := d.Get("service_config_websocket_transport_function_name").(string)
serviceWebsocketTransportFunctionNamespace := d.Get("service_config_websocket_transport_function_namespace").(string)
serviceWebsocketTransportFunctionQualifier := d.Get("service_config_websocket_transport_function_qualifier").(string)
request.ServiceWebsocketRegisterFunctionName = &serviceWebsocketRegisterFunctionName
request.ServiceWebsocketRegisterFunctionNamespace = &serviceWebsocketRegisterFunctionNamespace
request.ServiceWebsocketRegisterFunctionQualifier = &serviceWebsocketRegisterFunctionQualifier
request.ServiceWebsocketCleanupFunctionName = &serviceWebsocketCleanupFunctionName
request.ServiceWebsocketCleanupFunctionNamespace = &serviceWebsocketCleanupFunctionNamespace
request.ServiceWebsocketCleanupFunctionQualifier = &serviceWebsocketCleanupFunctionQualifier
request.ServiceWebsocketTransportFunctionName = &serviceWebsocketTransportFunctionName
request.ServiceWebsocketTransportFunctionNamespace = &serviceWebsocketTransportFunctionNamespace
request.ServiceWebsocketTransportFunctionQualifier = &serviceWebsocketTransportFunctionQualifier
}
if v, ok := d.GetOkExists("is_debug_after_charge"); ok {
request.IsDebugAfterCharge = helper.Bool(v.(bool))
}
if v, ok := d.GetOkExists("is_delete_response_error_codes"); ok {
request.IsDeleteResponseErrorCodes = helper.Bool(v.(bool))
}
request.ResponseType = helper.String(d.Get("response_type").(string))
if object, ok := d.GetOk("response_success_example"); ok {
request.ResponseSuccessExample = helper.String(object.(string))
}
if object, ok := d.GetOk("response_fail_example"); ok {
request.ResponseFailExample = helper.String(object.(string))
}
if v, ok := d.GetOk("auth_relation_api_id"); ok {
request.AuthRelationApiId = helper.String(v.(string))
}
if v, ok := d.GetOk("service_parameters"); ok {
serviceParameters := v.(*schema.Set).List()
request.ServiceParameters = make([]*apigateway.ServiceParameter, 0, len(serviceParameters))
for _, item := range serviceParameters {
dMap := item.(map[string]interface{})
serviceParameter := apigateway.ServiceParameter{}
if v, ok := dMap["name"]; ok {
serviceParameter.Name = helper.String(v.(string))
}
if v, ok := dMap["position"]; ok {
serviceParameter.Position = helper.String(v.(string))
}
if v, ok := dMap["relevant_request_parameter_position"]; ok {
serviceParameter.RelevantRequestParameterPosition = helper.String(v.(string))
}
if v, ok := dMap["relevant_request_parameter_name"]; ok {
serviceParameter.RelevantRequestParameterName = helper.String(v.(string))
}
if v, ok := dMap["default_value"]; ok {
serviceParameter.DefaultValue = helper.String(v.(string))
}
if v, ok := dMap["relevant_request_parameter_desc"]; ok {
serviceParameter.RelevantRequestParameterDesc = helper.String(v.(string))
}
if v, ok := dMap["relevant_request_parameter_type"]; ok {