From 53dc08b4e625a825818963711eed01fb555b5cb7 Mon Sep 17 00:00:00 2001
From: Timo Furrer <tfurrer@gitlab.com>
Date: Mon, 4 Nov 2024 20:36:30 +0100
Subject: [PATCH] Support `cache_policy` input in job templates

Changelog: added

Refs https://gitlab.com/components/opentofu/-/issues/35
---
 templates/apply.yml          | 5 +++++
 templates/custom-command.yml | 6 ++++++
 templates/destroy.yml        | 5 +++++
 templates/fmt.yml            | 6 ++++++
 templates/graph.yml          | 5 +++++
 templates/plan.yml           | 5 +++++
 templates/test.yml           | 5 +++++
 templates/validate.yml       | 6 ++++++
 8 files changed, 43 insertions(+)

diff --git a/templates/apply.yml b/templates/apply.yml
index adaec37..7184145 100644
--- a/templates/apply.yml
+++ b/templates/apply.yml
@@ -95,6 +95,10 @@ spec:
       default: [{when: on_success}]
       type: array
       description: 'Defines the `rules` of the job.'
+    cache_policy:
+      default: pull-push
+      type: string
+      description: 'Defines the cache policy of the job.'
 
 ---
 
@@ -107,6 +111,7 @@ spec:
   rules: $[[ inputs.rules ]]
   cache:
     key: "$__CACHE_KEY_HACK"
+    policy: $[[ inputs.cache_policy ]]
     paths:
       - $TF_ROOT/.terraform/
   variables:
diff --git a/templates/custom-command.yml b/templates/custom-command.yml
index 49bb171..762d46a 100644
--- a/templates/custom-command.yml
+++ b/templates/custom-command.yml
@@ -82,6 +82,11 @@ spec:
       type: array
       description: 'Defines the `needs` of the job.'
 
+    cache_policy:
+      default: pull-push
+      type: string
+      description: 'Defines the cache policy of the job.'
+
 ---
 
 '$[[ inputs.as ]]':
@@ -89,6 +94,7 @@ spec:
   needs: $[[ inputs.needs ]]
   cache:
     key: "$__CACHE_KEY_HACK"
+    policy: $[[ inputs.cache_policy ]]
     paths:
       - $TF_ROOT/.terraform/
   variables:
diff --git a/templates/destroy.yml b/templates/destroy.yml
index 4519979..69af628 100644
--- a/templates/destroy.yml
+++ b/templates/destroy.yml
@@ -95,6 +95,10 @@ spec:
       default: [{when: on_success}]
       type: array
       description: 'Defines the `rules` of the job.'
+    cache_policy:
+      default: pull-push
+      type: string
+      description: 'Defines the cache policy of the job.'
 
 ---
 
@@ -107,6 +111,7 @@ spec:
   rules: $[[ inputs.rules ]]
   cache:
     key: "$__CACHE_KEY_HACK"
+    policy: $[[ inputs.cache_policy ]]
     paths:
       - $TF_ROOT/.terraform/
   variables:
diff --git a/templates/fmt.yml b/templates/fmt.yml
index cba5d83..59ac9ce 100644
--- a/templates/fmt.yml
+++ b/templates/fmt.yml
@@ -92,6 +92,11 @@ spec:
       type: array
       description: 'Defines the `rules` of the job.'
 
+    cache_policy:
+      default: pull-push
+      type: string
+      description: 'Defines the cache policy of the job.'
+
 ---
 
 '$[[ inputs.as ]]':
@@ -101,6 +106,7 @@ spec:
   allow_failure: $[[ inputs.allow_failure ]]
   cache:
     key: "$__CACHE_KEY_HACK"
+    policy: $[[ inputs.cache_policy ]]
     paths:
       - $TF_ROOT/.terraform/
   variables:
diff --git a/templates/graph.yml b/templates/graph.yml
index 27b0296..0e57dee 100644
--- a/templates/graph.yml
+++ b/templates/graph.yml
@@ -89,6 +89,10 @@ spec:
       default: []
       type: array
       description: 'Defines the `needs` of the job.'
+    cache_policy:
+      default: pull-push
+      type: string
+      description: 'Defines the cache policy of the job.'
 
 ---
 
@@ -97,6 +101,7 @@ spec:
   needs: $[[ inputs.needs ]]
   cache:
     key: "$__CACHE_KEY_HACK"
+    policy: $[[ inputs.cache_policy ]]
     paths:
       - $TF_ROOT/.terraform/
   variables:
diff --git a/templates/plan.yml b/templates/plan.yml
index 9987fcd..659903c 100644
--- a/templates/plan.yml
+++ b/templates/plan.yml
@@ -94,6 +94,10 @@ spec:
       default: [{when: on_success}]
       type: array
       description: 'Defines the `rules` of the job.'
+    cache_policy:
+      default: pull-push
+      type: string
+      description: 'Defines the cache policy of the job.'
 
 ---
 
@@ -116,6 +120,7 @@ spec:
   rules: $[[ inputs.rules ]]
   cache:
     key: "$__CACHE_KEY_HACK"
+    policy: $[[ inputs.cache_policy ]]
     paths:
       - $TF_ROOT/.terraform/
   variables:
diff --git a/templates/test.yml b/templates/test.yml
index 1978669..ff98fcc 100644
--- a/templates/test.yml
+++ b/templates/test.yml
@@ -91,6 +91,10 @@ spec:
       default: [{when: on_success}]
       type: array
       description: 'Defines the `rules` of the job.'
+    cache_policy:
+      default: pull-push
+      type: string
+      description: 'Defines the cache policy of the job.'
 
 ---
 
@@ -100,6 +104,7 @@ spec:
   rules: $[[ inputs.rules ]]
   cache:
     key: "$__CACHE_KEY_HACK"
+    policy: $[[ inputs.cache_policy ]]
     paths:
       - $TF_ROOT/.terraform/
   variables:
diff --git a/templates/validate.yml b/templates/validate.yml
index 22b1ab5..49b5827 100644
--- a/templates/validate.yml
+++ b/templates/validate.yml
@@ -88,6 +88,11 @@ spec:
       type: array
       description: 'Defines the `rules` of the job.'
 
+    cache_policy:
+      default: pull-push
+      type: string
+      description: 'Defines the cache policy of the job.'
+
 ---
 
 '$[[ inputs.as ]]':
@@ -95,6 +100,7 @@ spec:
   rules: $[[ inputs.rules ]]
   cache:
     key: "$__CACHE_KEY_HACK"
+    policy: $[[ inputs.cache_policy ]]
     paths:
       - $TF_ROOT/.terraform/
   variables:
-- 
GitLab