Skip to content

Commit c650c77

Browse files
Feat: Add permit restart from failed steps to pipeline resource (#137)
## What Add possibility to disable restart From failed step in pipeline resource. ## Why This property was absent from the terraform provider, causing the default "true" value to always be applied and would reset manual changes on apply ## Notes <!-- Add any notes here --> ## Checklist * [x] _I have read [CONTRIBUTING.md](https://github.com/codefresh-io/terraform-provider-codefresh/blob/master/CONTRIBUTING.md)._ * [x] _I have [allowed changes to my fork to be made](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)._ * [x] _I have added tests, assuming new tests are warranted_. * [x] _I understand that the `/test` comment will be ignored by the CI trigger [unless it is made by a repo admin or collaborator](https://codefresh.io/docs/docs/pipelines/triggers/git-triggers/#support-for-building-pull-requests-from-forks)._
1 parent 353f7d9 commit c650c77

File tree

4 files changed

+95
-25
lines changed

4 files changed

+95
-25
lines changed

codefresh/cfclient/pipeline.go

+20-19
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,26 @@ func (t *CronTrigger) SetVariables(variables map[string]interface{}) {
103103
}
104104

105105
type Spec struct {
106-
Variables []Variable `json:"variables,omitempty"`
107-
SpecTemplate *SpecTemplate `json:"specTemplate,omitempty"`
108-
Triggers []Trigger `json:"triggers,omitempty"`
109-
CronTriggers []CronTrigger `json:"cronTriggers,omitempty"`
110-
Priority int `json:"priority,omitempty"`
111-
Concurrency int `json:"concurrency,omitempty"`
112-
BranchConcurrency int `json:"branchConcurrency,omitempty"`
113-
TriggerConcurrency int `json:"triggerConcurrency,omitempty"`
114-
Contexts []interface{} `json:"contexts,omitempty"`
115-
Steps *Steps `json:"steps,omitempty"`
116-
Stages *Stages `json:"stages,omitempty"`
117-
Mode string `json:"mode,omitempty"`
118-
FailFast *bool `json:"fail_fast,omitempty"`
119-
RuntimeEnvironment RuntimeEnvironment `json:"runtimeEnvironment,omitempty"`
120-
TerminationPolicy []map[string]interface{} `json:"terminationPolicy,omitempty"`
121-
PackId string `json:"packId,omitempty"`
122-
RequiredAvailableStorage string `json:"requiredAvailableStorage,omitempty"`
123-
Hooks *Hooks `json:"hooks,omitempty"`
124-
Options map[string]bool `json:"options,omitempty"`
106+
Variables []Variable `json:"variables,omitempty"`
107+
SpecTemplate *SpecTemplate `json:"specTemplate,omitempty"`
108+
Triggers []Trigger `json:"triggers,omitempty"`
109+
CronTriggers []CronTrigger `json:"cronTriggers,omitempty"`
110+
Priority int `json:"priority,omitempty"`
111+
Concurrency int `json:"concurrency,omitempty"`
112+
BranchConcurrency int `json:"branchConcurrency,omitempty"`
113+
TriggerConcurrency int `json:"triggerConcurrency,omitempty"`
114+
Contexts []interface{} `json:"contexts,omitempty"`
115+
Steps *Steps `json:"steps,omitempty"`
116+
Stages *Stages `json:"stages,omitempty"`
117+
Mode string `json:"mode,omitempty"`
118+
FailFast *bool `json:"fail_fast,omitempty"`
119+
RuntimeEnvironment RuntimeEnvironment `json:"runtimeEnvironment,omitempty"`
120+
TerminationPolicy []map[string]interface{} `json:"terminationPolicy,omitempty"`
121+
PackId string `json:"packId,omitempty"`
122+
RequiredAvailableStorage string `json:"requiredAvailableStorage,omitempty"`
123+
Hooks *Hooks `json:"hooks,omitempty"`
124+
Options map[string]bool `json:"options,omitempty"`
125+
PermitRestartFromFailedSteps bool `json:"permitRestartFromFailedSteps,omitempty"`
125126
}
126127

127128
type Steps struct {

codefresh/resource_pipeline.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ Or: <code>original_yaml_string = file("/path/to/my/codefresh.yml")</code>
101101
Optional: true,
102102
Default: 0,
103103
},
104+
"permit_restart_from_failed_steps": {
105+
Description: "Defines whether it is permitted to restart builds in this pipeline from failed step. Defaults to true",
106+
Type: schema.TypeBool,
107+
Optional: true,
108+
Default: true,
109+
},
104110
"spec_template": {
105111
Description: "The pipeline's spec template.",
106112
Type: schema.TypeList,
@@ -774,6 +780,7 @@ func flattenSpec(spec cfclient.Spec) []interface{} {
774780
m["concurrency"] = spec.Concurrency
775781
m["branch_concurrency"] = spec.BranchConcurrency
776782
m["trigger_concurrency"] = spec.TriggerConcurrency
783+
m["permit_restart_from_failed_steps"] = spec.PermitRestartFromFailedSteps
777784

778785
m["priority"] = spec.Priority
779786

@@ -923,12 +930,13 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) {
923930
OriginalYamlString: originalYamlString,
924931
},
925932
Spec: cfclient.Spec{
926-
PackId: d.Get("spec.0.pack_id").(string),
927-
RequiredAvailableStorage: d.Get("spec.0.required_available_storage").(string),
928-
Priority: d.Get("spec.0.priority").(int),
929-
Concurrency: d.Get("spec.0.concurrency").(int),
930-
BranchConcurrency: d.Get("spec.0.branch_concurrency").(int),
931-
TriggerConcurrency: d.Get("spec.0.trigger_concurrency").(int),
933+
PackId: d.Get("spec.0.pack_id").(string),
934+
RequiredAvailableStorage: d.Get("spec.0.required_available_storage").(string),
935+
Priority: d.Get("spec.0.priority").(int),
936+
Concurrency: d.Get("spec.0.concurrency").(int),
937+
BranchConcurrency: d.Get("spec.0.branch_concurrency").(int),
938+
TriggerConcurrency: d.Get("spec.0.trigger_concurrency").(int),
939+
PermitRestartFromFailedSteps: d.Get("spec.0.permit_restart_from_failed_steps").(bool),
932940
},
933941
}
934942

codefresh/resource_pipeline_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,39 @@ func TestAccCodefreshPipeline_Concurrency(t *testing.T) {
7979
})
8080
}
8181

