/
utils_wait.go
1476 lines (1315 loc) · 81.1 KB
/
utils_wait.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
// Copyright 2021 Confluent Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"net/http"
"time"
)
const (
stateUp = "UP"
stateCreated = "CREATED"
)
func waitForCreatedKafkaApiKeyToSync(ctx context.Context, c *KafkaRestClient) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: kafkaApiKeySyncStatus(ctx, c),
// Default timeout for a resource
// https://www.terraform.io/plugin/sdkv2/resources/retries-and-customizable-timeouts
// Based on the tests, Kafka API Key takes about 2 minutes to sync
Timeout: 20 * time.Minute,
Delay: 1 * time.Minute,
PollInterval: 1 * time.Minute,
// Expects 2x http.StatusOK before exiting which adds PollInterval to the total time it takes to sync an API Key
// but helps to ensure the API Key is synced across all brokers.
ContinuousTargetOccurence: 2,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka API Key %q to sync", c.clusterApiKey), map[string]interface{}{apiKeyLoggingKey: c.clusterApiKey})
if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return err
}
return nil
}
func waitForCreatedSchemaRegistryApiKeyToSync(ctx context.Context, c *SchemaRegistryRestClient) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: schemaRegistryApiKeySyncStatus(ctx, c),
// Default timeout for a resource
// https://www.terraform.io/plugin/sdkv2/resources/retries-and-customizable-timeouts
// Based on the tests, Schema Registry API Key takes about 30 seconds to sync
Timeout: 20 * time.Minute,
Delay: 30 * time.Second,
PollInterval: 30 * time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka API Key %q to sync", c.clusterApiKey), map[string]interface{}{apiKeyLoggingKey: c.clusterApiKey})
if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return err
}
return nil
}
func waitForCreatedFlinkApiKeyToSync(ctx context.Context, c *FlinkRestClient, organizationID string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: flinkApiKeySyncStatus(ctx, c, organizationID),
// Default timeout for a resource
// https://www.terraform.io/plugin/sdkv2/resources/retries-and-customizable-timeouts
// Based on the tests, Flink API Key takes about 10 seconds to sync
Timeout: 20 * time.Minute,
Delay: 10 * time.Second,
PollInterval: 30 * time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Flink API Key %q to sync", c.flinkApiKey), map[string]interface{}{apiKeyLoggingKey: c.flinkApiKey})
if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return err
}
return nil
}
func waitForCreatedCloudApiKeyToSync(ctx context.Context, c *Client, cloudApiKey, cloudApiSecret string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: cloudApiKeySyncStatus(ctx, c, cloudApiKey, cloudApiSecret),
// Default timeout for a resource
// https://www.terraform.io/plugin/sdkv2/resources/retries-and-customizable-timeouts
// Based on the tests, Cloud API Key takes about 10 seconds to sync (or even faster)
Timeout: 20 * time.Minute,
Delay: 15 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Cloud API Key %q to sync", cloudApiKey), map[string]interface{}{apiKeyLoggingKey: cloudApiKey})
if _, err := stateConf.WaitForStateContext(c.orgApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForKafkaClusterToProvision(ctx context.Context, c *Client, environmentId, clusterId, clusterType string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateProvisioned},
Refresh: kafkaClusterProvisionStatus(c.cmkApiContext(ctx), c, environmentId, clusterId),
// https://docs.confluent.io/cloud/current/clusters/cluster-types.html#provisioning-time
Timeout: getTimeoutFor(clusterType),
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka Cluster %q provisioning status to become %q", clusterId, stateProvisioned), map[string]interface{}{kafkaClusterLoggingKey: clusterId})
if _, err := stateConf.WaitForStateContext(c.cmkApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForKsqlClusterToProvision(ctx context.Context, c *Client, environmentId, clusterId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateProvisioned},
Refresh: ksqlClusterProvisionStatus(c.ksqlApiContext(ctx), c, environmentId, clusterId),
Timeout: ksqlCreateTimeout,
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for ksqlDB Cluster %q provisioning status to become %v", clusterId, []string{stateUp, stateProvisioned}), map[string]interface{}{ksqlClusterLoggingKey: clusterId})
if _, err := stateConf.WaitForStateContext(c.ksqlApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForPrivateLinkAccessToProvision(ctx context.Context, c *Client, environmentId, privateLinkAccessId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: privateLinkAccessProvisionStatus(c.netApiContext(ctx), c, environmentId, privateLinkAccessId),
Timeout: networkingAPICreateTimeout,
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Private Link Access %q provisioning status to become %q", privateLinkAccessId, stateReady), map[string]interface{}{privateLinkAccessLoggingKey: privateLinkAccessId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForPrivateLinkAttachmentToProvision(ctx context.Context, c *Client, environmentId, privateLinkAttachmentId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady, stateWaitingForConnections},
Refresh: privateLinkAttachmentProvisionStatus(c.netPLApiContext(ctx), c, environmentId, privateLinkAttachmentId),
Timeout: networkingAPICreateTimeout,
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Private Link Attachment %q provisioning status to become %q", privateLinkAttachmentId, stateWaitingForConnections), map[string]interface{}{privateLinkAttachmentLoggingKey: privateLinkAttachmentId})
if _, err := stateConf.WaitForStateContext(c.netPLApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForPrivateLinkAttachmentConnectionToProvision(ctx context.Context, c *Client, environmentId, privateLinkAttachmentConnectionId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: privateLinkAttachmentConnectionProvisionStatus(c.netPLApiContext(ctx), c, environmentId, privateLinkAttachmentConnectionId),
Timeout: networkingAPICreateTimeout,
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Private Link Attachment Connection %q provisioning status to become %q", privateLinkAttachmentConnectionId, stateReady), map[string]interface{}{privateLinkAttachmentConnectionLoggingKey: privateLinkAttachmentConnectionId})
if _, err := stateConf.WaitForStateContext(c.netPLApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForNetworkLinkServiceToProvision(ctx context.Context, c *Client, environmentId, nlsId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: nlsProvisionStatus(c.netApiContext(ctx), c, environmentId, nlsId),
Timeout: networkingAPICreateTimeout,
// TODO: increase delay
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Network Link Service %q provisioning status to become %q", nlsId, stateReady), map[string]interface{}{networkLinkServiceLoggingKey: nlsId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForNetworkToProvision(ctx context.Context, c *Client, environmentId, networkId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: networkProvisionStatus(c.netApiContext(ctx), c, environmentId, networkId),
Timeout: networkingAPICreateTimeout,
// TODO: increase delay
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Network %q provisioning status to become %q", networkId, stateReady), map[string]interface{}{networkLoggingKey: networkId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForFlinkStatementToProvision(ctx context.Context, c *FlinkRestClient, statementName string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{statePending},
Target: []string{stateRunning, stateCompleted},
Refresh: flinkStatementProvisionStatus(c.apiContext(ctx), c, statementName),
// Default timeout
Timeout: 20 * time.Minute,
Delay: 5 * time.Second,
PollInterval: 10 * time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Flink Statement %q provisioning status to become %q", statementName, stateReady), map[string]interface{}{flinkStatementLoggingKey: statementName})
if _, err := stateConf.WaitForStateContext(c.apiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForNetworkLinkEndpointToProvision(ctx context.Context, c *Client, environmentId, nleId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady, statePendingAccept, stateInactive},
Refresh: nleProvisionStatus(c.netApiContext(ctx), c, environmentId, nleId),
Timeout: networkingAPICreateTimeout,
// TODO: increase delay
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Network Link Endpoint %q provisioning status to become %q", nleId, stateReady), map[string]interface{}{networkLinkEndpointLoggingKey: nleId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForDnsRecordToProvision(ctx context.Context, c *Client, environmentId, dnsRecordId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady, stateCreated},
Refresh: dnsRecordProvisionStatus(c.netAPApiContext(ctx), c, environmentId, dnsRecordId),
Timeout: networkingAPICreateTimeout,
// TODO: increase delay
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for DNS Record %q provisioning status to become %q", dnsRecordId, stateCreated), map[string]interface{}{dnsRecordKey: dnsRecordId})
if _, err := stateConf.WaitForStateContext(c.netAPApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForAccessPointToProvision(ctx context.Context, c *Client, environmentId, accessPointId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady, statePendingAccept},
Refresh: accessPointProvisionStatus(c.netAPApiContext(ctx), c, environmentId, accessPointId),
Timeout: networkingAPICreateTimeout,
// TODO: increase delay
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Access Point %q provisioning status to become %q", accessPointId, stateReady), map[string]interface{}{accessPointKey: accessPointId})
if _, err := stateConf.WaitForStateContext(c.netAPApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForComputePoolToProvision(ctx context.Context, c *Client, environmentId, computePoolId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateProvisioned},
Refresh: computePoolProvisionStatus(c.fcpmApiContext(ctx), c, environmentId, computePoolId),
Timeout: fcpmAPICreateTimeout,
// TODO: increase delay
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Flink Compute Pool %q provisioning status to become %q", computePoolId, stateProvisioned), map[string]interface{}{computePoolLoggingKey: computePoolId})
if _, err := stateConf.WaitForStateContext(c.fcpmApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForSchemaRegistryClusterToProvision(ctx context.Context, c *Client, environmentId, clusterId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateProvisioned},
Refresh: schemaRegistryClusterProvisionStatus(c.srcmApiContext(ctx), c, environmentId, clusterId),
// https://docs.confluent.io/cloud/current/clusters/cluster-types.html#provisioning-time
Timeout: 1 * time.Hour,
Delay: 5 * time.Second,
PollInterval: 30 * time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Schema Registry Cluster %q provisioning status to become %q", clusterId, stateProvisioned), map[string]interface{}{schemaRegistryClusterLoggingKey: clusterId})
if _, err := stateConf.WaitForStateContext(c.srcmApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForConnectorToProvision(ctx context.Context, c *Client, displayName, environmentId, clusterId string) error {
stateConf := &resource.StateChangeConf{
// Allow PROVISIONING -> DEGRADED -> RUNNING transition
Pending: []string{stateProvisioning, stateDegraded},
Target: []string{stateRunning},
Refresh: connectorProvisionStatus(c.connectApiContext(ctx), c, displayName, environmentId, clusterId),
Timeout: connectAPICreateTimeout,
Delay: 6 * time.Minute,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Connector %q=%q provisioning status to become %q", paramDisplayName, displayName, stateRunning))
if _, err := stateConf.WaitForStateContext(c.connectApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForConnectorToChangeStatus(ctx context.Context, c *Client, displayName, environmentId, clusterId, currentStatus, targetStatus string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{currentStatus},
Target: []string{targetStatus},
Refresh: connectorUpdateStatus(c.connectApiContext(ctx), c, displayName, environmentId, clusterId),
Timeout: 1 * time.Hour,
Delay: 30 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Connector %q=%q status to become %q", paramDisplayName, displayName, targetStatus))
if _, err := stateConf.WaitForStateContext(c.connectApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForKafkaMirrorTopicToChangeStatus(ctx context.Context, c *KafkaRestClient, clusterId, linkName, mirrorTopicName, currentStatus, targetStatus string) error {
pendingStatuses := []string{currentStatus}
if targetStatus == stateStopped {
pendingStatuses = append(pendingStatuses, statePendingStopped)
}
stateConf := &resource.StateChangeConf{
Pending: pendingStatuses,
Target: []string{targetStatus},
Refresh: kafkaMirrorTopicUpdateStatus(c.apiContext(ctx), c, clusterId, linkName, mirrorTopicName),
Timeout: 5 * time.Minute,
Delay: 2 * time.Second,
PollInterval: 1 * time.Minute,
}
kafkaMirrorTopicId := createKafkaMirrorTopicId(clusterId, linkName, mirrorTopicName)
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka Mirror Topic %q to be deleted", kafkaMirrorTopicId), map[string]interface{}{kafkaMirrorTopicLoggingKey: kafkaMirrorTopicId})
if _, err := stateConf.WaitForStateContext(c.apiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForPeeringToProvision(ctx context.Context, c *Client, environmentId, peeringId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady, statePendingAccept},
Refresh: peeringProvisionStatus(c.netApiContext(ctx), c, environmentId, peeringId),
Timeout: networkingAPICreateTimeout,
// TODO: increase delay
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Peering %q provisioning status to become %q", peeringId, statePendingAccept), map[string]interface{}{networkLoggingKey: peeringId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForTagToProvision(ctx context.Context, c *SchemaRegistryRestClient, tagId, tagName string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: tagProvisionStatus(c.dataCatalogApiContext(ctx), c, tagId, tagName),
Timeout: dataCatalogTimeout,
PollInterval: time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Tag %q provisioning status to become %q", tagId, stateReady), map[string]interface{}{tagLoggingKey: tagId})
if _, err := stateConf.WaitForStateContext(c.dataCatalogApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForBusinessMetadataToProvision(ctx context.Context, c *SchemaRegistryRestClient, businessMetadataId, businessMetadataName string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: businessMetadataProvisionStatus(c.dataCatalogApiContext(ctx), c, businessMetadataId, businessMetadataName),
Timeout: dataCatalogTimeout,
PollInterval: time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Business Metadata %q provisioning status to become %q", businessMetadataId, stateReady), map[string]interface{}{businessMetadataLoggingKey: businessMetadataId})
if _, err := stateConf.WaitForStateContext(c.dataCatalogApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForTagBindingToProvision(ctx context.Context, c *SchemaRegistryRestClient, tagBindingId, tagName, entityName, entityType string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: tagBindingProvisionStatus(c.dataCatalogApiContext(ctx), c, tagBindingId, tagName, entityName, entityType),
Timeout: dataCatalogTimeout,
PollInterval: time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Tag Binding %q provisioning status to become %q", tagBindingId, stateReady), map[string]interface{}{tagBindingLoggingKey: tagBindingId})
if _, err := stateConf.WaitForStateContext(c.dataCatalogApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForBusinessMetadataBindingToProvision(ctx context.Context, c *SchemaRegistryRestClient, businessMetadataBindingId, businessMetadataName, entityName, entityType string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: businessMetadataBindingProvisionStatus(c.dataCatalogApiContext(ctx), c, businessMetadataBindingId, businessMetadataName, entityName, entityType),
Timeout: dataCatalogTimeout,
PollInterval: time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Business Metadata Binding %q provisioning status to become %q", businessMetadataBindingId, stateReady), map[string]interface{}{businessMetadataBindingLoggingKey: businessMetadataBindingId})
if _, err := stateConf.WaitForStateContext(c.dataCatalogApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForSchemaExporterToProvision(ctx context.Context, c *SchemaRegistryRestClient, id, name string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady},
Refresh: schemaExporterProvisionStatus(c.apiContext(ctx), c, id, name),
Timeout: dataCatalogExporterTimeout,
PollInterval: 30 * time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Schema Exporter %q provisioning status to become %q", id, stateReady), map[string]interface{}{schemaExporterLoggingKey: id})
if _, err := stateConf.WaitForStateContext(c.apiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForTransitGatewayAttachmentToProvision(ctx context.Context, c *Client, environmentId, transitGatewayAttachmentId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateProvisioning},
Target: []string{stateReady, statePendingAccept},
Refresh: transitGatewayAttachmentProvisionStatus(c.netApiContext(ctx), c, environmentId, transitGatewayAttachmentId),
Timeout: networkingAPICreateTimeout,
// TODO: increase delay
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Transit Gateway Attachment %q provisioning status to become %q", transitGatewayAttachmentId, statePendingAccept), map[string]interface{}{transitGatewayAttachmentLoggingKey: transitGatewayAttachmentId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForKafkaClusterCkuUpdateToComplete(ctx context.Context, c *Client, environmentId, clusterId string, cku int32) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: kafkaClusterCkuUpdateStatus(c.cmkApiContext(ctx), c, environmentId, clusterId, cku),
// https://docs.confluent.io/cloud/current/clusters/cluster-types.html#resizing-time
Timeout: getTimeoutFor(kafkaClusterTypeDedicated),
Delay: 5 * time.Second,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka Cluster %q CKU update", clusterId), map[string]interface{}{kafkaClusterLoggingKey: clusterId})
if _, err := stateConf.WaitForStateContext(c.cmkApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForDnsRecordToBeDeleted(ctx context.Context, c *Client, environmentId, dnsRecordId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: dnsRecordDeleteStatus(c.netAPApiContext(ctx), c, environmentId, dnsRecordId),
Timeout: networkingAPIDeleteTimeout,
Delay: 1 * time.Minute,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for DNS Record %q to be deleted", dnsRecordId), map[string]interface{}{dnsRecordKey: dnsRecordId})
if _, err := stateConf.WaitForStateContext(c.netAPApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForPrivateLinkAccessToBeDeleted(ctx context.Context, c *Client, environmentId, privateLinkAccessId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: privateLinkAccessDeleteStatus(c.netApiContext(ctx), c, environmentId, privateLinkAccessId),
Timeout: networkingAPIDeleteTimeout,
Delay: 1 * time.Minute,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Private Link Access %q to be deleted", privateLinkAccessId), map[string]interface{}{privateLinkAccessLoggingKey: privateLinkAccessId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForPrivateLinkAttachmentConnectionToBeDeleted(ctx context.Context, c *Client, environmentId, plattcId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: plattcDeleteStatus(c.netPLApiContext(ctx), c, environmentId, plattcId),
Timeout: networkingAPIDeleteTimeout,
Delay: 1 * time.Minute,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for private link attachment connection %q to be deleted", plattcId), map[string]interface{}{privateLinkAttachmentConnectionLoggingKey: plattcId})
if _, err := stateConf.WaitForStateContext(c.netPLApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForPeeringToBeDeleted(ctx context.Context, c *Client, environmentId, peeringId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: peeringDeleteStatus(c.netApiContext(ctx), c, environmentId, peeringId),
Timeout: networkingAPIDeleteTimeout,
Delay: 1 * time.Minute,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Peering %q to be deleted", peeringId), map[string]interface{}{peeringLoggingKey: peeringId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForNetworkLinkEndpointToBeDeleted(ctx context.Context, c *Client, environmentId, nleId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: nleDeleteStatus(c.netApiContext(ctx), c, environmentId, nleId),
Timeout: networkingAPIDeleteTimeout,
Delay: 1 * time.Minute,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Network Link Endpoint %q to be deleted", nleId), map[string]interface{}{networkLinkEndpointLoggingKey: nleId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForTransitGatewayAttachmentToBeDeleted(ctx context.Context, c *Client, environmentId, transitGatewayAttachmentId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: transitGatewayAttachmentDeleteStatus(c.netApiContext(ctx), c, environmentId, transitGatewayAttachmentId),
Timeout: networkingAPIDeleteTimeout,
Delay: 1 * time.Minute,
PollInterval: 1 * time.Minute,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Transit Gateway Attachment %q to be deleted", transitGatewayAttachmentId), map[string]interface{}{transitGatewayAttachmentLoggingKey: transitGatewayAttachmentId})
if _, err := stateConf.WaitForStateContext(c.netApiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForKafkaTopicToBeDeleted(ctx context.Context, c *KafkaRestClient, topicName string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: kafkaTopicDeleteStatus(c.apiContext(ctx), c, topicName),
Timeout: 1 * time.Hour,
Delay: 10 * time.Second,
PollInterval: 1 * time.Minute,
}
topicId := createKafkaTopicId(c.clusterId, topicName)
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka Topic %q to be deleted", topicId), map[string]interface{}{kafkaTopicLoggingKey: topicId})
if _, err := stateConf.WaitForStateContext(c.apiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForFlinkStatementToBeDeleted(ctx context.Context, c *FlinkRestClient, statementName string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: flinkStatementDeleteStatus(c.apiContext(ctx), c, statementName),
// Default timeout
Timeout: 20 * time.Minute,
Delay: 10 * time.Second,
PollInterval: 10 * time.Second,
}
statementId := createFlinkStatementId(c.environmentId, c.computePoolId, statementName)
tflog.Debug(ctx, fmt.Sprintf("Waiting for Flink Statement %q to be deleted", statementId), map[string]interface{}{flinkStatementLoggingKey: statementId})
if _, err := stateConf.WaitForStateContext(c.apiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForFlinkStatementToBeStopped(ctx context.Context, c *FlinkRestClient, statementName string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{statePending, stateRunning, stateCompleted},
Target: []string{stateStopped},
Refresh: flinkStatementStoppingStatus(c.apiContext(ctx), c, statementName),
// Default timeout
Timeout: 20 * time.Minute,
Delay: 5 * time.Second,
PollInterval: 10 * time.Second,
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Flink Statement %q stopping status to become %q", statementName, stateStopped), map[string]interface{}{flinkStatementLoggingKey: statementName})
if _, err := stateConf.WaitForStateContext(c.apiContext(ctx)); err != nil {
return err
}
return nil
}
func waitForKafkaMirrorTopicToBeDeleted(ctx context.Context, c *KafkaRestClient, linkName, mirrorTopicName string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: kafkaMirrorTopicDeleteStatus(c.apiContext(ctx), c, linkName, mirrorTopicName),
Timeout: 1 * time.Hour,
Delay: 10 * time.Second,
PollInterval: 1 * time.Minute,
}
kafkaMirrorTopicId := createKafkaMirrorTopicId(c.clusterId, linkName, mirrorTopicName)
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka Topic %q to be deleted", kafkaMirrorTopicId), map[string]interface{}{kafkaMirrorTopicLoggingKey: kafkaMirrorTopicId})
if _, err := stateConf.WaitForStateContext(c.apiContext(ctx)); err != nil {
return err
}
return nil
}
func flinkStatementDeleteStatus(ctx context.Context, c *FlinkRestClient, statementName string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
statement, resp, err := executeFlinkStatementRead(c.apiContext(ctx), c, statementName)
statementId := createFlinkStatementId(c.environmentId, c.computePoolId, statementName)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Flink Statement %q: %s", statementName, createDescriptiveError(err)), map[string]interface{}{flinkStatementLoggingKey: statementId})
isResourceNotFound := isNonKafkaRestApiResourceNotFound(resp)
if isResourceNotFound {
tflog.Debug(ctx, fmt.Sprintf("Finishing Flink Statement %q deletion process: Received %d status code when reading %q Flink Statement", statementName, resp.StatusCode, statementName), map[string]interface{}{flinkStatementLoggingKey: statementId})
return 0, stateDone, nil
} else {
tflog.Debug(ctx, fmt.Sprintf("Exiting Flink Statement %q deletion process: Failed when reading Flink Statement: %s", statementName, createDescriptiveError(err)), map[string]interface{}{flinkStatementLoggingKey: statementId})
return nil, stateFailed, err
}
}
tflog.Debug(ctx, fmt.Sprintf("Performing Flink Statement %q deletion process: Flink Statement %d's status is %q", statementName, resp.StatusCode, statement.Status.GetPhase()), map[string]interface{}{flinkStatementLoggingKey: statementId})
return statement, stateInProgress, nil
}
}
func kafkaTopicDeleteStatus(ctx context.Context, c *KafkaRestClient, topicName string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
kafkaTopic, resp, err := c.apiClient.TopicV3Api.GetKafkaTopic(c.apiContext(ctx), c.clusterId, topicName).Execute()
topicId := createKafkaTopicId(c.clusterId, topicName)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Kafka Topic %q: %s", topicId, createDescriptiveError(err)), map[string]interface{}{kafkaTopicLoggingKey: topicId})
// 404 means that the topic has been deleted
isResourceNotFound := ResponseHasExpectedStatusCode(resp, http.StatusNotFound)
if isResourceNotFound {
// Result (the 1st argument) can't be nil
return 0, stateDone, nil
} else {
return nil, stateFailed, err
}
}
return kafkaTopic, stateInProgress, nil
}
}
func kafkaMirrorTopicDeleteStatus(ctx context.Context, c *KafkaRestClient, linkName, mirrorTopicName string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
kafkaTopic, resp, err := c.apiClient.ClusterLinkingV3Api.ReadKafkaMirrorTopic(c.apiContext(ctx), c.clusterId, linkName, mirrorTopicName).Execute()
kafkaMirrorTopicId := createKafkaMirrorTopicId(c.clusterId, linkName, mirrorTopicName)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Kafka Mirror Topic %q: %s", kafkaMirrorTopicId, createDescriptiveError(err)), map[string]interface{}{kafkaMirrorTopicLoggingKey: kafkaMirrorTopicId})
// 404 means that the topic has been deleted
isResourceNotFound := ResponseHasExpectedStatusCode(resp, http.StatusNotFound)
if isResourceNotFound {
// Result (the 1st argument) can't be nil
return 0, stateDone, nil
} else {
return nil, stateFailed, err
}
}
return kafkaTopic, stateInProgress, nil
}
}
func plattcDeleteStatus(ctx context.Context, c *Client, environmentId, plattcId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
plattc, resp, err := executePlattcRead(c.netPLApiContext(ctx), c, environmentId, plattcId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Private Link Attachment Connection %q: %s", plattcId, createDescriptiveError(err)), map[string]interface{}{privateLinkAttachmentConnectionLoggingKey: plattcId})
isResourceNotFound := isNonKafkaRestApiResourceNotFound(resp)
if isResourceNotFound {
tflog.Debug(ctx, fmt.Sprintf("Finishing Private Link Attachment Connection %q deletion process: Received %d status code when reading %q Plattc", plattcId, resp.StatusCode, plattcId), map[string]interface{}{privateLinkAttachmentConnectionLoggingKey: plattcId})
return 0, stateDone, nil
} else {
tflog.Debug(ctx, fmt.Sprintf("Exiting Private Link Attachment Connection %q deletion process: Failed when reading Plattc: %s: %s", plattcId, createDescriptiveError(err), plattc.Status.GetErrorMessage()), map[string]interface{}{privateLinkAttachmentConnectionLoggingKey: plattcId})
return nil, stateFailed, err
}
}
tflog.Debug(ctx, fmt.Sprintf("Performing Private Link Attachment Connection %q deletion process: private link attachment connection %d's status is %q", plattcId, resp.StatusCode, plattc.Status.GetPhase()), map[string]interface{}{privateLinkAttachmentConnectionLoggingKey: plattcId})
return plattc, stateInProgress, nil
}
}
func waitForClusterLinkToBeDeleted(ctx context.Context, c *KafkaRestClient, linkName string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{stateInProgress},
Target: []string{stateDone},
Refresh: clusterLinkDeleteStatus(c.apiContext(ctx), c, linkName),
Timeout: 1 * time.Hour,
Delay: 10 * time.Second,
PollInterval: 1 * time.Minute,
}
topicId := createClusterLinkId(c.clusterId, linkName)
tflog.Debug(ctx, fmt.Sprintf("Waiting for Cluster Link %q to be deleted", topicId), map[string]interface{}{clusterLinkLoggingKey: topicId})
if _, err := stateConf.WaitForStateContext(c.apiContext(ctx)); err != nil {
return err
}
return nil
}
func clusterLinkDeleteStatus(ctx context.Context, c *KafkaRestClient, linkName string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
clusterLink, resp, err := c.apiClient.ClusterLinkingV3Api.GetKafkaLink(c.apiContext(ctx), c.clusterId, linkName).Execute()
clusterLinkId := createClusterLinkId(c.clusterId, linkName)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Cluster Link %q: %s", clusterLinkId, createDescriptiveError(err)), map[string]interface{}{clusterLinkLoggingKey: clusterLinkId})
// 404 means that the cluster link has been deleted
isResourceNotFound := ResponseHasExpectedStatusCode(resp, http.StatusNotFound)
if isResourceNotFound {
// Result (the 1st argument) can't be nil
return 0, stateDone, nil
} else {
return nil, stateFailed, err
}
}
return clusterLink, stateInProgress, nil
}
}
func kafkaClusterCkuUpdateStatus(ctx context.Context, c *Client, environmentId string, clusterId string, desiredCku int32) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
cluster, _, err := executeKafkaRead(c.cmkApiContext(ctx), c, environmentId, clusterId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Kafka Cluster %q: %s", clusterId, createDescriptiveError(err)), map[string]interface{}{kafkaClusterLoggingKey: clusterId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka Cluster %q CKU update", clusterId), map[string]interface{}{kafkaClusterLoggingKey: clusterId})
// Wail until actual # of CKUs is the same as desired one
// spec.cku is the user’s desired # of CKUs, and status.cku is the current # of CKUs in effect
// because the change is still pending, for example
// Use desiredCku on the off chance that API will not work as expected (i.e., spec.cku = status.cku during expansion).
// CAPAC-293
if cluster.Status.GetCku() == cluster.Spec.Config.CmkV2Dedicated.Cku && cluster.Status.GetCku() == desiredCku {
return cluster, stateDone, nil
}
return cluster, stateInProgress, nil
}
}
func kafkaClusterProvisionStatus(ctx context.Context, c *Client, environmentId string, clusterId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
cluster, _, err := executeKafkaRead(c.cmkApiContext(ctx), c, environmentId, clusterId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Kafka Cluster %q: %s", clusterId, createDescriptiveError(err)), map[string]interface{}{kafkaClusterLoggingKey: clusterId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Kafka Cluster %q provisioning status to become %q: current status is %q", clusterId, stateProvisioned, cluster.Status.GetPhase()), map[string]interface{}{kafkaClusterLoggingKey: clusterId})
if cluster.Status.GetPhase() == stateProvisioning || cluster.Status.GetPhase() == stateProvisioned {
return cluster, cluster.Status.GetPhase(), nil
} else if cluster.Status.GetPhase() == stateFailed {
return nil, stateFailed, fmt.Errorf("kafka Cluster %q provisioning status is %q", clusterId, stateFailed)
}
// Kafka Cluster is in an unexpected state
return nil, stateUnexpected, fmt.Errorf("kafka Cluster %q is an unexpected state %q", clusterId, cluster.Status.GetPhase())
}
}
func ksqlClusterProvisionStatus(ctx context.Context, c *Client, environmentId, clusterId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
cluster, _, err := executeKsqlRead(c.ksqlApiContext(ctx), c, environmentId, clusterId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading ksqlDB Cluster %q: %s", clusterId, createDescriptiveError(err)), map[string]interface{}{ksqlClusterLoggingKey: clusterId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for ksqlDB Cluster %q provisioning status to become %q: current status is %q", clusterId, stateProvisioned, cluster.Status.GetPhase()), map[string]interface{}{ksqlClusterLoggingKey: clusterId})
if cluster.Status.GetPhase() == stateProvisioning || cluster.Status.GetPhase() == stateProvisioned {
return cluster, cluster.Status.GetPhase(), nil
} else if cluster.Status.GetPhase() == stateFailed {
return nil, stateFailed, fmt.Errorf("ksqlDB Cluster %q provisioning status is %q", clusterId, stateFailed)
}
// ksqlDB Cluster is in an unexpected state
return nil, stateUnexpected, fmt.Errorf("ksqlDB Cluster %q is an unexpected state %q", clusterId, cluster.Status.GetPhase())
}
}
func schemaRegistryClusterProvisionStatus(ctx context.Context, c *Client, environmentId string, clusterId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
cluster, _, err := executeSchemaRegistryClusterRead(c.srcmApiContext(ctx), c, environmentId, clusterId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Schema Registry Cluster %q: %s", clusterId, createDescriptiveError(err)), map[string]interface{}{schemaRegistryClusterLoggingKey: clusterId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Schema Registry Cluster %q provisioning status to become %q: current status is %q", clusterId, stateProvisioned, cluster.Status.GetPhase()), map[string]interface{}{schemaRegistryClusterLoggingKey: clusterId})
if cluster.Status.GetPhase() == stateProvisioning || cluster.Status.GetPhase() == stateProvisioned {
return cluster, cluster.Status.GetPhase(), nil
} else if cluster.Status.GetPhase() == stateFailed {
return nil, stateFailed, fmt.Errorf("schema Registry Cluster %q provisioning status is %q", clusterId, stateFailed)
}
// SR Cluster is in an unexpected state
return nil, stateUnexpected, fmt.Errorf("schema Registry Cluster %q is an unexpected state %q", clusterId, cluster.Status.GetPhase())
}
}
func privateLinkAccessProvisionStatus(ctx context.Context, c *Client, environmentId string, privateLinkAccessId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
privateLinkAccess, _, err := executePrivateLinkAccessRead(c.netApiContext(ctx), c, environmentId, privateLinkAccessId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Private Link Access %q: %s", privateLinkAccessId, createDescriptiveError(err)), map[string]interface{}{privateLinkAccessLoggingKey: privateLinkAccessId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Private Link Access %q provisioning status to become %q: current status is %q", privateLinkAccessId, stateReady, privateLinkAccess.Status.GetPhase()), map[string]interface{}{privateLinkAccessLoggingKey: privateLinkAccessId})
if privateLinkAccess.Status.GetPhase() == stateProvisioning || privateLinkAccess.Status.GetPhase() == stateReady {
return privateLinkAccess, privateLinkAccess.Status.GetPhase(), nil
} else if privateLinkAccess.Status.GetPhase() == stateFailed {
return nil, stateFailed, fmt.Errorf("private Link Access %q provisioning status is %q: %s", privateLinkAccessId, stateFailed, privateLinkAccess.Status.GetErrorMessage())
}
// Private Link Access is in an unexpected state
return nil, stateUnexpected, fmt.Errorf("private Link Access %q is an unexpected state %q: %s", privateLinkAccessId, privateLinkAccess.Status.GetPhase(), privateLinkAccess.Status.GetErrorMessage())
}
}
func privateLinkAttachmentProvisionStatus(ctx context.Context, c *Client, environmentId string, privateLinkAttachmentId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
privateLinkAttachment, _, err := executePlattRead(c.netPLApiContext(ctx), c, privateLinkAttachmentId, environmentId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Private Link Attachment %q: %s", privateLinkAttachmentId, createDescriptiveError(err)), map[string]interface{}{privateLinkAttachmentLoggingKey: privateLinkAttachmentId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Private Link Attachment %q provisioning status to become %q: current status is %q", privateLinkAttachmentId, stateWaitingForConnections, privateLinkAttachment.Status.GetPhase()), map[string]interface{}{privateLinkAttachmentLoggingKey: privateLinkAttachmentId})
if privateLinkAttachment.Status.GetPhase() == stateProvisioning || privateLinkAttachment.Status.GetPhase() == stateReady || privateLinkAttachment.Status.GetPhase() == stateWaitingForConnections {
return privateLinkAttachment, privateLinkAttachment.Status.GetPhase(), nil
} else if privateLinkAttachment.Status.GetPhase() == stateFailed {
return nil, stateFailed, fmt.Errorf("private Link Attachment %q provisioning status is %q: %s", privateLinkAttachmentId, stateFailed, privateLinkAttachment.Status.GetErrorMessage())
}
// Private Link Attachment is in an unexpected state
return nil, stateUnexpected, fmt.Errorf("private Link Attachment %q is an unexpected state %q: %s", privateLinkAttachmentId, privateLinkAttachment.Status.GetPhase(), privateLinkAttachment.Status.GetErrorMessage())
}
}
func privateLinkAttachmentConnectionProvisionStatus(ctx context.Context, c *Client, environmentId string, privateLinkAttachmentConnectionId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
privateLinkAttachmentConnection, _, err := executePlattcRead(c.netPLApiContext(ctx), c, privateLinkAttachmentConnectionId, environmentId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Private Link Attachment Connection %q: %s", privateLinkAttachmentConnectionId, createDescriptiveError(err)), map[string]interface{}{privateLinkAttachmentConnectionLoggingKey: privateLinkAttachmentConnectionId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Private Link Attachment Connection %q provisioning status to become %q: current status is %q", privateLinkAttachmentConnectionId, stateReady, privateLinkAttachmentConnection.Status.GetPhase()), map[string]interface{}{privateLinkAttachmentConnectionLoggingKey: privateLinkAttachmentConnectionId})
if privateLinkAttachmentConnection.Status.GetPhase() == stateProvisioning || privateLinkAttachmentConnection.Status.GetPhase() == stateReady {
return privateLinkAttachmentConnection, privateLinkAttachmentConnection.Status.GetPhase(), nil
} else if privateLinkAttachmentConnection.Status.GetPhase() == stateFailed {
return nil, stateFailed, fmt.Errorf("private Link Attachment Connection %q provisioning status is %q: %s", privateLinkAttachmentConnectionId, stateFailed, privateLinkAttachmentConnection.Status.GetErrorMessage())
}
// Private Link Attachment Connection is in an unexpected state
return nil, stateUnexpected, fmt.Errorf("private Link Attachment Connection %q is an unexpected state %q: %s", privateLinkAttachmentConnectionId, privateLinkAttachmentConnection.Status.GetPhase(), privateLinkAttachmentConnection.Status.GetErrorMessage())
}
}
func nlsProvisionStatus(ctx context.Context, c *Client, environmentId string, nlsId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
nls, _, err := executeNLSRead(c.netApiContext(ctx), c, nlsId, environmentId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Network Link Service %q: %s", nlsId, createDescriptiveError(err)), map[string]interface{}{networkLinkServiceLoggingKey: nlsId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Network Link Service %q provisioning status to become %q: current status is %q", nlsId, stateReady, nls.Status.GetPhase()), map[string]interface{}{networkLinkServiceLoggingKey: nlsId})
if nls.Status.GetPhase() == stateProvisioning || nls.Status.GetPhase() == stateReady {
return nls, nls.Status.GetPhase(), nil
} else if nls.Status.GetPhase() == stateFailed {
return nil, stateFailed, fmt.Errorf("network link service %q provisioning status is %q: %s", nlsId, stateFailed, nls.Status.GetErrorMessage())
}
// Network is in an unexpected state
return nil, stateUnexpected, fmt.Errorf("network link service %q is an unexpected state %q: %s", nlsId, nls.Status.GetPhase(), nls.Status.GetErrorMessage())
}
}
func networkProvisionStatus(ctx context.Context, c *Client, environmentId string, networkId string) resource.StateRefreshFunc {
return func() (result interface{}, s string, err error) {
network, _, err := executeNetworkRead(c.netApiContext(ctx), c, environmentId, networkId)
if err != nil {
tflog.Warn(ctx, fmt.Sprintf("Error reading Network %q: %s", networkId, createDescriptiveError(err)), map[string]interface{}{networkLoggingKey: networkId})
return nil, stateUnknown, err
}
tflog.Debug(ctx, fmt.Sprintf("Waiting for Network %q provisioning status to become %q: current status is %q", networkId, stateReady, network.Status.GetPhase()), map[string]interface{}{networkLoggingKey: networkId})
if network.Status.GetPhase() == stateProvisioning || network.Status.GetPhase() == stateReady {
return network, network.Status.GetPhase(), nil
} else if network.Status.GetPhase() == stateFailed {
return nil, stateFailed, fmt.Errorf("network %q provisioning status is %q: %s", networkId, stateFailed, network.Status.GetErrorMessage())
}
// Network is in an unexpected state
return nil, stateUnexpected, fmt.Errorf("network %q is an unexpected state %q: %s", networkId, network.Status.GetPhase(), network.Status.GetErrorMessage())
}
}