Merge branch 'feature/k8s_extnet' into '2.1'

added extnet_id parameter to k8s; added read-only parameter lb_ip to k8s

See merge request rudecs/terraform-provider-decort!4
2.1
Petr Krutov 3 years ago
commit 77d8d2e921

@ -605,11 +605,27 @@ type K8sRecord struct {
Masters K8sNodeRecord `json:"masters"` Masters K8sNodeRecord `json:"masters"`
Workers []K8sNodeRecord `json:"workers"` Workers []K8sNodeRecord `json:"workers"`
} `json:"k8sGroups"` } `json:"k8sGroups"`
LbID int `json:"lbId"`
Name string `json:"name"` Name string `json:"name"`
RgID int `json:"rgId"` RgID int `json:"rgId"`
RgName string `json:"rgName"` RgName string `json:"rgName"`
} }
//LbRecord represents load balancer instance
type LbRecord struct {
ID int `json:"id"`
Name string `json:"name"`
RgID int `json:"rgId"`
VinsID int `json:"vinsId"`
ExtNetID int `json:"extnetId"`
PrimaryNode struct {
BackendIP string `json:"backendIp"`
ComputeID int `json:"computeId"`
FrontendIP string `json:"frontendIp"`
NetworkID int `json:"networkId"`
} `json:"primaryNode"`
}
const K8sCreateAPI = "/restmachine/cloudapi/k8s/create" const K8sCreateAPI = "/restmachine/cloudapi/k8s/create"
const K8sGetAPI = "/restmachine/cloudapi/k8s/get" const K8sGetAPI = "/restmachine/cloudapi/k8s/get"
const K8sUpdateAPI = "/restmachine/cloudapi/k8s/update" const K8sUpdateAPI = "/restmachine/cloudapi/k8s/update"
@ -623,6 +639,8 @@ const K8sWorkerDeleteAPI = "/restmachine/cloudapi/k8s/deleteWorkerFromGroup"
const K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig" const K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig"
const LbGetAPI = "/restmachine/cloudapi/lb/get"
//Blasphemous workaround for parsing Result value //Blasphemous workaround for parsing Result value
type TaskResult int type TaskResult int

@ -73,10 +73,11 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
//} //}
urlValues.Add("withLB", strconv.FormatBool(true)) urlValues.Add("withLB", strconv.FormatBool(true))
//if extNet, ok := d.GetOk("extnet_id"); ok { if extNet, ok := d.GetOk("extnet_id"); ok {
//urlValues.Add("extnetId", strconv.Itoa(extNet.(int))) urlValues.Add("extnetId", strconv.Itoa(extNet.(int)))
//} } else {
urlValues.Add("extnetId", strconv.Itoa(0)) urlValues.Add("extnetId", "0")
}
//if desc, ok := d.GetOk("desc"); ok { //if desc, ok := d.GetOk("desc"); ok {
//urlValues.Add("desc", desc.(string)) //urlValues.Add("desc", desc.(string))
@ -121,6 +122,21 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
d.Set("default_wg_id", k8s.Groups.Workers[0].ID) d.Set("default_wg_id", k8s.Groups.Workers[0].ID)
urlValues = &url.Values{}
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
resp, err = controller.decortAPICall("POST", LbGetAPI, urlValues)
if err != nil {
return err
}
var lb LbRecord
if err := json.Unmarshal([]byte(resp), &lb); err != nil {
return err
}
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
urlValues = &url.Values{} urlValues = &url.Values{}
urlValues.Add("k8sId", d.Id()) urlValues.Add("k8sId", d.Id())
kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues) kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues)
@ -151,6 +167,21 @@ func resourceK8sRead(d *schema.ResourceData, m interface{}) error {
controller := m.(*ControllerCfg) controller := m.(*ControllerCfg)
urlValues := &url.Values{} urlValues := &url.Values{}
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
resp, err := controller.decortAPICall("POST", LbGetAPI, urlValues)
if err != nil {
return err
}
var lb LbRecord
if err := json.Unmarshal([]byte(resp), &lb); err != nil {
return err
}
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
urlValues = &url.Values{}
urlValues.Add("k8sId", d.Id()) urlValues.Add("k8sId", d.Id())
kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues) kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues)
if err != nil { if err != nil {
@ -303,13 +334,13 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
//Description: "Create k8s with load balancer if true.", //Description: "Create k8s with load balancer if true.",
//}, //},
//"extnet_id": { "extnet_id": {
//Type: schema.TypeInt, Type: schema.TypeInt,
//Optional: true, Optional: true,
//ForceNew: true, Computed: true,
//Default: 0, ForceNew: true,
//Description: "ID of the external network to connect workers to.", Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
//}, },
//"desc": { //"desc": {
//Type: schema.TypeString, //Type: schema.TypeString,
@ -317,6 +348,12 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
//Description: "Text description of this instance.", //Description: "Text description of this instance.",
//}, //},
"lb_ip": {
Type: schema.TypeString,
Computed: true,
Description: "IP address of default load balancer.",
},
"default_wg_id": { "default_wg_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,

@ -24,6 +24,7 @@ description: |-
### Optional ### Optional
- **extnet_id** (Number) ID of the external network to connect workers to. If omitted network will be chosen by the platfom.
- **id** (String) The ID of this resource. - **id** (String) The ID of this resource.
- **masters** (Block List, Max: 1) Master node(s) configuration. (see [below for nested schema](#nestedblock--masters)) - **masters** (Block List, Max: 1) Master node(s) configuration. (see [below for nested schema](#nestedblock--masters))
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) - **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
@ -33,6 +34,7 @@ description: |-
- **default_wg_id** (Number) ID of default workers group for this instace. - **default_wg_id** (Number) ID of default workers group for this instace.
- **kubeconfig** (String) Kubeconfig for cluster access. - **kubeconfig** (String) Kubeconfig for cluster access.
- **lb_ip** (String) IP address of default load balancer.
<a id="nestedblock--masters"></a> <a id="nestedblock--masters"></a>
### Nested Schema for `masters` ### Nested Schema for `masters`

Loading…
Cancel
Save