You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
822 B
45 lines
822 B
package decort
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
|
)
|
|
|
|
func utilityPfwCheckPresence(d *schema.ResourceData, m interface{}) (*PfwRecord, error) {
|
|
controller := m.(*ControllerCfg)
|
|
urlValues := &url.Values{}
|
|
|
|
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
|
resp, err := controller.decortAPICall("POST", ComputePfwListAPI, urlValues)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if resp == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
idS := strings.Split(d.Id(), "-")[1]
|
|
id, err := strconv.Atoi(idS)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var pfws []PfwRecord
|
|
if err := json.Unmarshal([]byte(resp), &pfws); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, pfw := range pfws {
|
|
if pfw.ID == id {
|
|
return &pfw, nil
|
|
}
|
|
}
|
|
|
|
return nil, nil
|
|
}
|