From 9adcfc4d210449d05ff67bb4baca567904e4a712 Mon Sep 17 00:00:00 2001
From: maximenoel8 <55169628+maximenoel8@users.noreply.github.com>
Date: Mon, 27 Nov 2023 09:10:02 +1300
Subject: [PATCH] Add support to paygo images on controller (#1426)

---
 modules/controller/main.tf      |  5 +++++
 modules/controller/variables.tf | 33 +++++++++++++++++++++++++++++++++
 salt/controller/bashrc          |  5 +++++
 3 files changed, 43 insertions(+)

diff --git a/modules/controller/main.tf b/modules/controller/main.tf
index a674a5a42..3326caea0 100644
--- a/modules/controller/main.tf
+++ b/modules/controller/main.tf
@@ -60,10 +60,15 @@ module "controller" {
     server_http_proxy         = var.server_http_proxy
     custom_download_endpoint  = var.custom_download_endpoint
     pxeboot_image             = var.pxeboot_configuration["image"]
+    is_using_paygo_server     = var.is_using_paygo_server
     is_using_build_image      = var.is_using_build_image
     is_using_scc_repositories = var.is_using_scc_repositories
+    server_instance_id        = var.server_instance_id
     container_runtime         = lookup(var.server_configuration, "runtime", null)
 
+    sle12_paygo_minion    = length(var.sle12_paygo_minion_configuration["hostnames"]) > 0 ? var.sle12_paygo_minion_configuration["hostnames"][0] : null
+    sle15_paygo_minion    = length(var.sle15_paygo_minion_configuration["hostnames"]) > 0 ? var.sle15_paygo_minion_configuration["hostnames"][0] : null
+    slesforsap15_paygo_minion = length(var.sleforsap15_paygo_minion_configuration["hostnames"]) > 0 ? var.sleforsap15_paygo_minion_configuration["hostnames"][0] : null
     sle11sp4_minion      = length(var.sle11sp4_minion_configuration["hostnames"]) > 0 ? var.sle11sp4_minion_configuration["hostnames"][0] : null
     sle11sp4_sshminion   = length(var.sle11sp4_sshminion_configuration["hostnames"]) > 0 ? var.sle11sp4_sshminion_configuration["hostnames"][0] : null
     sle11sp4_client      = length(var.sle11sp4_client_configuration["hostnames"]) > 0 ? var.sle11sp4_client_configuration["hostnames"][0] : null
diff --git a/modules/controller/variables.tf b/modules/controller/variables.tf
index f8135c324..b3f632687 100644
--- a/modules/controller/variables.tf
+++ b/modules/controller/variables.tf
@@ -112,6 +112,28 @@ variable "monitoringserver_configuration" {
   }
 }
 
+variable "sle12_paygo_minion_configuration" {
+  description = "use module.<SLE12_PAYGO_MINION>.configuration, see main.tf.libvirt-testsuite.example"
+  default = {
+    hostnames = []
+  }
+}
+
+variable "sle15_paygo_minion_configuration" {
+  description = "use module.<SLE15_PAYGO_MINION>.configuration, see main.tf.libvirt-testsuite.example"
+  default = {
+    hostnames = []
+  }
+}
+
+variable "sleforsap15_paygo_minion_configuration" {
+  description = "use module.<SLEFORSAP15_PAYGO_MINION>.configuration, see main.tf.libvirt-testsuite.example"
+  default = {
+    hostnames = []
+  }
+}
+
+
 variable "sle11sp4_minion_configuration" {
   description = "use module.<SLE11SP4_MINION>.configuration, see main.tf.libvirt-testsuite.example"
   default = {
@@ -712,6 +734,11 @@ variable "no_mirror" {
   default     = false
 }
 
+variable "is_using_paygo_server" {
+  description = "Specify to controller that server image is a paygo image"
+  default     = false
+}
+
 variable "is_using_build_image" {
 description = "Specify to controller that server image is a build image"
 default     = false
@@ -722,6 +749,12 @@ variable "is_using_scc_repositories" {
   default     = false
 }
 
+variable "server_instance_id" {
+  description = "Server instance ID"
+  default     = null
+}
+
+
 variable "nested_vm_host" {
   description = "Hostname for a nested VM if it is used, see README_TESTING.md"
   type        = string
diff --git a/salt/controller/bashrc b/salt/controller/bashrc
index f134cd40f..33b5cd651 100644
--- a/salt/controller/bashrc
+++ b/salt/controller/bashrc
@@ -24,6 +24,9 @@ export VIRTHOST_KVM_PASSWORD="linux" {% else %}# no KVM host defined {% endif %}
 {% if grains.get('mirror') | default(false, true) %}export MIRROR="yes" {% else %}# no mirror used {% endif %}
 
 # QAM clients
+{% if grains.get('sle12_paygo_minion') | default(false, true) %}export SLE12_PAYGO_MINION="{{ grains.get('sle12_paygo_minion') }}" {% else %}# no SLE12_PAYGO minion defined {% endif %}
+{% if grains.get('sle15_paygo_minion') | default(false, true) %}export SLE15_PAYGO_MINION="{{ grains.get('sle15_paygo_minion') }}" {% else %}# no SLE15_PAYGO minion defined {% endif %}
+{% if grains.get('sleforsap15_paygo_minion') | default(false, true) %}export SLEFORSAP15_PAYGO_MINION="{{ grains.get('sleforsap15_paygo_minion') }}" {% else %}# no SLEFORSAP15_PAYGO minion defined {% endif %}
 {% if grains.get('sle11sp4_minion') | default(false, true) %}export SLE11SP4_MINION="{{ grains.get('sle11sp4_minion') }}" {% else %}# no SLE11SP4 minion defined {% endif %}
 {% if grains.get('sle11sp4_sshminion') | default(false, true) %}export SLE11SP4_SSHMINION="{{ grains.get('sle11sp4_sshminion') }}" {% else %}# no SLE11SP4 ssh minion defined {% endif %}
 {% if grains.get('sle11sp4_client') | default(false, true) %}export SLE11SP4_CLIENT="{{ grains.get('sle11sp4_client') }}" {% else %}# no SLE11SP4 client defined {% endif %}
@@ -111,7 +114,9 @@ export AUTH_REGISTRY_CREDENTIALS="{{ grains.get('auth_registry_username') }}|{{
 export PROVIDER="{{ grains.get('provider') }}"
 {% if grains.get('container_runtime') | default(false, true) %}export CONTAINER_RUNTIME="{{ grains.get('container_runtime') }}" {% else %}# no CONTAINER_RUNTIME used {% endif %}
 {% if 'build_image' not in grains.get('product_version') | default('', true) %}export IS_USING_BUILD_IMAGE="{{ grains.get('is_using_build_image') }}" {% endif %}
+export IS_USING_PAYGO_SERVER="{{ grains.get('is_using_paygo_server') }}"
 export IS_USING_SCC_REPOSITORIES="{{ grains.get('is_using_scc_repositories') }}"
+export SERVER_INSTANCE_ID="{{ grains.get('server_instance_id') }}"
 
 #### Generate certificates for Google Chrome
 if [ ! -f /etc/pki/trust/anchors/$SERVER.cert ]; then