Skip to content

Commit 20dbf89

Browse files
committed
feat: Support Pending Approval options in pipelines
1 parent f5a71d8 commit 20dbf89

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

client/pipeline.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type Spec struct {
8585
RuntimeEnvironment RuntimeEnvironment `json:"runtimeEnvironment,omitempty"`
8686
TerminationPolicy []map[string]interface{} `json:"terminationPolicy,omitempty"`
8787
Hooks *Hooks `json:"hooks,omitempty"`
88+
Options map[string]bool `json:"options,omitempty"`
8889
}
8990

9091
type Steps struct {

codefresh/resource_pipeline.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,23 @@ func resourcePipeline() *schema.Resource {
306306
},
307307
},
308308
},
309+
"options": {
310+
Type: schema.TypeList,
311+
MaxItems: 1,
312+
Optional: true,
313+
Elem: &schema.Resource{
314+
Schema: map[string]*schema.Schema{
315+
"keep_pvcs_for_pending_approval": {
316+
Type: schema.TypeBool,
317+
Optional: true,
318+
},
319+
"pending_approval_concurrency_applied": {
320+
Type: schema.TypeBool,
321+
Optional: true,
322+
},
323+
},
324+
},
325+
},
309326
},
310327
},
311328
},
@@ -445,6 +462,21 @@ func flattenSpec(spec cfClient.Spec) []interface{} {
445462
m["termination_policy"] = flattenSpecTerminationPolicy(spec.TerminationPolicy)
446463
}
447464

465+
if len(spec.Options) > 0 {
466+
var resOptions []map[string]bool
467+
options := map[string]bool{}
468+
for keyOption, valueOption := range spec.Options {
469+
switch {
470+
case keyOption == "keepPVCsForPendingApproval":
471+
options["keep_pvcs_for_pending_approval"] = valueOption
472+
case keyOption == "pendingApprovalConcurrencyApplied":
473+
options["pending_approval_concurrency_applied"] = valueOption
474+
}
475+
}
476+
resOptions = append(resOptions, options)
477+
m["options"] = resOptions
478+
}
479+
448480
m["concurrency"] = spec.Concurrency
449481
m["branch_concurrency"] = spec.BranchConcurrency
450482
m["trigger_concurrency"] = spec.TriggerConcurrency
@@ -647,6 +679,18 @@ func mapResourceToPipeline(d *schema.ResourceData) *cfClient.Pipeline {
647679
onTerminateAnnotationPolicy["key"] = "cf_predecessor"
648680
codefreshTerminationPolicy = append(codefreshTerminationPolicy, onTerminateAnnotationPolicy)
649681
}
682+
if _, ok := d.GetOk("spec.0.options"); ok {
683+
pipelineSpecOption := make(map[string]bool)
684+
if keepPVCs, ok := d.GetOkExists("spec.0.options.0.keep_pvcs_for_pending_approval"); ok {
685+
pipelineSpecOption["keepPVCsForPendingApproval"] = keepPVCs.(bool)
686+
}
687+
if pendingApprovalConcurrencyApplied, ok := d.GetOkExists("spec.0.options.0.pending_approval_concurrency_applied"); ok {
688+
pipelineSpecOption["pendingApprovalConcurrencyApplied"] = pendingApprovalConcurrencyApplied.(bool)
689+
}
690+
pipeline.Spec.Options = pipelineSpecOption
691+
} else {
692+
pipeline.Spec.Options = nil
693+
}
650694

651695
pipeline.Spec.TerminationPolicy = codefreshTerminationPolicy
652696

codefresh/resource_pipeline_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,41 @@ func TestAccCodefreshPipelineOnCreateBranchIgnoreTrigger(t *testing.T) {
428428
})
429429
}
430430

