Packer 1.6 converting vsphere-iso JSON config to HCL2

With the release of Packer 1.6 came several depreciated fields in the vsphere-iso builder. From the looks of it, seems to be a format/type change because the fields actually still exists but just as properties it seems. An example of the changes are the following:

Working in Packer 1.5.6:

JSON

"disk_size": 123456,
"disk_thin_provisioned": true
"network": "VM Network",
"network_card": "vmxnet3"

Working in Packer 1.6.0:

JSON

"storage": [
    {
        "disk_size": 123456,
        "disk_thin_provisioned": true
    }
],
"network_adapters": [
    {
        "network": "VM Network",
        "network_card": "vmxnet3"
    }
]

The issue I have at the moment is I’m using Packer 1.6.0 and am trying to convert the above working JSON code to HCL2. I can’t figure out the HCL2 syntax that supports the changes that were made in Packer 1.6.0.

I’ve tried the following:

network_adapter = {
    network_card = "vmxnet3"
    network = "VM Network"
}

Output:

An argument named “network_adapter” is not expected here.

network_adapter = (
    network_card = "vmxnet3"
    network = "VM Network"
)

Output:

Error: Unbalanced parentheses

on .\Packer\ConfigFileName.pkr.hcl line 19, in source “vsphere-iso”
“Test”: 18: storage = ( 19: disk_thin_provisioned = true

Expected a closing parenthesis to terminate the expression.

    network_adapter = [
        network_card = "vmxnet3",
        network = "VM Network"
    ]

Output:

Error: Missing item separator

on .\Packer\ConfigFileName.pkr.hcl line 19, in source “vsphere-iso”
“Test”: 18: storage = [ 19: disk_thin_provisioned =
true,

Expected a comma to mark the beginning of the next item.

I’ve also tried several other permutations of different collection syntax together with no luck so far. Any suggestions or tips would greatly be appreciated

I also posted this question on StackOverflow. If you have any advice, feel free to answer the question their aswell to earn yourself some SO rep.

You’re so close – you want it pluralized, with curly braces:

network_adapters {
        network_card = "vmxnet3"
        network = "VM Network"
}

We’re working on updating the docs to have hcl examples for these sub-blocks, but it’s a long process; thanks for your patience while we update them.

1 Like

Thank you @SawmpDragons! The missing “s” was a typo when commenting here on the forums and StackOverflow but wasn’t represented that way in my actual code. This big misunderstanding for me here was the fact you’re not using the assignment operator =. When removing it and added the curly braces back, that fixed everything!

Awesome – if you have any more HCL issues, please reach out!