diff --git a/codefresh/cfclient/pipeline.go b/codefresh/cfclient/pipeline.go index dba6f11..f4f71a7 100644 --- a/codefresh/cfclient/pipeline.go +++ b/codefresh/cfclient/pipeline.go @@ -133,7 +133,7 @@ type Spec struct { RequiredAvailableStorage string `json:"requiredAvailableStorage,omitempty"` Hooks *Hooks `json:"hooks,omitempty"` Options map[string]bool `json:"options,omitempty"` - PermitRestartFromFailedSteps bool `json:"permitRestartFromFailedSteps,omitempty"` + PermitRestartFromFailedSteps *bool `json:"permitRestartFromFailedSteps,omitempty"` ExternalResources []ExternalResource `json:"externalResources,omitempty"` } diff --git a/codefresh/data_current_account_user.go b/codefresh/data_current_account_user.go index 93b516e..ba8b3b6 100644 --- a/codefresh/data_current_account_user.go +++ b/codefresh/data_current_account_user.go @@ -68,7 +68,6 @@ func mapDataCurrentAccountUserToResource(currentAccount *cfclient.CurrentAccount isFound := false - for _, user := range currentAccount.Users { if (userAttributeName == "name" && user.UserName == userAttributeValue) || (userAttributeName == "email" && user.Email == userAttributeValue) { isFound = true diff --git a/codefresh/resource_pipeline.go b/codefresh/resource_pipeline.go index eadcb58..11ad6d9 100644 --- a/codefresh/resource_pipeline.go +++ b/codefresh/resource_pipeline.go @@ -17,6 +17,10 @@ import ( var terminationPolicyOnCreateBranchAttributes = []string{"branchName", "ignoreTrigger", "ignoreBranch"} +func ptrBool(b bool) *bool { + return &b +} + func resourcePipeline() *schema.Resource { return &schema.Resource{ 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.", @@ -102,10 +106,20 @@ Or: original_yaml_string = file("/path/to/my/codefresh.yml") Default: 0, }, "permit_restart_from_failed_steps": { - Description: "Defines whether it is permitted to restart builds in this pipeline from failed step. Defaults to true", + Description: "Defines whether it is permitted to restart builds in this pipeline from failed step (default: `true`).", Type: schema.TypeBool, Optional: true, Default: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + // If the user set the pipeline to use account settings, ignore the diff + return d.Get("spec.0.permit_restart_from_failed_steps_use_account_settings").(bool) + }, + }, + "permit_restart_from_failed_steps_use_account_settings": { + Description: "Defines whether `permit_restart_from_failed_steps` should be set to “Use account settings” (default: `false`). If set, `permit_restart_from_failed_steps` will be ignored.", + Type: schema.TypeBool, + Optional: true, + Default: false, }, "spec_template": { Description: "The pipeline's spec template.", @@ -915,7 +929,17 @@ func flattenSpec(spec cfclient.Spec) []map[string]interface{} { m["concurrency"] = spec.Concurrency m["branch_concurrency"] = spec.BranchConcurrency m["trigger_concurrency"] = spec.TriggerConcurrency - m["permit_restart_from_failed_steps"] = spec.PermitRestartFromFailedSteps + + if spec.PermitRestartFromFailedSteps == nil { + m["permit_restart_from_failed_steps"] = true // default value + m["permit_restart_from_failed_steps_use_account_settings"] = true + } else if *spec.PermitRestartFromFailedSteps { + m["permit_restart_from_failed_steps"] = true + m["permit_restart_from_failed_steps_use_account_settings"] = false + } else { + m["permit_restart_from_failed_steps"] = false + m["permit_restart_from_failed_steps_use_account_settings"] = false + } m["priority"] = spec.Priority @@ -1084,16 +1108,31 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) { OriginalYamlString: originalYamlString, }, Spec: cfclient.Spec{ - PackId: d.Get("spec.0.pack_id").(string), - RequiredAvailableStorage: d.Get("spec.0.required_available_storage").(string), - Priority: d.Get("spec.0.priority").(int), - Concurrency: d.Get("spec.0.concurrency").(int), - BranchConcurrency: d.Get("spec.0.branch_concurrency").(int), - TriggerConcurrency: d.Get("spec.0.trigger_concurrency").(int), - PermitRestartFromFailedSteps: d.Get("spec.0.permit_restart_from_failed_steps").(bool), + PackId: d.Get("spec.0.pack_id").(string), + RequiredAvailableStorage: d.Get("spec.0.required_available_storage").(string), + Priority: d.Get("spec.0.priority").(int), + Concurrency: d.Get("spec.0.concurrency").(int), + BranchConcurrency: d.Get("spec.0.branch_concurrency").(int), + TriggerConcurrency: d.Get("spec.0.trigger_concurrency").(int), }, } + shouldPermitRestart := d.Get("spec.0.permit_restart_from_failed_steps").(bool) + shouldUseAccountSettings := d.Get("spec.0.permit_restart_from_failed_steps_use_account_settings").(bool) + switch shouldUseAccountSettings { + case true: + pipeline.Spec.PermitRestartFromFailedSteps = nil + default: + switch shouldPermitRestart { + case true: + pipeline.Spec.PermitRestartFromFailedSteps = ptrBool(true) + case false: + pipeline.Spec.PermitRestartFromFailedSteps = ptrBool(false) + default: + pipeline.Spec.PermitRestartFromFailedSteps = nil + } + } + if _, ok := d.GetOk("spec.0.spec_template"); ok { pipeline.Spec.SpecTemplate = &cfclient.SpecTemplate{ Location: d.Get("spec.0.spec_template.0.location").(string), diff --git a/docs/resources/pipeline.md b/docs/resources/pipeline.md index bbc02e5..8264c26 100644 --- a/docs/resources/pipeline.md +++ b/docs/resources/pipeline.md @@ -132,7 +132,8 @@ Optional: - `external_resource` (Block List) (see [below for nested schema](#nestedblock--spec--external_resource)) - `options` (Block List, Max: 1) The options for the pipeline. (see [below for nested schema](#nestedblock--spec--options)) - `pack_id` (String) SAAS pack (`5cd1746617313f468d669013` for Small; `5cd1746717313f468d669014` for Medium; `5cd1746817313f468d669015` for Large; `5cd1746817313f468d669017` for XL; `5cd1746817313f468d669018` for XXL); `5cd1746817313f468d669020` for 4XL). -- `permit_restart_from_failed_steps` (Boolean) Defines whether it is permitted to restart builds in this pipeline from failed step. Defaults to true +- `permit_restart_from_failed_steps` (Boolean) Defines whether it is permitted to restart builds in this pipeline from failed step (default: `true`). +- `permit_restart_from_failed_steps_use_account_settings` (Boolean) Defines whether `permit_restart_from_failed_steps` should be set to “Use account settings” (default: `false`). If set, `permit_restart_from_failed_steps` will be ignored. - `priority` (Number) Helps to organize the order of builds execution in case of reaching the concurrency limit (default: `0`). - `required_available_storage` (String) Minimum disk space required for build filesystem ( unit Gi is required). - `runtime_environment` (Block List) The runtime environment for the pipeline. (see [below for nested schema](#nestedblock--spec--runtime_environment))