mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-07-03 08:02:39 +00:00
Merge pull request #53 from bkmeneguello/importer
Better import method and error message
This commit is contained in:
commit
18c35324b0
|
@ -130,10 +130,10 @@ func resourceId(targetNode string, resType string, vmId int) string {
|
||||||
var rxRsId = regexp.MustCompile("([^/]+)/([^/]+)/(\\d+)")
|
var rxRsId = regexp.MustCompile("([^/]+)/([^/]+)/(\\d+)")
|
||||||
|
|
||||||
func parseResourceId(resId string) (targetNode string, resType string, vmId int, err error) {
|
func parseResourceId(resId string) (targetNode string, resType string, vmId int, err error) {
|
||||||
idMatch := rxRsId.FindStringSubmatch(resId)
|
if !rxRsId.MatchString(resId) {
|
||||||
if idMatch == nil {
|
return "", "", -1, fmt.Errorf("Invalid resource format: %s. Must be node/type/vmId", resId)
|
||||||
err = fmt.Errorf("Invalid resource id: %s", resId)
|
|
||||||
}
|
}
|
||||||
|
idMatch := rxRsId.FindStringSubmatch(resId)
|
||||||
targetNode = idMatch[1]
|
targetNode = idMatch[1]
|
||||||
resType = idMatch[2]
|
resType = idMatch[2]
|
||||||
vmId, err = strconv.Atoi(idMatch[3])
|
vmId, err = strconv.Atoi(idMatch[3])
|
||||||
|
|
|
@ -22,7 +22,7 @@ func resourceVmQemu() *schema.Resource {
|
||||||
Update: resourceVmQemuUpdate,
|
Update: resourceVmQemuUpdate,
|
||||||
Delete: resourceVmQemuDelete,
|
Delete: resourceVmQemuDelete,
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: resourceVmQemuImport,
|
State: schema.ImportStatePassthrough,
|
||||||
},
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
@ -577,6 +577,7 @@ func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
_, _, vmID, err := parseResourceId(d.Id())
|
_, _, vmID, err := parseResourceId(d.Id())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pmParallelEnd(pconf)
|
pmParallelEnd(pconf)
|
||||||
|
d.SetId("")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
vmr := pxapi.NewVmRef(vmID)
|
vmr := pxapi.NewVmRef(vmID)
|
||||||
|
@ -630,12 +631,6 @@ func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
return nil
|
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 {
|
func resourceVmQemuDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
pconf := meta.(*providerConfiguration)
|
pconf := meta.(*providerConfiguration)
|
||||||
pmParallelBegin(pconf)
|
pmParallelBegin(pconf)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user