Skip to content

Commit

Permalink
Better import method and error message
Browse files Browse the repository at this point in the history
  • Loading branch information
bkmeneguello committed May 23, 2019
1 parent 24a4408 commit a6163ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 3 additions & 3 deletions proxmox/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func resourceId(targetNode string, resType string, vmId int) string {
var rxRsId = regexp.MustCompile("([^/]+)/([^/]+)/(\\d+)")

func parseResourceId(resId string) (targetNode string, resType string, vmId int, err error) {
idMatch := rxRsId.FindStringSubmatch(resId)
if idMatch == nil {
err = fmt.Errorf("Invalid resource id: %s", resId)
if !rxRsId.MatchString(resId) {
return "", "", -1, fmt.Errorf("Invalid resource format: %s. Must be node/type/vmId", resId)
}
idMatch := rxRsId.FindStringSubmatch(resId)
targetNode = idMatch[1]
resType = idMatch[2]
vmId, err = strconv.Atoi(idMatch[3])
Expand Down
9 changes: 2 additions & 7 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func resourceVmQemu() *schema.Resource {
Update: resourceVmQemuUpdate,
Delete: resourceVmQemuDelete,
Importer: &schema.ResourceImporter{
State: resourceVmQemuImport,
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -577,6 +577,7 @@ func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
_, _, vmID, err := parseResourceId(d.Id())
if err != nil {
pmParallelEnd(pconf)
d.SetId("")
return err
}
vmr := pxapi.NewVmRef(vmID)
Expand Down Expand Up @@ -630,12 +631,6 @@ func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

func resourceVmQemuImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
// TODO: research proper import
err := resourceVmQemuRead(d, meta)
return []*schema.ResourceData{d}, err
}

func resourceVmQemuDelete(d *schema.ResourceData, meta interface{}) error {
pconf := meta.(*providerConfiguration)
pmParallelBegin(pconf)
Expand Down

0 comments on commit a6163ce

Please sign in to comment.