From c59893f922ac7488d64c9c3e7152d6d8defbfcff Mon Sep 17 00:00:00 2001
From: Eesaan Atluri <atlurie@uab.edu>
Date: Tue, 9 Jul 2019 20:04:11 -0500
Subject: [PATCH] Define connecction block once for all provisioners.

All provisioners are using same connection details in the resource block
so define it once at the start of the block rather than using them once
per each provisioning task.
---
 main.tf | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/main.tf b/main.tf
index 3282705..37696ef 100644
--- a/main.tf
+++ b/main.tf
@@ -83,13 +83,15 @@ depends_on = ["openstack_networking_subnet_v2.dmzsubnet"]
 resource "openstack_compute_floatingip_associate_v2" "ohpc" {
   floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}"
   instance_id = "${openstack_compute_instance_v2.ohpc.id}"
+  
+  connection {
+    host    =  "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
+    #host        = "${openstack_networking_floatingip_v2.ohpc.address}"
+    user        = "centos"
+    private_key = "${file("~/.ssh/id_rsa")}"
+  }
 
   provisioner "remote-exec" {
-    connection {
-      host    =  "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
-      user        = "centos"
-      private_key = "${file("~/.ssh/id_rsa")}"
-    }
 
     inline = [
       "sudo mkdir -p /CRI_XCBC && sudo chown centos: /CRI_XCBC",
@@ -104,21 +106,9 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" {
   provisioner "file" {
     source      = "CRI_XCBC/"
     destination = "/CRI_XCBC/"
-    connection {
-      host    =  "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
-      #host        = "${openstack_networking_floatingip_v2.terraform.address}"
-      user        = "centos"
-      private_key = "${file("~/.ssh/id_rsa")}"
-    }
   }
 
   provisioner "remote-exec" {
-    connection {
-      host    =  "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
-      #host        = "${openstack_networking_floatingip_v2.ohpc.address}"
-      user        = "centos"
-      private_key = "${file("~/.ssh/id_rsa")}"
-    }
     inline = [
       "sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b"
     ]
-- 
GitLab