Skip to content

Commit 80248af

Browse files
Feat: Add enable notifications on pipeline level (credit @nickborysov) (#136)
## What Add enable notifications on pipeline resource level ## Why ## Notes re-implement stale #86 because of multiple conflicts ## 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 c650c77 commit 80248af

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

codefresh/resource_pipeline.go

+10
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ Pipeline concurrency policy: Builds on 'Pending Approval' state should be:
606606
Type: schema.TypeBool,
607607
Optional: true,
608608
},
609+
"enable_notifications": {
610+
Type: schema.TypeBool,
611+
Optional: true,
612+
Default: false,
613+
},
609614
},
610615
},
611616
},
@@ -768,6 +773,8 @@ func flattenSpec(spec cfclient.Spec) []interface{} {
768773
options["keep_pvcs_for_pending_approval"] = valueOption
769774
case keyOption == "pendingApprovalConcurrencyApplied":
770775
options["pending_approval_concurrency_applied"] = valueOption
776+
case keyOption == "enableNotifications":
777+
options["enable_notifications"] = valueOption
771778
}
772779
}
773780
resOptions = append(resOptions, options)
@@ -1082,6 +1089,9 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) {
10821089
if pendingApprovalConcurrencyApplied, ok := d.GetOkExists("spec.0.options.0.pending_approval_concurrency_applied"); ok {
10831090
pipelineSpecOption["pendingApprovalConcurrencyApplied"] = pendingApprovalConcurrencyApplied.(bool)
10841091
}
1092+
if enableNotifications, ok := d.GetOkExists("spec.0.options.0.enable_notifications"); ok {
1093+
pipelineSpecOption["enableNotifications"] = enableNotifications.(bool)
1094+
}
10851095
pipeline.Spec.Options = pipelineSpecOption
10861096
} else {
10871097
pipeline.Spec.Options = nil

codefresh/resource_pipeline_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,14 @@ func TestAccCodefreshPipelineOptions(t *testing.T) {
735735
CheckDestroy: testAccCheckCodefreshPipelineDestroy,
736736
Steps: []resource.TestStep{
737737
{
738-
Config: testAccCodefreshPipelineOptions(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true, false),
738+
Config: testAccCodefreshPipelineOptions(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true, false, false),
739739
Check: resource.ComposeTestCheckFunc(
740740
testAccCheckCodefreshPipelineExists(resourceName, &pipeline),
741741
resource.TestCheckResourceAttr(resourceName, "name", name),
742742
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "spec.0.options.*", map[string]string{
743743
"keep_pvcs_for_pending_approval": "true",
744744
"pending_approval_concurrency_applied": "false",
745+
"enable_notifications": "false",
745746
}),
746747
),
747748
},
@@ -1338,7 +1339,7 @@ func TestAccCodefreshPipeline_Contexts(t *testing.T) {
13381339
})
13391340
}
13401341

1341-
func testAccCodefreshPipelineOptions(rName, repo, path, revision, context string, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied bool) string {
1342+
func testAccCodefreshPipelineOptions(rName, repo, path, revision, context string, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied bool, enableNotifications bool) string {
13421343
return fmt.Sprintf(`
13431344
resource "codefresh_pipeline" "test" {
13441345
@@ -1360,10 +1361,11 @@ resource "codefresh_pipeline" "test" {
13601361
options {
13611362
keep_pvcs_for_pending_approval = %t
13621363
pending_approval_concurrency_applied = %t
1364+
enable_notifications = %t
13631365
}
13641366
}
13651367
}
1366-
`, rName, repo, path, revision, context, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied)
1368+
`, rName, repo, path, revision, context, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied, enableNotifications)
13671369
}
13681370

13691371
func testAccCodefreshPipelineOnCreateBranchIgnoreTrigger(rName, repo, path, revision, context string, ignoreTrigger bool) string {

docs/resources/pipeline.md

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ Optional:
188188

189189
Optional:
190190

191+
- `enable_notifications` (Boolean)
191192
- `keep_pvcs_for_pending_approval` (Boolean) When build enters 'Pending Approval' state, volume should:
192193
* Default (attribute not specified): "Use Setting accounts"
193194
* true: "Remain (build remains active)"

0 commit comments

Comments
 (0)