Skip to content

Commit 9ac80ec

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 9ac80ec

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

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

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

codefresh/resource_pipeline.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) {
10901090
Concurrency: d.Get("spec.0.concurrency").(int),
10911091
BranchConcurrency: d.Get("spec.0.branch_concurrency").(int),
10921092
TriggerConcurrency: d.Get("spec.0.trigger_concurrency").(int),
1093-
PermitRestartFromFailedSteps: d.Get("spec.0.permit_restart_from_failed_steps").(bool),
1093+
PermitRestartFromFailedSteps: d.Get("spec.0.permit_restart_from_failed_steps").(*bool),
10941094
},
10951095
}
10961096

codefresh/resource_pipeline_test.go

+7-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"),
@@ -1069,8 +1069,11 @@ resource "codefresh_pipeline" "test" {
10691069
}
10701070
`, rName, repo, path, revision, context, concurrency, concurrencyBranch, concurrencyTrigger)
10711071
}
1072+
func ptrBool(b bool) *bool {
1073+
return &b
1074+
}
10721075

1073-
func testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(rName string, repo string, path string, revision string, context string, permitRestartFromFailedSteps bool) string {
1076+
func testAccCodefreshPipelineBasicConfigPermitRestartFromFailedSteps(rName string, repo string, path string, revision string, context string, permitRestartFromFailedSteps *bool) string {
10741077
return fmt.Sprintf(`
10751078
resource "codefresh_pipeline" "test" {
10761079
@@ -1094,7 +1097,7 @@ resource "codefresh_pipeline" "test" {
10941097
10951098
}
10961099
}
1097-
`, rName, repo, path, revision, context, permitRestartFromFailedSteps)
1100+
`, rName, repo, path, revision, context, *permitRestartFromFailedSteps)
10981101
}
10991102

11001103
func testAccCodefreshPipelineBasicConfigTriggers(

0 commit comments

Comments
 (0)