From 80248af246aff7d55addba7e64c93fccae1b2379 Mon Sep 17 00:00:00 2001 From: ilia-medvedev-codefresh Date: Mon, 26 Feb 2024 18:11:38 +0200 Subject: [PATCH] Feat: Add enable notifications on pipeline level (credit @nickborysov) (#136) ## What Add enable notifications on pipeline resource level ## Why ## Notes re-implement stale https://github.com/codefresh-io/terraform-provider-codefresh/pull/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)._ --- codefresh/resource_pipeline.go | 10 ++++++++++ codefresh/resource_pipeline_test.go | 8 +++++--- docs/resources/pipeline.md | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/codefresh/resource_pipeline.go b/codefresh/resource_pipeline.go index b3fd98c..698ab3f 100644 --- a/codefresh/resource_pipeline.go +++ b/codefresh/resource_pipeline.go @@ -606,6 +606,11 @@ Pipeline concurrency policy: Builds on 'Pending Approval' state should be: Type: schema.TypeBool, Optional: true, }, + "enable_notifications": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, }, }, @@ -768,6 +773,8 @@ func flattenSpec(spec cfclient.Spec) []interface{} { options["keep_pvcs_for_pending_approval"] = valueOption case keyOption == "pendingApprovalConcurrencyApplied": options["pending_approval_concurrency_applied"] = valueOption + case keyOption == "enableNotifications": + options["enable_notifications"] = valueOption } } resOptions = append(resOptions, options) @@ -1082,6 +1089,9 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) { if pendingApprovalConcurrencyApplied, ok := d.GetOkExists("spec.0.options.0.pending_approval_concurrency_applied"); ok { pipelineSpecOption["pendingApprovalConcurrencyApplied"] = pendingApprovalConcurrencyApplied.(bool) } + if enableNotifications, ok := d.GetOkExists("spec.0.options.0.enable_notifications"); ok { + pipelineSpecOption["enableNotifications"] = enableNotifications.(bool) + } pipeline.Spec.Options = pipelineSpecOption } else { pipeline.Spec.Options = nil diff --git a/codefresh/resource_pipeline_test.go b/codefresh/resource_pipeline_test.go index d3530aa..9bd580c 100644 --- a/codefresh/resource_pipeline_test.go +++ b/codefresh/resource_pipeline_test.go @@ -735,13 +735,14 @@ func TestAccCodefreshPipelineOptions(t *testing.T) { CheckDestroy: testAccCheckCodefreshPipelineDestroy, Steps: []resource.TestStep{ { - Config: testAccCodefreshPipelineOptions(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true, false), + Config: testAccCodefreshPipelineOptions(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true, false, false), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName, &pipeline), resource.TestCheckResourceAttr(resourceName, "name", name), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "spec.0.options.*", map[string]string{ "keep_pvcs_for_pending_approval": "true", "pending_approval_concurrency_applied": "false", + "enable_notifications": "false", }), ), }, @@ -1338,7 +1339,7 @@ func TestAccCodefreshPipeline_Contexts(t *testing.T) { }) } -func testAccCodefreshPipelineOptions(rName, repo, path, revision, context string, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied bool) string { +func testAccCodefreshPipelineOptions(rName, repo, path, revision, context string, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied bool, enableNotifications bool) string { return fmt.Sprintf(` resource "codefresh_pipeline" "test" { @@ -1360,10 +1361,11 @@ resource "codefresh_pipeline" "test" { options { keep_pvcs_for_pending_approval = %t pending_approval_concurrency_applied = %t + enable_notifications = %t } } } -`, rName, repo, path, revision, context, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied) +`, rName, repo, path, revision, context, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied, enableNotifications) } func testAccCodefreshPipelineOnCreateBranchIgnoreTrigger(rName, repo, path, revision, context string, ignoreTrigger bool) string { diff --git a/docs/resources/pipeline.md b/docs/resources/pipeline.md index 8d4014e..589a117 100644 --- a/docs/resources/pipeline.md +++ b/docs/resources/pipeline.md @@ -188,6 +188,7 @@ Optional: Optional: +- `enable_notifications` (Boolean) - `keep_pvcs_for_pending_approval` (Boolean) When build enters 'Pending Approval' state, volume should: * Default (attribute not specified): "Use Setting accounts" * true: "Remain (build remains active)"