[AETHER]-615 Update the Jenkins job

1. Replace the Rancher CLI with Terraform in TOST related jobs.
2. Still the Rancher CLI in FluentBit but will fix it soon
3. Add new jenkins job to install shared resources

Change-Id: I6e4d5ecf696e7a17a1d954df19093005bf14bf8c
diff --git a/jjb/pipeline/tost-deploy.groovy b/jjb/pipeline/tost-deploy.groovy
index 42961ff..2eba5ad 100644
--- a/jjb/pipeline/tost-deploy.groovy
+++ b/jjb/pipeline/tost-deploy.groovy
@@ -7,6 +7,8 @@
     }
     environment {
         KUBECONFIG = credentials("${params.k8s_config}")
+        gcp = credentials("${params.gcp_credential}")
+        rancher_dev = credentials("${params.rancher_api_env}")
     }
     stages {
         stage('Install tools') {
@@ -14,7 +16,7 @@
                 sh '''
                 set -x
                 apt-get update -y
-                apt-get install -y curl wget jq git
+                apt-get install -y curl wget jq git unzip
 
                 # Install kubectl
                 curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
@@ -23,9 +25,61 @@
 
                 # Test Kubectl & Rancher
                 kubectl get nodes
+
+                # Install
+                wget https://releases.hashicorp.com/terraform/0.13.2/terraform_0.13.2_linux_amd64.zip
+                unzip terraform_0.13.2_linux_amd64.zip
+                mv terraform /usr/local/bin
+                terraform version
                 '''
             }
         }
+
+        stage('Init Terraform') {
+            steps {
+                withCredentials([sshUserPrivateKey(credentialsId: "aether_jenkins", keyFileVariable: 'keyfile')]) {
+
+                sh """#!/bin/bash
+                set -x
+                mkdir -p ~/.ssh
+                ssh-keyscan -t rsa -p 29418 ${git_server} >> ~/.ssh/known_hosts
+cat <<EOF > ~/.ssh/config
+Host ${git_server}
+  User ${git_user}
+  Hostname ${git_server}
+  Port 29418
+  IdentityFile ${keyfile}
+EOF
+
+                git clone "ssh://${git_server}:29418/${git_repo}"
+                cd ${workspace}/${git_repo}/${terraform_dir}/tost
+                if [ ! -z ${config_review} ] && [ ! -z ${config_patchset} ]; then
+                    CFG_LAST2=\$(echo ${config_review} | tail -c 3)
+                    git fetch "ssh://${git_server}:29418/${git_repo}" refs/changes/\${CFG_LAST2}/${config_review}/${config_patchset} && git checkout FETCH_HEAD
+                fi
+                GOOGLE_BACKEND_CREDENTIALS=${gcp} terraform init
+
+                """
+                }
+            }
+        }
+        stage('Perform Terraform') {
+             steps {
+                sh """
+                cd ${workspace}/${git_repo}/${terraform_dir}/tost
+                GOOGLE_BACKEND_CREDENTIALS=${gcp} terraform destroy -var-file=${rancher_dev} -var 'cluster_name=${rancher_cluster}' -var-file=app_map.tfvars -auto-approve
+                GOOGLE_BACKEND_CREDENTIALS=${gcp} terraform apply -var-file=${rancher_dev} -var 'cluster_name=${rancher_cluster}' -var-file=app_map.tfvars -auto-approve
+
+                """
+             }
+        }
+
+        stage('Install shared resources') {
+            steps {
+                sh(script: "date -u")
+                    build(job: "${params.job_name}-shared")
+            }
+        }
         stage('Parallel Stage') {
             parallel {
                 stage('onos') {
@@ -48,7 +102,7 @@
                 }
             }
         }
-        stage('E2E Testing') {
+    stage('E2E Testing') {
             options {
                 timeout(time: 120, unit: "SECONDS")
             }
@@ -101,6 +155,7 @@
             if [ ! -z "${params.target_server}" ]; then
                 kubectl delete -f test.yaml
             fi
+            rm -rf ${workspace}/${git_repo}
             """
             cleanWs()
         }