jetbrains-infra/packer-builder-vsphere

Some fields do not allow use of environment variables

lbonilla68 opened this issue · 2 comments

I'm trying to use variables throughout my Packer config when using vsphere-iso and there are 3 fields so far that I can't use environment variables with. Those are vcenter_server, vm_name and vm_cluster. The rest of the fields allow the usage of env variables just fine. When I try to run it I get the errors below:

3 error(s) occurred:

  • vcenter_server is required
  • vm_name is required
  • host or cluster is required

**Packer Code below **

{
"variables": {
"ansible_dir": "{{ env ANSIBLE_DIR }}",
"datacenter": "{{ env DATACENTER }}",
"disk_cntlr_type": "lsilogic-sas",
"iso_path": "{{ env ISO_PATH }}",
"packer_log_path": "/tmp/packer.log",
"target_playbook": "Ansible_playbook.yml",
"vcenter_server": "{{ env VCENTER_SERVER }}",
"vcenter_user": "{{ env VCENTER_USER }}",
"vcenter_pwd": "{{ env VCENTER_PWD }}",
"vm_name": "{{ env VM_NAME }}",
"vm_folder": "{{ env VM_FOLDER }}",
"vm_cluster": "{{ env VM_CLUSTER }}",
"vm_datacenter": "{{ env VM_DATACENTER }}",
"vm_datastore": "{{ env VM_DATASTORE }}",
"vm_network": "{{ env VM_NETWORK }}",
"vm_network_card_type": "vmxnet3",
"vm_guest_os": "windows8Server64Guest",
"vmtools_iso_path": "{{ env VMTOOLS_ISO_PATH }}",
"winrm_user": "administrator",
"winrm_passwd": "{{ env `WINRM_PWD` }}"
},
"builders": [
{
"type": "vsphere-iso",

  "vcenter_server":      "{{ user `vcenter_server` }}",
  "username":            "{{ user `vcenter_user` }}",
  "password":            "{{ user `vcenter_pwd` }}",
  "insecure_connection": "true",

  "vm_name":   "{{ user `vm_name` }}",
  "folder":   "{{ user `vm_folder` }}",
  "cluster":  "{{ user `vm_cluster` }}",

  "datacenter": "{{ user `vm_datacenter` }}",
  "datastore": "{{ user `vm_datastore` }}",
  "notes":    "Built By Packer",
  
  "CPUs": 2,
  "cpu_cores": 2,
  "RAM": 8192,
  "disk_size": 102400,
  "disk_thin_provisioned": true,
  "network_card": "{{ user `vm_network_card_type` }}",
  "network": "{{ user `vm_network` }}",
  "guest_os_type": "{{ user `vm_guest_os` }}",
  "disk_controller_type": "{{ user `disk_cntlr_type` }}",

  "iso_paths": [
    "[{{ user `vm_datastore` }}] {{ user `iso_path` }}",
    "[{{ user `vm_datastore` }}] {{ user `vmtools_iso_path` }}"
  ],

  "floppy_files": [
    "{{template_dir}}/files/win_setup/2016core/"
  ],

  "communicator": "winrm",
  "winrm_username": "{{ user `winrm_user` }}",
  "winrm_password": "{{ user `winrm_passwd` }}",
  "shutdown_timeout": "15m",

  "convert_to_template":  true
}

]

Change values in builder section as fallowing:
"vcenter_server": "{{ user vsphere_server }}",
"vm_name": "{{ user template_name }}",

On your variables section make fallowing changes as well:
"vcenter_server": "{{ env vsphere_server }}",
"vm_name": "{{ env template_name }}",

Check the results.

I had done that but I must have entered something wrong because now it's working for me. Thank you!