82+
func TestAccCodefreshPipeline_PremitRestartFromFailedSteps(t *testing.T) {
83+
name := pipelineNamePrefix + acctest.RandString(10)
84+
resourceName := "codefresh_pipeline.test"
85+
var pipeline cfclient.Pipeline
86+
87+
resource.ParallelTest(t, resource.TestCase{
88+
PreCheck: func() { testAccPreCheck(t) },
89+
Providers: testAccProviders,
90+
CheckDestroy: testAccCheckCodefreshPipelineDestroy,
91+
Steps: []resource.TestStep{
92+
{
93+
Config: testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true),
94+
Check: resource.ComposeTestCheckFunc(
95+
testAccCheckCodefreshPipelineExists(resourceName, &pipeline),
96+
resource.TestCheckResourceAttr(resourceName, "spec.0.permit_restart_from_failed_steps", "true"),
97+
),
98+
},
99+
{
100+
ResourceName: resourceName,
101+
ImportState: true,
102+
ImportStateVerify: true,
103+
},
104+
{
105+
Config: testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", false),
106+
Check: resource.ComposeTestCheckFunc(
107+
testAccCheckCodefreshPipelineExists(resourceName, &pipeline),
108+
resource.TestCheckResourceAttr(resourceName, "spec.0.permit_restart_from_failed_steps", "false"),
109+
),
110+
},
111+
},
112+
})
113+
}
114+
82115
func TestAccCodefreshPipeline_Tags(t *testing.T) {
83116
name := pipelineNamePrefix + acctest.RandString(10)
84117
resourceName := "codefresh_pipeline.test"
@@ -955,6 +988,33 @@ resource "codefresh_pipeline" "test" {
955988
`, rName, repo, path, revision, context, concurrency, concurrencyBranch, concurrencyTrigger)
956989
}
957990

991+
func testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(rName string, repo string, path string, revision string, context string, permitRestartFromFailedSteps bool) string {
992+
return fmt.Sprintf(`
993+
resource "codefresh_pipeline" "test" {
994+
995+
lifecycle {
996+
ignore_changes = [
997+
revision
998+
]
999+
}
1000+
1001+
name = "%s"
1002+
1003+
spec {
1004+
spec_template {
1005+
repo = %q
1006+
path = %q
1007+
revision = %q
1008+
context = %q
1009+
}
1010+
1011+
permit_restart_from_failed_steps = %t
1012+
1013+
}
1014+
}
1015+
`, rName, repo, path, revision, context, permitRestartFromFailedSteps)
1016+
}
1017+
9581018
func testAccCodefreshPipelineBasicConfigTriggers(
9591019
rName,
9601020
repo,

docs/resources/pipeline.md

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Optional:
130130
- `cron_trigger` (Block List) The pipeline's cron triggers. Conflicts with the deprecated [codefresh_pipeline_cron_trigger](https://registry.terraform.io/providers/codefresh-io/codefresh/latest/docs/resources/pipeline_cron_trigger) resource. (see [below for nested schema](#nestedblock--spec--cron_trigger))
131131
- `options` (Block List, Max: 1) The options for the pipeline. (see [below for nested schema](#nestedblock--spec--options))
132132
- `pack_id` (String) SAAS pack (`5cd1746617313f468d669013` for Small; `5cd1746717313f468d669014` for Medium; `5cd1746817313f468d669015` for Large; `5cd1746817313f468d669017` for XL; `5cd1746817313f468d669018` for XXL); `5cd1746817313f468d669020` for 4XL).
133+
- `permit_restart_from_failed_steps` (Boolean) Defines whether it is permitted to restart builds in this pipeline from failed step. Defaults to true
133134
- `priority` (Number) Helps to organize the order of builds execution in case of reaching the concurrency limit (default: `0`).
134135
- `required_available_storage` (String) Minimum disk space required for build filesystem ( unit Gi is required).
135136
- `runtime_environment` (Block List) The runtime environment for the pipeline. (see [below for nested schema](#nestedblock--spec--runtime_environment))

0 commit comments

Comments
 (0)