431+
func TestAccCodefreshPipelineOptions(t *testing.T) {
432+
name := pipelineNamePrefix + acctest.RandString(10)
433+
resourceName := "codefresh_pipeline.test"
434+
435+
resource.ParallelTest(t, resource.TestCase{
436+
PreCheck: func() { testAccPreCheck(t) },
437+
Providers: testAccProviders,
438+
CheckDestroy: testAccCheckCodefreshPipelineDestroy,
439+
Steps: []resource.TestStep{
440+
{
441+
Config: testAccCodefreshPipelineOptions(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true, false),
442+
Check: resource.ComposeTestCheckFunc(
443+
testAccCheckCodefreshPipelineExists(resourceName),
444+
resource.TestCheckResourceAttr(resourceName, "name", name),
445+
resource.TestCheckResourceAttr(resourceName, "spec.0.options.0.keep_pvcs_for_pending_approval", "true"),
446+
resource.TestCheckResourceAttr(resourceName, "spec.0.options.0.pending_approval_concurrency_applied", "false"),
447+
),
448+
},
449+
{
450+
ResourceName: resourceName,
451+
ImportState: true,
452+
ImportStateVerify: true,
453+
},
454+
{
455+
Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"),
456+
Check: resource.ComposeTestCheckFunc(
457+
testAccCheckCodefreshPipelineExists(resourceName),
458+
resource.TestCheckResourceAttr(resourceName, "name", name),
459+
resource.TestCheckNoResourceAttr(resourceName, "spec.0.options"),
460+
),
461+
},
462+
},
463+
})
464+
}
465+
431466
func testAccCheckCodefreshPipelineExists(resource string) resource.TestCheckFunc {
432467
return func(state *terraform.State) error {
433468

@@ -848,6 +883,34 @@ func TestAccCodefreshPipeline_Contexts(t *testing.T) {
848883
})
849884
}
850885

886+
func testAccCodefreshPipelineOptions(rName, repo, path, revision, context string, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied bool) string {
887+
return fmt.Sprintf(`
888+
resource "codefresh_pipeline" "test" {
889+
890+
lifecycle {
891+
ignore_changes = [
892+
revision
893+
]
894+
}
895+
896+
name = "%s"
897+
898+
spec {
899+
spec_template {
900+
repo = %q
901+
path = %q
902+
revision = %q
903+
context = %q
904+
}
905+
options {
906+
keep_pvcs_for_pending_approval = %t
907+
pending_approval_concurrency_applied = %t
908+
}
909+
}
910+
}
911+
`, rName, repo, path, revision, context, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied)
912+
}
913+
851914
func testAccCodefreshPipelineOnCreateBranchIgnoreTrigger(rName, repo, path, revision, context string, ignoreTrigger bool) string {
852915
return fmt.Sprintf(`
853916
resource "codefresh_pipeline" "test" {

docs/resources/pipeline.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ resource "codefresh_pipeline" "test" {
108108
- `runtime_environment` - (Optional) A collection of `runtime_environment` blocks as documented below.
109109
- `contexts` - (Optional) A list of strings representing the contexts ([shared_configuration](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/shared-configuration/)) to be configured for the pipeline
110110
- `termination_policy` - (Optional) A `termination_policy` block as documented below.
111+
- `options` - (Optional) A `options` block as documented below.
111112

112113
---
113114

@@ -178,6 +179,18 @@ The following table presents how to configure this block based on the options av
178179
| Once a build is created, terminate all other running builds | From the SAME trigger | Defined | N/A | false | true |
179180
| Once a build is created, terminate all other running builds | From ANY trigger | Defined | N/A | true | true |
180181

182+
---
183+
184+
`options` supports the following:
185+
186+
- `keep_pvcs_for_pending_approval` - (Optional) Boolean for the Settings under pending approval: `When build enters "Pending Approval" state, volume should`:
187+
* Default (attribute not specified): "Use Setting accounts"
188+
* true: "Remain (build remains active)"
189+
* false: "Be removed"
190+
- `pending_approval_concurrency_applied` - (Optional) Boolean for the Settings under pending approval: `Pipeline concurrency policy: Builds on "Pending Approval" state should be`:
191+
* Default (attribute not specified): "Use Setting accounts"
192+
* true: "Included in concurrency"
193+
* false: "Not included in concurrency"
181194

182195
## Attributes Reference
183196

0 commit comments

Comments
 (0)