Implement Import function for Compute resource
This commit is contained in:
@@ -112,8 +112,8 @@ func parseComputeDisks(disks []DiskRecord) []interface{} {
|
|||||||
elem["sep_id"] = value.SepID
|
elem["sep_id"] = value.SepID
|
||||||
elem["sep_type"] = value.SepType
|
elem["sep_type"] = value.SepType
|
||||||
elem["pool"] = value.Pool
|
elem["pool"] = value.Pool
|
||||||
elem["status"] = value.Status
|
// elem["status"] = value.Status
|
||||||
elem["tech_status"] = value.TechStatus
|
// elem["tech_status"] = value.TechStatus
|
||||||
elem["compute_id"] = value.ComputeID
|
elem["compute_id"] = value.ComputeID
|
||||||
result[i] = elem
|
result[i] = elem
|
||||||
}
|
}
|
||||||
@@ -417,6 +417,7 @@ func dataSourceCompute() *schema.Resource {
|
|||||||
Description: "User-defined text description of this compute instance.",
|
Description: "User-defined text description of this compute instance.",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
"status": {
|
"status": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@@ -429,12 +430,11 @@ func dataSourceCompute() *schema.Resource {
|
|||||||
Description: "Current technical status of this compute instance.",
|
Description: "Current technical status of this compute instance.",
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
"internal_ip": {
|
||||||
"internal_ip": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
Description: "Internal IP address of this Compute.",
|
||||||
Description: "Internal IP address of this Compute.",
|
},
|
||||||
},
|
|
||||||
*/
|
*/
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,6 +230,10 @@ func resourceCompute() *schema.Resource {
|
|||||||
Delete: resourceComputeDelete,
|
Delete: resourceComputeDelete,
|
||||||
Exists: resourceComputeExists,
|
Exists: resourceComputeExists,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Timeouts: &schema.ResourceTimeout{
|
Timeouts: &schema.ResourceTimeout{
|
||||||
Create: &Timeout180s,
|
Create: &Timeout180s,
|
||||||
Read: &Timeout30s,
|
Read: &Timeout30s,
|
||||||
@@ -369,7 +373,6 @@ func resourceCompute() *schema.Resource {
|
|||||||
},
|
},
|
||||||
Description: "Specification for guest logins on this compute instance.",
|
Description: "Specification for guest logins on this compute instance.",
|
||||||
},
|
},
|
||||||
*/
|
|
||||||
|
|
||||||
"status": {
|
"status": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@@ -382,6 +385,7 @@ func resourceCompute() *schema.Resource {
|
|||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "Current technical status of this compute instance.",
|
Description: "Current technical status of this compute instance.",
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@@ -197,11 +198,24 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
|
|||||||
controller := m.(*ControllerCfg)
|
controller := m.(*ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
computeId, argSet := d.GetOk("compute_id") // NB: compute_id is NOT present in computeResource schema!
|
// make it possible to use "read" & "check presence" functions with comptue ID set so
|
||||||
if argSet {
|
// that Import of Compute resource is possible
|
||||||
|
idSet := false
|
||||||
|
theId, err := strconv.Atoi(d.Id())
|
||||||
|
if err != nil || theId <= 0 {
|
||||||
|
computeId, argSet := d.GetOk("compute_id") // NB: compute_id is NOT present in computeResource schema!
|
||||||
|
if argSet {
|
||||||
|
theId = computeId.(int)
|
||||||
|
idSet = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
idSet = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if idSet {
|
||||||
// compute ID is specified, try to get compute instance straight by this ID
|
// compute ID is specified, try to get compute instance straight by this ID
|
||||||
log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", computeId.(int))
|
log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", theId)
|
||||||
urlValues.Add("computeId", fmt.Sprintf("%d", computeId.(int)))
|
urlValues.Add("computeId", fmt.Sprintf("%d", theId))
|
||||||
computeFacts, err := controller.decortAPICall("POST", ComputeGetAPI, urlValues)
|
computeFacts, err := controller.decortAPICall("POST", ComputeGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -209,6 +223,8 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
|
|||||||
return computeFacts, nil
|
return computeFacts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ID was not set in the schema upon entering this function - work through Compute name
|
||||||
|
// and RG ID
|
||||||
computeName, argSet := d.GetOk("name")
|
computeName, argSet := d.GetOk("name")
|
||||||
if !argSet {
|
if !argSet {
|
||||||
return "", fmt.Errorf("Cannot locate compute instance if name is empty and no compute ID specified")
|
return "", fmt.Errorf("Cannot locate compute instance if name is empty and no compute ID specified")
|
||||||
@@ -251,5 +267,4 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return "", nil // there should be no error if Compute does not exist
|
return "", nil // there should be no error if Compute does not exist
|
||||||
// return "", fmt.Errorf("Cannot find Compute name %q in resource group ID %d", name, rgid)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user