From fb919c4db252ccaf4feb7d545720ae222475b0c8 Mon Sep 17 00:00:00 2001 From: Ilia Medvedev Date: Sun, 25 Feb 2024 10:35:02 +0200 Subject: [PATCH 1/2] re-implement https://github.com/codefresh-io/terraform-provider-codefresh/pull/86 --- codefresh/resource_pipeline.go | 9 +++++++++ codefresh/resource_pipeline_test.go | 8 +++++--- docs/resources/pipeline.md | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/codefresh/resource_pipeline.go b/codefresh/resource_pipeline.go index 4430262..48f8e38 100644 --- a/codefresh/resource_pipeline.go +++ b/codefresh/resource_pipeline.go @@ -600,6 +600,10 @@ Pipeline concurrency policy: Builds on 'Pending Approval' state should be: Type: schema.TypeBool, Optional: true, }, + "enable_notifications": { + Type: schema.TypeBool, + Optional: true, + }, }, }, }, @@ -762,6 +766,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) @@ -1074,6 +1080,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 07dff4a..f89e2e6 100644 --- a/codefresh/resource_pipeline_test.go +++ b/codefresh/resource_pipeline_test.go @@ -702,13 +702,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", }), ), }, @@ -1278,7 +1279,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" { @@ -1300,10 +1301,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 9313d8a..46add3c 100644 --- a/docs/resources/pipeline.md +++ b/docs/resources/pipeline.md @@ -187,6 +187,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)" From 9be5f6dc27263ce8fe103cdb79f442a76b87e39a Mon Sep 17 00:00:00 2001 From: Ilia Medvedev Date: Sun, 25 Feb 2024 10:43:12 +0200 Subject: [PATCH 2/2] set deafult --- codefresh/resource_pipeline.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codefresh/resource_pipeline.go b/codefresh/resource_pipeline.go index 48f8e38..95e256d 100644 --- a/codefresh/resource_pipeline.go +++ b/codefresh/resource_pipeline.go @@ -602,7 +602,8 @@ Pipeline concurrency policy: Builds on 'Pending Approval' state should be: }, "enable_notifications": { Type: schema.TypeBool, - Optional: true, + Optional: true, + Default: false, }, }, },