-
Notifications
You must be signed in to change notification settings - Fork 669
/
data_source_ibm_cd_tekton_pipeline.go
1105 lines (1059 loc) · 38.4 KB
/
data_source_ibm_cd_tekton_pipeline.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 IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package cdtektonpipeline
import (
"context"
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM/continuous-delivery-go-sdk/cdtektonpipelinev2"
)
func DataSourceIBMCdTektonPipeline() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMCdTektonPipelineRead,
Schema: map[string]*schema.Schema{
"pipeline_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "ID of current instance.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "String.",
},
"status": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Pipeline status.",
},
"resource_group": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The resource group in which the pipeline was created.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID.",
},
},
},
},
"toolchain": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Toolchain object containing references to the parent toolchain.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "UUID.",
},
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for the toolchain that contains the Tekton pipeline.",
},
},
},
},
"definitions": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Definition list.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"source": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Source repository containing the Tekton pipeline definition.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The only supported source type is \"git\", indicating that the source is a git repository.",
},
"properties": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Properties of the source, which define the URL of the repository and a branch or tag.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"url": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "URL of the definition repository.",
},
"branch": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A branch from the repo, specify one of branch or tag only.",
},
"tag": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A tag from the repo, specify one of branch or tag only.",
},
"path": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The path to the definition's YAML files.",
},
"tool": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Reference to the repository tool in the parent toolchain.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID of the repository tool instance in the parent toolchain.",
},
},
},
},
},
},
},
},
},
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "API URL for interacting with the definition.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The aggregated definition ID.",
},
},
},
},
"properties": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Tekton pipeline's environment properties.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Property name.",
},
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Property value. Any string value is valid.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "API URL for interacting with the property.",
},
"enum": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Options for `single_select` property type. Only needed when using `single_select` property type.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Property type.",
},
"locked": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "When true, this property cannot be overridden by a trigger property or at runtime. Attempting to override it will result in run requests being rejected. The default is false.",
},
"path": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used.",
},
},
},
},
"updated_at": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Standard RFC 3339 Date Time String.",
},
"created_at": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Standard RFC 3339 Date Time String.",
},
"triggers": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Tekton pipeline triggers list.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Trigger type.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Trigger name.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "API URL for interacting with the trigger. Only included when fetching the list of pipeline triggers.",
},
"event_listener": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Event listener name. The name of the event listener to which the trigger is associated. The event listeners are defined in the definition repositories of the Tekton pipeline.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The Trigger ID.",
},
"properties": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Optional trigger properties used to override or supplement the pipeline properties when triggering a pipeline run.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Property name.",
},
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Property value. Any string value is valid.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "API URL for interacting with the trigger property.",
},
"enum": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Options for `single_select` property type. Only needed for `single_select` property type.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Property type.",
},
"path": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A dot notation path for `integration` type properties only, that selects a value from the tool integration. If left blank the full tool integration data will be used.",
},
"locked": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "When true, this property cannot be overridden at runtime. Attempting to override it will result in run requests being rejected. The default is false.",
},
},
},
},
"tags": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Optional trigger tags array.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"worker": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Details of the worker used to run the trigger.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Name of the worker. Computed based on the worker ID.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Type of the worker. Computed based on the worker ID.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID of the worker.",
},
},
},
},
"max_concurrent_runs": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "Defines the maximum number of concurrent runs for this trigger. If omitted then the concurrency limit is disabled for this trigger.",
},
"enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether the trigger is enabled.",
},
"favorite": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Mark the trigger as a favorite.",
},
"source": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Source repository for a Git trigger. Only required for Git triggers. The referenced repository URL must match the URL of a repository tool integration in the parent toolchain. Obtain the list of integrations from the toolchain API https://cloud.ibm.com/apidocs/toolchain#list-tools.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The only supported source type is \"git\", indicating that the source is a git repository.",
},
"properties": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Properties of the source, which define the URL of the repository and a branch or pattern.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"url": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "URL of the repository to which the trigger is listening.",
},
"branch": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Name of a branch from the repo. One of branch or pattern must be specified, but only one or the other.",
},
"pattern": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The pattern of Git branch or tag to which to listen. You can specify a glob pattern such as '!test' or '*master' to match against multiple tags/branches in the repository. The glob pattern used must conform to Bash 4.3 specifications, see bash documentation for more info: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching. One of branch or pattern must be specified, but only one or the other.",
},
"blind_connection": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "True if the repository server is not addressable on the public internet. IBM Cloud will not be able to validate the connection details you provide.",
},
"hook_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID of the webhook from the repo. Computed upon creation of the trigger.",
},
"tool": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Reference to the repository tool in the parent toolchain.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID of the repository tool instance in the parent toolchain.",
},
},
},
},
},
},
},
},
},
},
"events": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Only needed for Git triggers. List of events to which a Git trigger listens. Choose one or more from: 'push', 'pull_request' and 'pull_request_closed'. For SCM repositories that use 'merge request' events, such events map to the equivalent 'pull request' events.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"cron": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Only needed for timer triggers. Cron expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: 0 *_/2 * * * - every 2 hours.",
},
"timezone": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the cron activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones.",
},
"secret": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Only needed for generic webhook trigger type. Secret used to start generic webhook trigger.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Secret type.",
},
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Secret value, not needed if secret type is `internal_validation`.",
},
"source": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Secret location, not needed if secret type is `internal_validation`.",
},
"key_name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Secret name, not needed if type is `internal_validation`.",
},
"algorithm": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Algorithm used for `digest_matches` secret type. Only needed for `digest_matches` secret type.",
},
},
},
},
"webhook_url": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Webhook URL that can be used to trigger pipeline runs.",
},
},
},
},
"worker": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Details of the worker used to run the pipeline.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Name of the worker. Computed based on the worker ID.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Type of the worker. Computed based on the worker ID.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID of the worker.",
},
},
},
},
"runs_url": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "URL for this pipeline showing the list of pipeline runs.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "API URL for interacting with the pipeline.",
},
"build_number": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The latest pipeline run build number. If this property is absent, the pipeline hasn't had any pipeline runs.",
},
"next_build_number": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The build number that will be used for the next pipeline run.",
},
"enable_notifications": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether to enable notifications for this pipeline. When enabled, pipeline run events will be published on all slack integration specified channels in the parent toolchain. If omitted, this feature is disabled by default.",
},
"enable_partial_cloning": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether to enable partial cloning for this pipeline. When partial clone is enabled, only the files contained within the paths specified in definition repositories are read and cloned, this means that symbolic links might not work. If omitted, this feature is disabled by default.",
},
"enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether this pipeline is enabled.",
},
},
}
}
func dataSourceIBMCdTektonPipelineRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
cdTektonPipelineClient, err := meta.(conns.ClientSession).CdTektonPipelineV2()
if err != nil {
return diag.FromErr(err)
}
getTektonPipelineOptions := &cdtektonpipelinev2.GetTektonPipelineOptions{}
getTektonPipelineOptions.SetID(d.Get("pipeline_id").(string))
tektonPipeline, response, err := cdTektonPipelineClient.GetTektonPipelineWithContext(context, getTektonPipelineOptions)
if err != nil {
log.Printf("[DEBUG] GetTektonPipelineWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetTektonPipelineWithContext failed %s\n%s", err, response))
}
d.SetId(fmt.Sprintf("%s", *getTektonPipelineOptions.ID))
if err = d.Set("name", tektonPipeline.Name); err != nil {
return diag.FromErr(fmt.Errorf("Error setting name: %s", err))
}
if err = d.Set("status", tektonPipeline.Status); err != nil {
return diag.FromErr(fmt.Errorf("Error setting status: %s", err))
}
resourceGroup := []map[string]interface{}{}
if tektonPipeline.ResourceGroup != nil {
modelMap, err := dataSourceIBMCdTektonPipelineResourceGroupReferenceToMap(tektonPipeline.ResourceGroup)
if err != nil {
return diag.FromErr(err)
}
resourceGroup = append(resourceGroup, modelMap)
}
if err = d.Set("resource_group", resourceGroup); err != nil {
return diag.FromErr(fmt.Errorf("Error setting resource_group %s", err))
}
toolchain := []map[string]interface{}{}
if tektonPipeline.Toolchain != nil {
modelMap, err := dataSourceIBMCdTektonPipelineToolchainReferenceToMap(tektonPipeline.Toolchain)
if err != nil {
return diag.FromErr(err)
}
toolchain = append(toolchain, modelMap)
}
if err = d.Set("toolchain", toolchain); err != nil {
return diag.FromErr(fmt.Errorf("Error setting toolchain %s", err))
}
definitions := []map[string]interface{}{}
if tektonPipeline.Definitions != nil {
for _, modelItem := range tektonPipeline.Definitions {
modelMap, err := dataSourceIBMCdTektonPipelineDefinitionToMap(&modelItem)
if err != nil {
return diag.FromErr(err)
}
definitions = append(definitions, modelMap)
}
}
if err = d.Set("definitions", definitions); err != nil {
return diag.FromErr(fmt.Errorf("Error setting definitions %s", err))
}
properties := []map[string]interface{}{}
if tektonPipeline.Properties != nil {
for _, modelItem := range tektonPipeline.Properties {
modelMap, err := dataSourceIBMCdTektonPipelinePropertyToMap(&modelItem)
if err != nil {
return diag.FromErr(err)
}
properties = append(properties, modelMap)
}
}
if err = d.Set("properties", properties); err != nil {
return diag.FromErr(fmt.Errorf("Error setting properties %s", err))
}
if err = d.Set("updated_at", flex.DateTimeToString(tektonPipeline.UpdatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err))
}
if err = d.Set("created_at", flex.DateTimeToString(tektonPipeline.CreatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err))
}
triggers := []map[string]interface{}{}
if tektonPipeline.Triggers != nil {
for _, modelItem := range tektonPipeline.Triggers {
modelMap, err := dataSourceIBMCdTektonPipelineTriggerToMap(modelItem)
if err != nil {
return diag.FromErr(err)
}
triggers = append(triggers, modelMap)
}
}
if err = d.Set("triggers", triggers); err != nil {
return diag.FromErr(fmt.Errorf("Error setting triggers %s", err))
}
worker := []map[string]interface{}{}
if tektonPipeline.Worker != nil {
modelMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(tektonPipeline.Worker)
if err != nil {
return diag.FromErr(err)
}
worker = append(worker, modelMap)
}
if err = d.Set("worker", worker); err != nil {
return diag.FromErr(fmt.Errorf("Error setting worker %s", err))
}
if err = d.Set("runs_url", tektonPipeline.RunsURL); err != nil {
return diag.FromErr(fmt.Errorf("Error setting runs_url: %s", err))
}
if err = d.Set("href", tektonPipeline.Href); err != nil {
return diag.FromErr(fmt.Errorf("Error setting href: %s", err))
}
if err = d.Set("build_number", flex.IntValue(tektonPipeline.BuildNumber)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting build_number: %s", err))
}
if err = d.Set("next_build_number", flex.IntValue(tektonPipeline.NextBuildNumber)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting next_build_number: %s", err))
}
if err = d.Set("enable_notifications", tektonPipeline.EnableNotifications); err != nil {
return diag.FromErr(fmt.Errorf("Error setting enable_notifications: %s", err))
}
if err = d.Set("enable_partial_cloning", tektonPipeline.EnablePartialCloning); err != nil {
return diag.FromErr(fmt.Errorf("Error setting enable_partial_cloning: %s", err))
}
if err = d.Set("enabled", tektonPipeline.Enabled); err != nil {
return diag.FromErr(fmt.Errorf("Error setting enabled: %s", err))
}
return nil
}
func dataSourceIBMCdTektonPipelineResourceGroupReferenceToMap(model *cdtektonpipelinev2.ResourceGroupReference) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ID != nil {
modelMap["id"] = model.ID
}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineToolchainReferenceToMap(model *cdtektonpipelinev2.ToolchainReference) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["id"] = model.ID
modelMap["crn"] = model.CRN
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineDefinitionToMap(model *cdtektonpipelinev2.Definition) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
sourceMap, err := dataSourceIBMCdTektonPipelineDefinitionSourceToMap(model.Source)
if err != nil {
return modelMap, err
}
modelMap["source"] = []map[string]interface{}{sourceMap}
if model.Href != nil {
modelMap["href"] = model.Href
}
modelMap["id"] = model.ID
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineDefinitionSourceToMap(model *cdtektonpipelinev2.DefinitionSource) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["type"] = model.Type
propertiesMap, err := dataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model.Properties)
if err != nil {
return modelMap, err
}
modelMap["properties"] = []map[string]interface{}{propertiesMap}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineDefinitionSourcePropertiesToMap(model *cdtektonpipelinev2.DefinitionSourceProperties) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["url"] = model.URL
if model.Branch != nil {
modelMap["branch"] = model.Branch
}
if model.Tag != nil {
modelMap["tag"] = model.Tag
}
modelMap["path"] = model.Path
if model.Tool != nil {
toolMap, err := dataSourceIBMCdTektonPipelineToolToMap(model.Tool)
if err != nil {
return modelMap, err
}
modelMap["tool"] = []map[string]interface{}{toolMap}
}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineToolToMap(model *cdtektonpipelinev2.Tool) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["id"] = model.ID
return modelMap, nil
}
func dataSourceIBMCdTektonPipelinePropertyToMap(model *cdtektonpipelinev2.Property) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["name"] = model.Name
if model.Value != nil {
modelMap["value"] = model.Value
}
if model.Href != nil {
modelMap["href"] = model.Href
}
if model.Enum != nil {
modelMap["enum"] = model.Enum
}
modelMap["type"] = model.Type
if model.Locked != nil {
modelMap["locked"] = model.Locked
}
if model.Path != nil {
modelMap["path"] = model.Path
}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerIntf) (map[string]interface{}, error) {
if _, ok := model.(*cdtektonpipelinev2.TriggerManualTrigger); ok {
return dataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model.(*cdtektonpipelinev2.TriggerManualTrigger))
} else if _, ok := model.(*cdtektonpipelinev2.TriggerScmTrigger); ok {
return dataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model.(*cdtektonpipelinev2.TriggerScmTrigger))
} else if _, ok := model.(*cdtektonpipelinev2.TriggerTimerTrigger); ok {
return dataSourceIBMCdTektonPipelineTriggerTimerTriggerToMap(model.(*cdtektonpipelinev2.TriggerTimerTrigger))
} else if _, ok := model.(*cdtektonpipelinev2.TriggerGenericTrigger); ok {
return dataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model.(*cdtektonpipelinev2.TriggerGenericTrigger))
} else if _, ok := model.(*cdtektonpipelinev2.Trigger); ok {
modelMap := make(map[string]interface{})
model := model.(*cdtektonpipelinev2.Trigger)
if model.Type != nil {
modelMap["type"] = model.Type
}
if model.Name != nil {
modelMap["name"] = model.Name
}
if model.Href != nil {
modelMap["href"] = model.Href
}
if model.EventListener != nil {
modelMap["event_listener"] = model.EventListener
}
if model.ID != nil {
modelMap["id"] = model.ID
}
if model.Properties != nil {
properties := []map[string]interface{}{}
for _, propertiesItem := range model.Properties {
propertiesItemMap, err := dataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem)
if err != nil {
return modelMap, err
}
properties = append(properties, propertiesItemMap)
}
modelMap["properties"] = properties
}
if model.Tags != nil {
modelMap["tags"] = model.Tags
}
if model.Worker != nil {
workerMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(model.Worker)
if err != nil {
return modelMap, err
}
modelMap["worker"] = []map[string]interface{}{workerMap}
}
if model.MaxConcurrentRuns != nil {
modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns)
}
if model.Enabled != nil {
modelMap["enabled"] = model.Enabled
}
if model.Favorite != nil {
modelMap["favorite"] = model.Favorite
}
if model.Source != nil {
sourceMap, err := dataSourceIBMCdTektonPipelineTriggerSourceToMap(model.Source)
if err != nil {
return modelMap, err
}
modelMap["source"] = []map[string]interface{}{sourceMap}
}
if model.Events != nil {
modelMap["events"] = model.Events
}
if model.Cron != nil {
modelMap["cron"] = model.Cron
}
if model.Timezone != nil {
modelMap["timezone"] = model.Timezone
}
if model.Secret != nil {
secretMap, err := dataSourceIBMCdTektonPipelineGenericSecretToMap(model.Secret)
if err != nil {
return modelMap, err
}
modelMap["secret"] = []map[string]interface{}{secretMap}
}
if model.WebhookURL != nil {
modelMap["webhook_url"] = model.WebhookURL
}
return modelMap, nil
} else {
return nil, fmt.Errorf("Unrecognized cdtektonpipelinev2.TriggerIntf subtype encountered")
}
}
func dataSourceIBMCdTektonPipelineTriggerPropertyToMap(model *cdtektonpipelinev2.TriggerProperty) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["name"] = model.Name
if model.Value != nil {
modelMap["value"] = model.Value
}
if model.Href != nil {
modelMap["href"] = model.Href
}
if model.Enum != nil {
modelMap["enum"] = model.Enum
}
modelMap["type"] = model.Type
if model.Path != nil {
modelMap["path"] = model.Path
}
if model.Locked != nil {
modelMap["locked"] = model.Locked
}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineWorkerToMap(model *cdtektonpipelinev2.Worker) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Name != nil {
modelMap["name"] = model.Name
}
if model.Type != nil {
modelMap["type"] = model.Type
}
modelMap["id"] = model.ID
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineTriggerSourceToMap(model *cdtektonpipelinev2.TriggerSource) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["type"] = model.Type
propertiesMap, err := dataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model.Properties)
if err != nil {
return modelMap, err
}
modelMap["properties"] = []map[string]interface{}{propertiesMap}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineTriggerSourcePropertiesToMap(model *cdtektonpipelinev2.TriggerSourceProperties) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["url"] = model.URL
if model.Branch != nil {
modelMap["branch"] = model.Branch
}
if model.Pattern != nil {
modelMap["pattern"] = model.Pattern
}
modelMap["blind_connection"] = model.BlindConnection
if model.HookID != nil {
modelMap["hook_id"] = model.HookID
}
toolMap, err := dataSourceIBMCdTektonPipelineToolToMap(model.Tool)
if err != nil {
return modelMap, err
}
modelMap["tool"] = []map[string]interface{}{toolMap}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineGenericSecretToMap(model *cdtektonpipelinev2.GenericSecret) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Type != nil {
modelMap["type"] = model.Type
}
if model.Value != nil {
modelMap["value"] = model.Value
}
if model.Source != nil {
modelMap["source"] = model.Source
}
if model.KeyName != nil {
modelMap["key_name"] = model.KeyName
}
if model.Algorithm != nil {
modelMap["algorithm"] = model.Algorithm
}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineTriggerManualTriggerToMap(model *cdtektonpipelinev2.TriggerManualTrigger) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["type"] = model.Type
modelMap["name"] = model.Name
if model.Href != nil {
modelMap["href"] = model.Href
}
modelMap["event_listener"] = model.EventListener
modelMap["id"] = model.ID
if model.Properties != nil {
properties := []map[string]interface{}{}
for _, propertiesItem := range model.Properties {
propertiesItemMap, err := dataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem)
if err != nil {
return modelMap, err
}
properties = append(properties, propertiesItemMap)
}
modelMap["properties"] = properties
}
if model.Tags != nil {
modelMap["tags"] = model.Tags
}
if model.Worker != nil {
workerMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(model.Worker)
if err != nil {
return modelMap, err
}
modelMap["worker"] = []map[string]interface{}{workerMap}
}
if model.MaxConcurrentRuns != nil {
modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns)
}
modelMap["enabled"] = model.Enabled
if model.Favorite != nil {
modelMap["favorite"] = model.Favorite
}
return modelMap, nil
}
func dataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipelinev2.TriggerScmTrigger) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["type"] = model.Type
modelMap["name"] = model.Name
if model.Href != nil {
modelMap["href"] = model.Href
}
modelMap["event_listener"] = model.EventListener
modelMap["id"] = model.ID
if model.Properties != nil {
properties := []map[string]interface{}{}
for _, propertiesItem := range model.Properties {
propertiesItemMap, err := dataSourceIBMCdTektonPipelineTriggerPropertyToMap(&propertiesItem)
if err != nil {
return modelMap, err
}
properties = append(properties, propertiesItemMap)
}
modelMap["properties"] = properties
}
if model.Tags != nil {
modelMap["tags"] = model.Tags
}
if model.Worker != nil {
workerMap, err := dataSourceIBMCdTektonPipelineWorkerToMap(model.Worker)
if err != nil {
return modelMap, err
}
modelMap["worker"] = []map[string]interface{}{workerMap}
}
if model.MaxConcurrentRuns != nil {
modelMap["max_concurrent_runs"] = flex.IntValue(model.MaxConcurrentRuns)
}
modelMap["enabled"] = model.Enabled
if model.Favorite != nil {
modelMap["favorite"] = model.Favorite
}
if model.Source != nil {
sourceMap, err := dataSourceIBMCdTektonPipelineTriggerSourceToMap(model.Source)
if err != nil {