]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Fixing lib/cr_tf/handler.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Nov 2019 14:06:05 +0000 (15:06 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Nov 2019 14:06:05 +0000 (15:06 +0100)
lib/cr_tf/handler.py

index ac8cff4398645f51f3e465fc8127b13bc7599414..e0d540df2c4da34d43a90396a75899fb472e808c 100644 (file)
@@ -61,7 +61,7 @@ from .terraform.disk import TerraformDisk
 
 from .xlate import XLATOR
 
-__version__ = '3.1.4'
+__version__ = '3.1.5'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -2238,6 +2238,7 @@ class CreateTerraformHandler(BaseHandler):
         vs_name = None
         for vs_name in self.vsphere.keys():
             break
+        vsphere = self.vsphere[vs_name]
 
         LOG.debug(_("Creating {!r} ...").format('dc.tf'))
         if self.verbose > 1:
@@ -2246,7 +2247,7 @@ class CreateTerraformHandler(BaseHandler):
 
         content = textwrap.dedent('''\
         # filename: dc.tf
-        # Configuring the VMware vSphere Provider and some dependend common used objects
+        # Configuring the VMware VSphere Provider and some dependend common used objects
 
         provider "vsphere" {
           vsphere_server       = var.vsphere_vcenter
@@ -2280,7 +2281,7 @@ class CreateTerraformHandler(BaseHandler):
                 pv=cluster.resource_pool_var, pn=cluster.resource_pool_name)
 
         if self.used_dc_clusters:
-            for dsc_name in sorted(self.used_dc_clusters, key=str.lower):
+            for dsc_name in sorted(self.used_dc_clusters[vs_name], key=str.lower):
                 dsc_tf_name = self.vsphere[vs_name].ds_cluster_mapping[dsc_name]
                 tpl = textwrap.dedent('''\
                 data "vsphere_datastore_cluster" "{tn}" {{
@@ -2292,7 +2293,7 @@ class CreateTerraformHandler(BaseHandler):
                 content += tpl.format(tn=dsc_tf_name, n=dsc_name)
 
         if self.used_datastores:
-            for ds_name in sorted(self.used_datastores, key=str.lower):
+            for ds_name in sorted(self.used_datastores[vs_name], key=str.lower):
                 ds_tf_name = self.vsphere[vs_name].ds_mapping[ds_name]
                 tpl = textwrap.dedent('''\
                 data "vsphere_datastore" "{tn}" {{
@@ -2303,7 +2304,7 @@ class CreateTerraformHandler(BaseHandler):
                 ''')
                 content += tpl.format(tn=ds_tf_name, n=ds_name)
 
-        for net_name in sorted(self.used_networks, key=str.lower):
+        for net_name in sorted(self.used_networks[vs_name], key=str.lower):
             net_tf_name = self.vsphere[vs_name].network_mapping[net_name]
             tpl = textwrap.dedent('''\
             data "vsphere_network" "{tn}" {{
@@ -2315,8 +2316,8 @@ class CreateTerraformHandler(BaseHandler):
             content += tpl.format(n=net_name, tn=net_tf_name)
 
         if self.vsphere_templates:
-            for tname in sorted(self.vsphere_templates.keys(), key=str.lower):
-                tpl_tf_name = self.vsphere_templates[tname]['tf_name']
+            for tname in sorted(self.vsphere_templates[vs_name].keys(), key=str.lower):
+                tpl_tf_name = self.vsphere_templates[vs_name][tname]['tf_name']
                 tpl = textwrap.dedent('''\
                 data "vsphere_virtual_machine" "{tn}" {{
                   name          = "{n}"