diff --git a/client/pipeline.go b/client/pipeline.go index 5d089cd..57b1af7 100644 --- a/client/pipeline.go +++ b/client/pipeline.go @@ -85,6 +85,7 @@ type Spec struct { RuntimeEnvironment RuntimeEnvironment `json:"runtimeEnvironment,omitempty"` TerminationPolicy []map[string]interface{} `json:"terminationPolicy,omitempty"` Hooks *Hooks `json:"hooks,omitempty"` + Options map[string]bool `json:"options,omitempty"` } type Steps struct { diff --git a/codefresh/resource_pipeline.go b/codefresh/resource_pipeline.go index 6ec621e..2c0c4c9 100644 --- a/codefresh/resource_pipeline.go +++ b/codefresh/resource_pipeline.go @@ -306,6 +306,23 @@ func resourcePipeline() *schema.Resource { }, }, }, + "options": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "keep_pvcs_for_pending_approval": { + Type: schema.TypeBool, + Optional: true, + }, + "pending_approval_concurrency_applied": { + Type: schema.TypeBool, + Optional: true, + }, + }, + }, + }, }, }, }, @@ -445,6 +462,21 @@ func flattenSpec(spec cfClient.Spec) []interface{} { m["termination_policy"] = flattenSpecTerminationPolicy(spec.TerminationPolicy) } + if len(spec.Options) > 0 { + var resOptions []map[string]bool + options := map[string]bool{} + for keyOption, valueOption := range spec.Options { + switch { + case keyOption == "keepPVCsForPendingApproval": + options["keep_pvcs_for_pending_approval"] = valueOption + case keyOption == "pendingApprovalConcurrencyApplied": + options["pending_approval_concurrency_applied"] = valueOption + } + } + resOptions = append(resOptions, options) + m["options"] = resOptions + } + m["concurrency"] = spec.Concurrency m["branch_concurrency"] = spec.BranchConcurrency m["trigger_concurrency"] = spec.TriggerConcurrency @@ -647,6 +679,18 @@ func mapResourceToPipeline(d *schema.ResourceData) *cfClient.Pipeline { onTerminateAnnotationPolicy["key"] = "cf_predecessor" codefreshTerminationPolicy = append(codefreshTerminationPolicy, onTerminateAnnotationPolicy) } + if _, ok := d.GetOk("spec.0.options"); ok { + pipelineSpecOption := make(map[string]bool) + if keepPVCs, ok := d.GetOkExists("spec.0.options.0.keep_pvcs_for_pending_approval"); ok { + pipelineSpecOption["keepPVCsForPendingApproval"] = keepPVCs.(bool) + } + if pendingApprovalConcurrencyApplied, ok := d.GetOkExists("spec.0.options.0.pending_approval_concurrency_applied"); ok { + pipelineSpecOption["pendingApprovalConcurrencyApplied"] = pendingApprovalConcurrencyApplied.(bool) + } + pipeline.Spec.Options = pipelineSpecOption + } else { + pipeline.Spec.Options = nil + } pipeline.Spec.TerminationPolicy = codefreshTerminationPolicy diff --git a/codefresh/resource_pipeline_test.go b/codefresh/resource_pipeline_test.go index fc2d3f8..07ea675 100644 --- a/codefresh/resource_pipeline_test.go +++ b/codefresh/resource_pipeline_test.go @@ -428,6 +428,41 @@ func TestAccCodefreshPipelineOnCreateBranchIgnoreTrigger(t *testing.T) { }) } +func TestAccCodefreshPipelineOptions(t *testing.T) { + name := pipelineNamePrefix + acctest.RandString(10) + resourceName := "codefresh_pipeline.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCodefreshPipelineDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCodefreshPipelineOptions(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckCodefreshPipelineExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.options.0.keep_pvcs_for_pending_approval", "true"), + resource.TestCheckResourceAttr(resourceName, "spec.0.options.0.pending_approval_concurrency_applied", "false"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Check: resource.ComposeTestCheckFunc( + testAccCheckCodefreshPipelineExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckNoResourceAttr(resourceName, "spec.0.options"), + ), + }, + }, + }) +} + func testAccCheckCodefreshPipelineExists(resource string) resource.TestCheckFunc { return func(state *terraform.State) error { @@ -848,6 +883,34 @@ func TestAccCodefreshPipeline_Contexts(t *testing.T) { }) } +func testAccCodefreshPipelineOptions(rName, repo, path, revision, context string, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied bool) string { + return fmt.Sprintf(` +resource "codefresh_pipeline" "test" { + + lifecycle { + ignore_changes = [ + revision + ] + } + + name = "%s" + + spec { + spec_template { + repo = %q + path = %q + revision = %q + context = %q + } + options { + keep_pvcs_for_pending_approval = %t + pending_approval_concurrency_applied = %t + } + } +} +`, rName, repo, path, revision, context, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied) +} + func testAccCodefreshPipelineOnCreateBranchIgnoreTrigger(rName, repo, path, revision, context string, ignoreTrigger bool) string { return fmt.Sprintf(` resource "codefresh_pipeline" "test" { diff --git a/docs/resources/pipeline.md b/docs/resources/pipeline.md index 39c0944..aaa0101 100644 --- a/docs/resources/pipeline.md +++ b/docs/resources/pipeline.md @@ -108,6 +108,7 @@ resource "codefresh_pipeline" "test" { - `runtime_environment` - (Optional) A collection of `runtime_environment` blocks as documented below. - `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 - `termination_policy` - (Optional) A `termination_policy` block as documented below. +- `options` - (Optional) A `options` block as documented below. --- @@ -178,6 +179,18 @@ The following table presents how to configure this block based on the options av | Once a build is created, terminate all other running builds | From the SAME trigger | Defined | N/A | false | true | | Once a build is created, terminate all other running builds | From ANY trigger | Defined | N/A | true | true | +--- + +`options` supports the following: + +- `keep_pvcs_for_pending_approval` - (Optional) Boolean for the Settings under pending approval: `When build enters "Pending Approval" state, volume should`: + * Default (attribute not specified): "Use Setting accounts" + * true: "Remain (build remains active)" + * false: "Be removed" +- `pending_approval_concurrency_applied` - (Optional) Boolean for the Settings under pending approval: `Pipeline concurrency policy: Builds on "Pending Approval" state should be`: + * Default (attribute not specified): "Use Setting accounts" + * true: "Included in concurrency" + * false: "Not included in concurrency" ## Attributes Reference