Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

NIC not connected when cloning VM (via terraform) from template (made by packer) #280

Open
manu89 opened this issue Oct 25, 2019 · 1 comment

Comments

@manu89
Copy link

manu89 commented Oct 25, 2019

Hi,

i have an issue when i try to clone VM (via terraform) from template (made by packer).
Packer create a template with success, now if i clone that template via vsphere web (manual) it works while if i try to use terraform, the process fails on the customization part due to vm NIC not connected.

Here is the packer template conf. details:
ks.cfg
`

cdrom
lang en_US.UTF-8
keyboard us
timezone UTC
network --onboot yes --bootproto=static --ip=X.X.X.X --netmask=255.255.255.0 --gateway=X.X.X.X --nameserver X.X.X.X
rootpw --plaintext packer
user --name=frank --password=Test123
auth --enableshadow --passalgo=sha512 --kickstart
firewall --disabled
selinux --permissive
bootloader --location=mbr
 
text
skipx
zerombr
 
clearpart --all --initlabel
autopart
 
firstboot --disable
reboot
 
%packages --instLangs=en_US.utf8 --nobase --ignoremissing --excludedocs
 
@core
%end
 
 
%post --log=/root/ks.log

#Install vmtools
yum -y install open-vm-tools 
systemctl enable vmtoolsd
systemctl start vmtoolsd

#yum -y update
%end

CentOS7_build.json
`

{
  
  "variables": {
    "VSPHERE_SERVER": "",
    "VSPHERE_USER": "",
    "VSPHERE_PASSWORD": ""
  },
  
  "builders": [
    {
        "type": "vsphere-iso",
        "vcenter_server":      "{{user `VSPHERE_SERVER`}}",
        "username":            "{{user `VSPHERE_USER`}}",
        "password":            "{{user `VSPHERE_PASSWORD`}}",
        "insecure_connection": "true",
        "vm_name": "RHEL-Centos7-Template",
        "notes": "Build via Packer",
        "datacenter": "InfraXXX",
        "cluster": "ClusterXXX",
        "host": "X.X.X.X",
        "datastore": "XXX_Datastore",
        "network": "XXX",
        "folder":"_SIU_Privata_912",
        "guest_os_type": "centos7_64Guest",

        "ssh_username": "root",
        "ssh_password": "packer",

        "CPUs":             2,
        "RAM":              2048,
        "RAM_reserve_all": false,

        "convert_to_template": true,

        "disk_controller_type":  "pvscsi",
        "disk_size":        25000,
        "disk_thin_provisioned": true,

        "network_card": "e1000",

        "iso_paths": [
          "[XXX_Datastore] Centos7-ISO/CentOS-7-x86_64-Minimal-1908.iso"
        ],
        "iso_checksum": "7002b56184180591a8fa08c2fe0c7338",
        "iso_checksum_type": "md5",
        "floppy_files": [
          "{{template_dir}}/ks.cfg"
        ],
        "boot_command": "<tab> text ks=hd:fd0:/ks.cfg<enter><wait>"
      }
    ]
}

Command RUN:
packer build -var VSPHERE_PASSWORD=$VSPHERE_PASSWORD -var VSPHERE_USER=$VSPHERE_USER -var VSPHERE_SERVER=$VSPHERE_SERVER ./CentOS7_build.json

Terraform v0.12.12
Packer v2.3

@LIV2
Copy link

LIV2 commented Oct 30, 2019

If manual cloning works but terraform doesn't then the issue must be with the terraform config
Have you specified a network_interface block in your terraform config? I don't think the terraform provider will connect the vm network unless you configure it to do so i.e

data "vsphere_network" "vlan1" {
    name = "VLAN1"
    datacenter_id = "${data.vsphere_datacenter.id}"
}

data "vsphere_virtual_machine" "my_template" {
  name = "packer-template"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

resource "vsphere_virtual_machine" "vm" {
  name             = "terraform-test"
  resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
  datastore_id     = "${data.vsphere_datastore.my_datastore.id}"

  num_cpus = 2
  memory   = 4096
  guest_id = "centos64Guest"
  scsi_type = "lsilogic"

  network_interface {
    network_id = "${data.vsphere_network.vlan1.id}"
  }

  clone {
    template_uuid = "${data.vsphere_virtual_machine.my_template.id}"
  }

  disk {
    label            = "disk0"
    size             = "${data.vsphere_virtual_machine.my_template.disks.0.size}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.my_template.disks.0.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.my_template.disks.0.thin_provisioned}"
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants