python-terrascript
python-terrascript copied to clipboard
Where i can find documentation more detailed for attributes resources for providers?
Greetings.
I'm using the vsphere provider, but i don't have clarify about how to use this provider through terrascript:
Actually i'm using the following configuration:
config += data.vsphere_datacenter('dc',
name = "MainDC",
)
config += data.vsphere_resource_pool('pool',
name = "VW_CLUSTER/Resources",
datacenter_id = data.vsphere_datacenter.datacenter.id
)
returning the following error:
datacenter_id = data.vsphere_datacenter.datacenter.id
AttributeError: type object 'vsphere_datacenter' has no attribute 'dc'
just comparing with this: https://registry.terraform.io/providers/hashicorp/vsphere/latest/docs
Im sure tha't i'm doing this wrong, but where i can check atributtes expecteds by classes?
Thanks for your time.
Regerads
Hi @VGzsysadm, here's some background information to start with.
Terrascript is only a thin wrapper and does not check whether the resulting Terraform configuration is correct.
The data.vsphere_datacenter
and all other classes are effectively just "aliases" for terrascript.Data
, e.g.
class vsphere_datacenter(terrascript.Data):
pass
which itself is simply a terrascript.NamedBlock
.
class Data(NamedBlock):
""" Terraform data source block. """
pass
class NamedBlock(Block):
def __init__(self, _name, **kwargs):
self._name = _name
super().__init__(**kwargs)
So if you take the definition of the vsphere_datacenter data source in Terraform
data "vsphere_datacenter" "datacenter" {
name = "dc1"
}
"datacenter"
is the name of the block and "dc1"
the name attribute of the data source.
Regarding your issue; I am quite out of practice with this but in the data.vsphere_resource_pool
, data.vsphere_datacenter
is a class and not an instance of a class. Also, if you want to reference the data source you add first you have to "remember" it in a variable.
I haven't tested this but the code below should get you closer.
# Create the data source
dc = data.vsphere_datacenter('dc',
name = "MainDC",
)
# Add the data source to the config.
config += dc
config += data.vsphere_resource_pool('pool',
name = "VW_CLUSTER/Resources",
# Reference the data source
datacenter_id = dc.id
)
Let me know whether that helped.
Regarding your issue; I am quite out of practice with this but in the
data.vsphere_resource_pool
,data.vsphere_datacenter
is a class and not an instance of a class. Also, if you want to reference the data source you add first you have to "remember" it in a variable.I haven't tested this but the code below should get you closer.
# Create the data source dc = data.vsphere_datacenter('dc', name = "MainDC", ) # Add the data source to the config. config += dc config += data.vsphere_resource_pool('pool', name = "VW_CLUSTER/Resources", # Reference the data source datacenter_id = dc.id )
Let me know whether that helped.
Hi mjuenema, thanks for your help.
I still investigating, trying to compare the json generated by terrascript with my terraform HCL.
I will add the solution when the errors gone..
Thanks!!.