Data as variable inserted in module (cloudinit and vsphere_virtual_machine)

Using cloudinit_config data as variable for virtual machine module.

Hello,

I’m trying to create a module that mainly contains a vsphere_virtual_machine resource inside which I’m defining the following vapp parameters:

  vapp {
    properties = {
      user-data = base64encode(data.template_cloudinit_config.prometheus.rendered)
      "hostname" = var.hostname
    }
  }

The cloudinit data is normally (without modules) defined in the same terraform state as the virtual machine, but if I want to create the module, things get a little complicated and I’m not sure if I can insert the whole thing as such, something to the effect of:
(inside the module definition):

  vapp {
    properties = {
      user-data = base64encode(var.cloudinit_config)
      "hostname" = var.hostname
    }
  }

(when calling the module):

module "virtual_machine" {
        source = "../modules/virtual_machine"
        cloudinit_config = data.template_cloudinit_config.prometheus.rendered
        [...]
}

Would that make sense? How would you normally go about solving this problem?

I’m not seeing any problem here? Just a straightforward normal use of a module input variable?

1 Like

Yeah, I think I’m overthinking it a little bit, because I thought about how complicated the cloudinit config is, but it just generates a string after all, which needs to be base64 encoded, so yes, I’ll try it out, I haven’t yet been able to yet, because I’m trying to think about integrating all the variables, but I’ll let you know.

Thanks :slight_smile:

It did work as expected, indeed. Thanks for the answer.