Trying to use an input variable containing self object (like $${var.self....} for a module, setting the provisioner command

Don’t know if this is even possible to do so if anyone knows, that would be much appreciated.

What I want to do is to have an input variable setting the command for a provisioner in a module. So, in the module I have done this:
resource “vsphere_virtual_machine” “vm” {
lifecycle {
ignore_changes = [
create_before_destroy = true
provisioner “local-exec” {
command = var.provisioner
on_failure = continue

And trying to set the provisioner variable like this
provisioner = “echo servers ipaddress is ‘$${self.default_ip_address}’”
or provisioner = “echo servers ipaddress is $${self.default_ip_address}”
This doesn’t work obviously.

If your command to run will include references to dynamic data about the object or any other object in the module then indeed you won’t be able to set it directly to the value of a variable, because a string variable is just data, not code to be executed.

If the user of your module needs to do its own provisioning of a VM declared in your module then a more typical answer would be for your module to export the IP address as an output value and then the calling module can use that IP address to interact with the VM.

I figured that it was something like that. What I wanted to do is using the “create_before_destroy = true” argument and using the provider to deploy an app to the vm, before it is replaced in case of changing to a new image or anything else that will force the redeploy of the vm.

But I guess the alternative you mention might be the way to go.