@@ -575,13 +575,7 @@ func mapResourceToPipeline(d *schema.ResourceData) *cfClient.Pipeline {
575
575
Context : d .Get ("spec.0.spec_template.0.context" ).(string ),
576
576
}
577
577
} else {
578
- stages , steps := extractStagesAndSteps (originalYamlString )
579
- pipeline .Spec .Steps = & cfClient.Steps {
580
- Steps : steps ,
581
- }
582
- pipeline .Spec .Stages = & cfClient.Stages {
583
- Stages : stages ,
584
- }
578
+ extractSpecAttributesFromOriginalYamlString (originalYamlString , pipeline )
585
579
}
586
580
587
581
if _ , ok := d .GetOk ("spec.0.runtime_environment" ); ok {
@@ -659,24 +653,30 @@ func mapResourceToPipeline(d *schema.ResourceData) *cfClient.Pipeline {
659
653
return pipeline
660
654
}
661
655
662
- // extractStagesAndSteps extracts the steps and stages from the original yaml string to enable propagation in the `Spec` attribute of the pipeline
656
+ // extractSpecAttributesFromOriginalYamlString extracts the steps and stages from the original yaml string to enable propagation in the `Spec` attribute of the pipeline
663
657
// We cannot leverage on the standard marshal/unmarshal because the steps attribute needs to maintain the order of elements
664
658
// while by default the standard function doesn't do it because in JSON maps are unordered
665
- func extractStagesAndSteps (originalYamlString string ) ( stages , steps string ) {
659
+ func extractSpecAttributesFromOriginalYamlString (originalYamlString string , pipeline * cfClient. Pipeline ) {
666
660
// Use mapSlice to preserve order of items from the YAML string
667
661
m := yaml.MapSlice {}
668
662
err := yaml .Unmarshal ([]byte (originalYamlString ), & m )
669
663
if err != nil {
670
664
log .Fatal ("Unable to unmarshall original_yaml_string" )
671
665
}
672
666
673
- stages = "[]"
667
+ stages : = "[]"
674
668
// Dynamically build JSON object for steps using String builder
675
669
stepsBuilder := strings.Builder {}
676
670
stepsBuilder .WriteString ("{" )
671
+ // Dynamically build JSON object for steps using String builder
672
+ hooksBuilder := strings.Builder {}
673
+ hooksBuilder .WriteString ("{" )
674
+
677
675
// Parse elements of the YAML string to extract Steps and Stages if defined
678
676
for _ , item := range m {
679
- if item .Key == "steps" {
677
+ key := item .Key .(string )
678
+ switch key {
679
+ case "steps" :
680
680
switch x := item .Value .(type ) {
681
681
default :
682
682
log .Fatalf ("unsupported value type: %T" , item .Value )
@@ -694,17 +694,28 @@ func extractStagesAndSteps(originalYamlString string) (stages, steps string) {
694
694
}
695
695
}
696
696
}
697
- }
698
- if item .Key == "stages" {
697
+ case "stages" :
699
698
// For Stages we don't have ordering issue because it's a list
700
699
y , _ := yaml .Marshal (item .Value )
701
700
j2 , _ := ghodss .YAMLToJSON (y )
702
701
stages = string (j2 )
702
+ case "mode" :
703
+ pipeline .Spec .Mode = item .Value .(string )
704
+ case "fail_fast" :
705
+ pipeline .Spec .FailFast = item .Value .(bool )
706
+ default :
707
+ log .Printf ("Unsupported entry %s" , key )
703
708
}
704
709
}
705
710
stepsBuilder .WriteString ("}" )
706
- steps = stepsBuilder .String ()
707
- return
711
+ steps := stepsBuilder .String ()
712
+ pipeline .Spec .Steps = & cfClient.Steps {
713
+ Steps : steps ,
714
+ }
715
+ pipeline .Spec .Stages = & cfClient.Stages {
716
+ Stages : stages ,
717
+ }
718
+
708
719
}
709
720
710
721
func getSupportedTerminationPolicyAttributes (policy string ) map [string ]interface {} {
0 commit comments