Merge "Add EXTRA_FORMULAS in cookiecutter testing"
diff --git a/cloud-deploy-pipeline.groovy b/cloud-deploy-pipeline.groovy
index 2f07d56..53e8c90 100644
--- a/cloud-deploy-pipeline.groovy
+++ b/cloud-deploy-pipeline.groovy
@@ -54,6 +54,11 @@
 
 def saltMaster
 
+if (STACK_TYPE == 'aws') {
+    venv_path = 'aws_venv'
+    env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
+}
+
 timestamps {
     node {
         try {
@@ -147,10 +152,6 @@
                     // set description
                     currentBuild.description = STACK_NAME
 
-                    // prepare configuration
-                    def venv_path = 'aws_venv'
-                    def env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
-
                     if (STACK_REUSE.toBoolean() == false) {
                         // get templates
                         git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
@@ -203,6 +204,11 @@
             // install k8s
             if (common.checkContains('STACK_INSTALL', 'k8s')) {
                 stage('Install Kubernetes infra') {
+                    // configure kubernetes_control_address - save loadbalancer
+                    def kubernetes_control_address = aws.getOutputs(venv_path, env_vars, STACK_NAME, 'ControlLoadBalancer')
+                    print(kubernetes_control_address)
+                    salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', 'kubernetes_control_address', kubernetes_control_address)
+
                     orchestrate.installKubernetesInfra(saltMaster)
                 }
 
@@ -215,9 +221,6 @@
                 stage('Scale Kubernetes computes') {
                     if (STACK_COMPUTE_COUNT > 0) {
                         if (STACK_TYPE == 'aws') {
-                            // configure aws
-                            def venv_path = 'aws_venv'
-                            def env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
 
                             // get stack info
                             def scaling_group = aws.getOutputs(venv_path, env_vars, STACK_NAME, 'ComputesScalingGroup')
@@ -227,6 +230,7 @@
 
                             // wait for computes to boot up
                             aws.waitForAutoscalingInstances(venv_path, env_vars, scaling_group)
+                            sleep(60)
                         }
 
                         orchestrate.installKubernetesCompute(saltMaster)
diff --git a/test-salt-formulas-pipeline.groovy b/test-salt-formulas-pipeline.groovy
index c3a2e51..bfa38e6 100644
--- a/test-salt-formulas-pipeline.groovy
+++ b/test-salt-formulas-pipeline.groovy
@@ -119,6 +119,7 @@
   } catch (Throwable e) {
      // If there was an error or exception thrown, the build failed
      currentBuild.result = "FAILURE"
+     ruby.runKitchenCommand("destroy")
      throw e
   } finally {
      if(currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")){