Skip to content

Commit 2adecb7

Browse files
committed
fix(resource/pipeline): fix permit_restart_from_failed_steps to JSON
`permit_restart_from_failed_steps` property of pipeline spec behaves differently when omit vs set to `false`. This means we should not omit `false` value while sending requests to API. Fixes #CR-26963
1 parent 736e7ad commit 2adecb7

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

Diff for: codefresh/cfclient/pipeline.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ type Spec struct {
133133
RequiredAvailableStorage string `json:"requiredAvailableStorage,omitempty"`
134134
Hooks *Hooks `json:"hooks,omitempty"`
135135
Options map[string]bool `json:"options,omitempty"`
136-
PermitRestartFromFailedSteps bool `json:"permitRestartFromFailedSteps,omitempty"`
136+
PermitRestartFromFailedSteps *bool `json:"permitRestartFromFailedSteps,omitempty"`
137137
ExternalResources []ExternalResource `json:"externalResources,omitempty"`
138138
}
139139

Diff for: codefresh/data_current_account_user.go

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func mapDataCurrentAccountUserToResource(currentAccount *cfclient.CurrentAccount
6868

6969
isFound := false
7070

71-
7271
for _, user := range currentAccount.Users {
7372
if (userAttributeName == "name" && user.UserName == userAttributeValue) || (userAttributeName == "email" && user.Email == userAttributeValue) {
7473
isFound = true

Diff for: codefresh/resource_pipeline.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import (
1717

1818
var terminationPolicyOnCreateBranchAttributes = []string{"branchName", "ignoreTrigger", "ignoreBranch"}
1919

20+
func ptrBool(b bool) *bool {
21+
return &b
22+
}
23+
2024
func resourcePipeline() *schema.Resource {
2125
return &schema.Resource{
2226
Description: "The central component of the Codefresh Platform. Pipelines are workflows that contain individual steps. Each step is responsible for a specific action in the process.",
@@ -1090,7 +1094,7 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) {
10901094
Concurrency: d.Get("spec.0.concurrency").(int),
10911095
BranchConcurrency: d.Get("spec.0.branch_concurrency").(int),
10921096
TriggerConcurrency: d.Get("spec.0.trigger_concurrency").(int),
1093-
PermitRestartFromFailedSteps: d.Get("spec.0.permit_restart_from_failed_steps").(bool),
1097+
PermitRestartFromFailedSteps: ptrBool(d.Get("spec.0.permit_restart_from_failed_steps").(bool)),
10941098
},
10951099
}
10961100

Diff for: codefresh/resource_pipeline_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestAccCodefreshPipeline_PremitRestartFromFailedSteps(t *testing.T) {
9090
CheckDestroy: testAccCheckCodefreshPipelineDestroy,
9191
Steps: []resource.TestStep{
9292
{
93-
Config: testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true),
93+
Config: testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", ptrBool(true)),
9494
Check: resource.ComposeTestCheckFunc(
9595
testAccCheckCodefreshPipelineExists(resourceName, &pipeline),
9696
resource.TestCheckResourceAttr(resourceName, "spec.0.permit_restart_from_failed_steps", "true"),
@@ -102,7 +102,7 @@ func TestAccCodefreshPipeline_PremitRestartFromFailedSteps(t *testing.T) {
102102
ImportStateVerify: true,
103103
},
104104
{
105-
Config: testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", false),
105+
Config: testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", ptrBool(false)),
106106
Check: resource.ComposeTestCheckFunc(
107107
testAccCheckCodefreshPipelineExists(resourceName, &pipeline),
108108
resource.TestCheckResourceAttr(resourceName, "spec.0.permit_restart_from_failed_steps", "false"),
@@ -1070,7 +1070,7 @@ resource "codefresh_pipeline" "test" {
10701070
`, rName, repo, path, revision, context, concurrency, concurrencyBranch, concurrencyTrigger)
10711071
}
10721072

1073-
func testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(rName string, repo string, path string, revision string, context string, permitRestartFromFailedSteps bool) string {
1073+
func testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(rName string, repo string, path string, revision string, context string, permitRestartFromFailedSteps *bool) string {
10741074
return fmt.Sprintf(`
10751075
resource "codefresh_pipeline" "test" {
10761076
@@ -1094,7 +1094,7 @@ resource "codefresh_pipeline" "test" {
10941094
10951095
}
10961096
}
1097-
`, rName, repo, path, revision, context, permitRestartFromFailedSteps)
1097+
`, rName, repo, path, revision, context, *permitRestartFromFailedSteps)
10981098
}
10991099

11001100
func testAccCodefreshPipelineBasicConfigTriggers(

0 commit comments

Comments
 (0)