From 27a482a76e7ee35b94f8539a50ecdf325f8711cb Mon Sep 17 00:00:00 2001
From: Timo Furrer <tfurrer@gitlab.com>
Date: Tue, 5 Nov 2024 14:59:29 +0100
Subject: [PATCH] Support `warning_on_none_empty_plan` input in pipeline
 templates

Changelog: added
---
 templates/full-pipeline.yml         | 7 ++++++-
 templates/job-templates.yml         | 5 +++++
 templates/validate-plan-apply.yml   | 5 +++++
 templates/validate-plan-destroy.yml | 7 ++++++-
 templates/validate-plan.yml         | 5 +++++
 5 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/templates/full-pipeline.yml b/templates/full-pipeline.yml
index 477e3c5..65a2195 100644
--- a/templates/full-pipeline.yml
+++ b/templates/full-pipeline.yml
@@ -155,6 +155,10 @@ spec:
         - when: manual
       type: array
       description: 'Defines the `rules` of the `delete-state` job.'
+    warning_on_none_empty_plan:
+      default: false
+      type: boolean
+      description: 'Whether to mark the job with a warning if the plan contains a diff.'
 
 ---
 
@@ -220,6 +224,7 @@ include:
       artifacts_access: $[[ inputs.plan_artifacts_access ]]
       var_file: $[[ inputs.var_file ]]
       rules: $[[ inputs.plan_rules ]]
+      warning_on_none_empty_plan: $[[ inputs.warning_on_none_empty_plan ]]
   - local: '/templates/apply.yml'
     inputs:
       as: '$[[ inputs.job_name_prefix ]]apply'
@@ -262,5 +267,5 @@ include:
 # job template, but the issue is that we cannot default it to something
 # meaningful other than `null` - but `null` is also not yet supported, see
 # https://gitlab.com/gitlab-org/gitlab/-/issues/440468
-$[[ inputs.job_name_prefix ]]delete-state:
+'$[[ inputs.job_name_prefix ]]delete-state':
   needs: ['$[[ inputs.job_name_prefix ]]destroy']
diff --git a/templates/job-templates.yml b/templates/job-templates.yml
index f4602c9..69120b5 100644
--- a/templates/job-templates.yml
+++ b/templates/job-templates.yml
@@ -101,6 +101,10 @@ spec:
       default: ''
       type: string
       description: 'Path to a variables files relative to root_dir.'
+    warning_on_none_empty_plan:
+      default: false
+      type: boolean
+      description: 'Whether to mark the job with a warning if the plan contains a diff.'
 
 ---
 
@@ -167,6 +171,7 @@ include:
       state_name: $[[ inputs.state_name ]]
       plan_name: $[[ inputs.plan_name ]]
       var_file: $[[ inputs.var_file ]]
+      warning_on_none_empty_plan: $[[ inputs.warning_on_none_empty_plan ]]
   - local: '/templates/apply.yml'
     inputs:
       as: '$[[ inputs.job_name_prefix ]]apply'
diff --git a/templates/validate-plan-apply.yml b/templates/validate-plan-apply.yml
index 8fd8a92..9b9a81a 100644
--- a/templates/validate-plan-apply.yml
+++ b/templates/validate-plan-apply.yml
@@ -125,6 +125,10 @@ spec:
           when: manual
       type: array
       description: 'Defines the `rules` of the `apply` job.'
+    warning_on_none_empty_plan:
+      default: false
+      type: boolean
+      description: 'Whether to mark the job with a warning if the plan contains a diff.'
 
 ---
 
@@ -172,6 +176,7 @@ include:
       artifacts_access: $[[ inputs.plan_artifacts_access ]]
       var_file: $[[ inputs.var_file ]]
       rules: $[[ inputs.plan_rules ]]
+      warning_on_none_empty_plan: $[[ inputs.warning_on_none_empty_plan ]]
   - local: '/templates/apply.yml'
     inputs:
       as: '$[[ inputs.job_name_prefix ]]apply'
diff --git a/templates/validate-plan-destroy.yml b/templates/validate-plan-destroy.yml
index 7e81b35..cc5ceb4 100644
--- a/templates/validate-plan-destroy.yml
+++ b/templates/validate-plan-destroy.yml
@@ -130,6 +130,10 @@ spec:
         - when: manual
       type: array
       description: 'Defines the `rules` of the `delete-state` job.'
+    warning_on_none_empty_plan:
+      default: false
+      type: boolean
+      description: 'Whether to mark the job with a warning if the plan contains a diff.'
 
 ---
 
@@ -178,6 +182,7 @@ include:
       destroy: true
       var_file: $[[ inputs.var_file ]]
       rules: $[[ inputs.plan_rules ]]
+      warning_on_none_empty_plan: $[[ inputs.warning_on_none_empty_plan ]]
   - local: '/templates/destroy.yml'
     inputs:
       as: '$[[ inputs.job_name_prefix ]]destroy'
@@ -206,5 +211,5 @@ include:
 # job template, but the issue is that we cannot default it to something
 # meaningful other than `null` - but `null` is also not yet supported, see
 # https://gitlab.com/gitlab-org/gitlab/-/issues/440468
-$[[ inputs.job_name_prefix ]]delete-state:
+'$[[ inputs.job_name_prefix ]]delete-state':
   needs: ['$[[ inputs.job_name_prefix ]]destroy']
diff --git a/templates/validate-plan.yml b/templates/validate-plan.yml
index a491411..feeba5a 100644
--- a/templates/validate-plan.yml
+++ b/templates/validate-plan.yml
@@ -111,6 +111,10 @@ spec:
         - if: $CI_COMMIT_BRANCH        # If there's no open merge request, add it to a *branch* pipeline instead.
       type: array
       description: 'Defines the `rules` of the `plan` job.'
+    warning_on_none_empty_plan:
+      default: false
+      type: boolean
+      description: 'Whether to mark the job with a warning if the plan contains a diff.'
 
 ---
 
@@ -158,3 +162,4 @@ include:
       artifacts_access: $[[ inputs.artifacts_access ]]
       var_file: $[[ inputs.var_file ]]
       rules: $[[ inputs.plan_rules ]]
+      warning_on_none_empty_plan: $[[ inputs.warning_on_none_empty_plan ]]
-- 
GitLab