Ejemplo n.º 1
0
func resourceVIXVMCreate(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)

	vm := new(vix.VM)
	vm.Provider = config.Product
	vm.VerifySSL = config.VerifySSL

	if err := tf_to_vix(d, vm); err != nil {
		return err
	}

	id, err := vm.Create()
	if err != nil {
		return err
	}

	log.Printf("[DEBUG] Resource ID: %s\n", id)
	d.SetId(id)

	// Initialize the connection info
	d.SetConnInfo(map[string]string{
		"type": "ssh",
		"host": vm.IPAddress,
	})

	return resourceVIXVMRead(d, meta)
}
Ejemplo n.º 2
0
func resourceVIXVMDelete(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)
	vmxFile := d.Id()

	vm := new(vix.VM)
	vm.Provider = config.Product
	vm.VerifySSL = config.VerifySSL

	if password := d.Get("password"); password != nil {
		vm.Image.Password = d.Get("password").(string)
	}

	return vm.Destroy(vmxFile)
}
Ejemplo n.º 3
0
func resourceVIXVMUpdate(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)

	vm := new(vix.VM)
	vm.Provider = config.Product
	vm.VerifySSL = config.VerifySSL

	// Maps terraform.ResourceState attrbutes to vix.VM
	tf_to_vix(d, vm)

	err := vm.Update(d.Id())
	if err != nil {
		return err
	}

	return resourceVIXVMRead(d, meta)
}
Ejemplo n.º 4
0
func resourceVIXVMRead(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)

	vmxFile := d.Id()

	vm := new(vix.VM)
	vm.Provider = config.Product
	vm.VerifySSL = config.VerifySSL

	running, err := vm.Refresh(vmxFile)
	if err != nil {
		return err
	}

	// This is to let TF know the resource is gone
	if !running {
		return nil
	}

	// Refreshes only what makes sense, for example, we do not refresh settings
	// that modify the behavior of this provider
	d.Set("name", vm.Name)
	d.Set("description", vm.Description)
	d.Set("cpus", vm.CPUs)
	d.Set("memory", vm.Memory)
	d.Set("ip_address", vm.IPAddress)

	err = net_vix_to_tf(vm, d)
	if err != nil {
		return err
	}

	err = cdrom_vix_to_tf(vm, d)
	if err != nil {
		return err
	}

	return nil
}