From a7a7423f01ed23021367dc20f5153d0b8dce933c Mon Sep 17 00:00:00 2001
From: Timo Furrer <tfurrer@gitlab.com>
Date: Fri, 19 Jan 2024 07:44:37 +0100
Subject: [PATCH] Add suggestion job

---
 backports/.Base.gitlab-ci.yml                 | 27 +++++++++++++++++++
 backports/OpenTofu.gitlab-ci.yml              |  3 +++
 backports/OpenTofu/Base.gitlab-ci.yml         | 27 +++++++++++++++++++
 .../BackportTemplates.gitlab-ci.yml           |  3 +++
 4 files changed, 60 insertions(+)

diff --git a/backports/.Base.gitlab-ci.yml b/backports/.Base.gitlab-ci.yml
index 738097d..4317934 100644
--- a/backports/.Base.gitlab-ci.yml
+++ b/backports/.Base.gitlab-ci.yml
@@ -23,3 +23,30 @@ variables:
   TF_ROOT: ${CI_PROJECT_DIR}
   # The name of the state file used by the GitLab Managed Terraform state backend
   TF_STATE_NAME: default
+
+.opentofu:suggest-component:
+  stage: validate
+  needs: []
+  allow_failure: true
+  rules:
+    if: '"$CI_SERVER_HOST" == "gitlab.com"'
+  image: alpine:3.19
+  script:
+    - |
+      echo "You are using the OpenTofu CI/CD template on GitLab.com which is not recommended."
+      echo "This template is available for self-managed customers until CI/CD components are available to them and it will be removed asap."
+      echo
+      echo "We recommed that you migrate to the OpenTofu CI/CD component instead."
+      echo "The OpenTofu CI/CD component with a default configuration can be included as follows:"
+      echo
+      echo "include:"
+      echo "  - component: gitlab.com/components/opentofu/full-pipeline@0.1.0"
+      echo "    inputs:"
+      echo "      version: latest"
+      echo "      opentofu_version: 1.6.0"
+      echo
+      echo "stages: [validate, test, build, deploy]"
+      echo
+      echo "You can read about more about the OpenTofu CI/CD component here:"
+      echo "https://gitlab.com/components/opentofu"
+    - false
diff --git a/backports/OpenTofu.gitlab-ci.yml b/backports/OpenTofu.gitlab-ci.yml
index 3a5d01e..b0510cd 100644
--- a/backports/OpenTofu.gitlab-ci.yml
+++ b/backports/OpenTofu.gitlab-ci.yml
@@ -17,6 +17,9 @@ include:
 
 stages: [validate, build, deploy]
 
+suggest-component:
+  extends: .opentofu:suggest-component
+
 fmt:
   extends: .opentofu:fmt
 
diff --git a/backports/OpenTofu/Base.gitlab-ci.yml b/backports/OpenTofu/Base.gitlab-ci.yml
index cf52a46..cf127ac 100644
--- a/backports/OpenTofu/Base.gitlab-ci.yml
+++ b/backports/OpenTofu/Base.gitlab-ci.yml
@@ -24,6 +24,33 @@ variables:
   # The name of the state file used by the GitLab Managed Terraform state backend
   TF_STATE_NAME: default
 
+.opentofu:suggest-component:
+  stage: validate
+  needs: []
+  allow_failure: true
+  rules:
+    if: '"$CI_SERVER_HOST" == "gitlab.com"'
+  image: alpine:3.19
+  script:
+    - |
+      echo "You are using the OpenTofu CI/CD template on GitLab.com which is not recommended."
+      echo "This template is available for self-managed customers until CI/CD components are available to them and it will be removed asap."
+      echo
+      echo "We recommed that you migrate to the OpenTofu CI/CD component instead."
+      echo "The OpenTofu CI/CD component with a default configuration can be included as follows:"
+      echo
+      echo "include:"
+      echo "  - component: gitlab.com/components/opentofu/full-pipeline@0.1.0"
+      echo "    inputs:"
+      echo "      version: latest"
+      echo "      opentofu_version: 1.6.0"
+      echo
+      echo "stages: [validate, test, build, deploy]"
+      echo
+      echo "You can read about more about the OpenTofu CI/CD component here:"
+      echo "https://gitlab.com/components/opentofu"
+    - false
+
 .opentofu:default:
   image:
     name: '$GITLAB_OPENTOFU_IMAGE_REGISTRY_BASE/gitlab-opentofu:$GITLAB_OPENTOFU_VERSION-opentofu$OPENTOFU_VERSION'
diff --git a/tests/integration-tests/BackportTemplates.gitlab-ci.yml b/tests/integration-tests/BackportTemplates.gitlab-ci.yml
index a6e872b..2565185 100644
--- a/tests/integration-tests/BackportTemplates.gitlab-ci.yml
+++ b/tests/integration-tests/BackportTemplates.gitlab-ci.yml
@@ -5,6 +5,9 @@ stages: [validate, test, build, deploy, cleanup]
 
 # Required to run everything immediately, instead of manually.
 
+suggest-component:
+  extends: .opentofu:suggest-component
+
 fmt:
   extends: .opentofu:fmt
   rules: [{when: always}]
-- 
GitLab