v3.2.2
This commit is contained in:
@@ -31,19 +31,23 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
|
||||
package k8s
|
||||
|
||||
const K8sCreateAPI = "/restmachine/cloudapi/k8s/create"
|
||||
const K8sGetAPI = "/restmachine/cloudapi/k8s/get"
|
||||
const K8sUpdateAPI = "/restmachine/cloudapi/k8s/update"
|
||||
const K8sDeleteAPI = "/restmachine/cloudapi/k8s/delete"
|
||||
const (
|
||||
K8sCreateAPI = "/restmachine/cloudapi/k8s/create"
|
||||
K8sGetAPI = "/restmachine/cloudapi/k8s/get"
|
||||
K8sUpdateAPI = "/restmachine/cloudapi/k8s/update"
|
||||
K8sDeleteAPI = "/restmachine/cloudapi/k8s/delete"
|
||||
K8sListAPI = "/restmachine/cloudapi/k8s/list"
|
||||
K8sListDeletedAPI = "/restmachine/cloudapi/k8s/listDeleted"
|
||||
|
||||
const K8sWgCreateAPI = "/restmachine/cloudapi/k8s/workersGroupAdd"
|
||||
const K8sWgDeleteAPI = "/restmachine/cloudapi/k8s/workersGroupDelete"
|
||||
K8sWgCreateAPI = "/restmachine/cloudapi/k8s/workersGroupAdd"
|
||||
K8sWgDeleteAPI = "/restmachine/cloudapi/k8s/workersGroupDelete"
|
||||
|
||||
const K8sWorkerAddAPI = "/restmachine/cloudapi/k8s/workerAdd"
|
||||
const K8sWorkerDeleteAPI = "/restmachine/cloudapi/k8s/deleteWorkerFromGroup"
|
||||
K8sWorkerAddAPI = "/restmachine/cloudapi/k8s/workerAdd"
|
||||
K8sWorkerDeleteAPI = "/restmachine/cloudapi/k8s/deleteWorkerFromGroup"
|
||||
|
||||
const K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig"
|
||||
K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig"
|
||||
|
||||
const LbGetAPI = "/restmachine/cloudapi/lb/get"
|
||||
LbGetAPI = "/restmachine/cloudapi/lb/get"
|
||||
|
||||
const AsyncTaskGetAPI = "/restmachine/cloudapi/tasks/get"
|
||||
AsyncTaskGetAPI = "/restmachine/cloudapi/tasks/get"
|
||||
)
|
||||
|
||||
419
internal/service/cloudapi/k8s/data_source_k8s.go
Normal file
419
internal/service/cloudapi/k8s/data_source_k8s.go
Normal file
@@ -0,0 +1,419 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/kvmvm"
|
||||
)
|
||||
|
||||
func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
k8s, err := utilityDataK8sCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId(strconv.FormatUint(k8s.ID, 10))
|
||||
|
||||
k8sList, err := utilityK8sListCheckPresence(ctx, d, m, K8sListAPI)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
curK8s := K8SItem{}
|
||||
for _, k8sCluster := range k8sList {
|
||||
if k8sCluster.ID == k8s.ID {
|
||||
curK8s = k8sCluster
|
||||
}
|
||||
}
|
||||
if curK8s.ID == 0 {
|
||||
return diag.Errorf("Cluster with id %d not found in List clusters", k8s.ID)
|
||||
}
|
||||
d.Set("vins_id", curK8s.VINSID)
|
||||
|
||||
masterComputeList := make([]kvmvm.ComputeGetResp, 0, len(k8s.K8SGroups.Masters.DetailedInfo))
|
||||
workersComputeList := make([]kvmvm.ComputeGetResp, 0, len(k8s.K8SGroups.Workers))
|
||||
for _, masterNode := range k8s.K8SGroups.Masters.DetailedInfo {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m, masterNode.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
masterComputeList = append(masterComputeList, *compute)
|
||||
}
|
||||
for _, worker := range k8s.K8SGroups.Workers {
|
||||
for _, info := range worker.DetailedInfo {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
workersComputeList = append(workersComputeList, *compute)
|
||||
}
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
kubeconfig, err := c.DecortAPICall(ctx, "POST", K8sGetConfigAPI, urlValues)
|
||||
if err != nil {
|
||||
log.Warnf("could not get kubeconfig: %v", err)
|
||||
}
|
||||
d.Set("kubeconfig", kubeconfig)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("lbId", strconv.FormatUint(k8s.LBID, 10))
|
||||
resp, err := c.DecortAPICall(ctx, "POST", LbGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
var lb LbRecord
|
||||
if err := json.Unmarshal([]byte(resp), &lb); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.Set("extnet_id", lb.ExtNetID)
|
||||
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
|
||||
|
||||
flattenK8sData(d, *k8s, masterComputeList, workersComputeList)
|
||||
return nil
|
||||
}
|
||||
|
||||
func aclListSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"explicit": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"right": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"user_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func aclGroupSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"account_acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: aclListSchemaMake(),
|
||||
},
|
||||
},
|
||||
"k8s_acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: aclListSchemaMake(),
|
||||
},
|
||||
},
|
||||
"rg_acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: aclListSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func detailedInfoSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"interfaces": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: interfacesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"natable_vins_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"natable_vins_network": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func interfacesSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"def_gw": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_address": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func masterGroupSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"cpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"detailed_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: detailedInfoSchemaMake(),
|
||||
},
|
||||
},
|
||||
"disk": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"master_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"num": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func k8sGroupListSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"annotations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"cpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"detailed_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: detailedInfoSchemaMake(),
|
||||
},
|
||||
},
|
||||
"disk": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"labels": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"num": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"taints": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"k8s_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: aclGroupSchemaMake(),
|
||||
},
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"bservice_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"k8sci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
|
||||
},
|
||||
"k8s_ci_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"masters": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: masterGroupSchemaMake(),
|
||||
},
|
||||
},
|
||||
"workers": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: k8sGroupListSchemaMake(),
|
||||
},
|
||||
},
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"lb_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "IP address of default load balancer.",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"kubeconfig": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Kubeconfig for cluster access.",
|
||||
},
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceK8s() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceK8sRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceK8sSchemaMake(),
|
||||
}
|
||||
}
|
||||
268
internal/service/cloudapi/k8s/data_source_k8s_list.go
Normal file
268
internal/service/cloudapi/k8s/data_source_k8s_list.go
Normal file
@@ -0,0 +1,268 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceK8sListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
k8sList, err := utilityK8sListCheckPresence(ctx, d, m, K8sListAPI)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
flattenK8sList(d, k8sList)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func serviceAccountSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"username": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func k8sWorkersGroupsSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"annotations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"cpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"detailed_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: detailedInfoSchemaMake(),
|
||||
},
|
||||
},
|
||||
"disk": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"detailed_info_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"labels": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"num": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"taints": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func createK8sListSchema() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"includedeleted": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"bservice_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"config": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"k8s_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"k8s_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"service_account": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: serviceAccountSchemaMake(),
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"workers_groups": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: k8sWorkersGroupsSchemaMake(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceK8sListSchemaMake() map[string]*schema.Schema {
|
||||
k8sListSchema := createK8sListSchema()
|
||||
return k8sListSchema
|
||||
}
|
||||
|
||||
func DataSourceK8sList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceK8sListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceK8sListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceK8sListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
k8sList, err := utilityK8sListCheckPresence(ctx, d, m, K8sListDeletedAPI)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
flattenK8sList(d, k8sList)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceK8sListDeletedSchemaMake() map[string]*schema.Schema {
|
||||
k8sListDeleted := createK8sListSchema()
|
||||
delete(k8sListDeleted, "includedeleted")
|
||||
return k8sListDeleted
|
||||
}
|
||||
|
||||
func DataSourceK8sListDeleted() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceK8sListDeletedRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceK8sListDeletedSchemaMake(),
|
||||
}
|
||||
}
|
||||
129
internal/service/cloudapi/k8s/data_source_k8s_wg_list.go
Normal file
129
internal/service/cloudapi/k8s/data_source_k8s_wg_list.go
Normal file
@@ -0,0 +1,129 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/kvmvm"
|
||||
)
|
||||
|
||||
func flattenWgList(wgList K8SGroupList, computesMap map[uint64][]kvmvm.ComputeGetResp) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, wg := range wgList {
|
||||
computes := computesMap[wg.ID]
|
||||
temp := map[string]interface{}{
|
||||
"annotations": wg.Annotations,
|
||||
"cpu": wg.CPU,
|
||||
"wg_id": wg.ID,
|
||||
"detailed_info": flattenDetailedInfo(wg.DetailedInfo, computes),
|
||||
"disk": wg.Disk,
|
||||
"guid": wg.GUID,
|
||||
"labels": wg.Labels,
|
||||
"name": wg.Name,
|
||||
"num": wg.Num,
|
||||
"ram": wg.RAM,
|
||||
"taints": wg.Taints,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenItemsWg(d *schema.ResourceData, wgList K8SGroupList, computes map[uint64][]kvmvm.ComputeGetResp) {
|
||||
d.Set("items", flattenWgList(wgList, computes))
|
||||
}
|
||||
|
||||
func utilityK8sWgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (K8SGroupList, error) {
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||
|
||||
resp, err := c.DecortAPICall(ctx, "POST", K8sGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var k8s K8SRecord
|
||||
if err := json.Unmarshal([]byte(resp), &k8s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8s.K8SGroups.Workers, nil
|
||||
}
|
||||
|
||||
func dataSourceK8sWgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
wgList, err := utilityK8sWgListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(d.Get("k8s_id").(int)))
|
||||
|
||||
workersComputeList := make(map[uint64][]kvmvm.ComputeGetResp)
|
||||
for _, worker := range wgList {
|
||||
workersComputeList[worker.ID] = make([]kvmvm.ComputeGetResp, 0, len(worker.DetailedInfo))
|
||||
for _, info := range worker.DetailedInfo {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
workersComputeList[worker.ID] = append(workersComputeList[worker.ID], *compute)
|
||||
}
|
||||
}
|
||||
flattenItemsWg(d, wgList, workersComputeList)
|
||||
return nil
|
||||
}
|
||||
|
||||
func wgSchemaMake() map[string]*schema.Schema {
|
||||
wgSchema := dataSourceK8sWgSchemaMake()
|
||||
delete(wgSchema, "k8s_id")
|
||||
wgSchema["wg_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of k8s worker Group.",
|
||||
}
|
||||
return wgSchema
|
||||
}
|
||||
|
||||
func dataSourceK8sWgListSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"k8s_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: wgSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceK8sWgList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceK8sWgListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceK8sWgListSchemaMake(),
|
||||
}
|
||||
}
|
||||
161
internal/service/cloudapi/k8s/data_source_wg.go
Normal file
161
internal/service/cloudapi/k8s/data_source_wg.go
Normal file
@@ -0,0 +1,161 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/kvmvm"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func flattenWgData(d *schema.ResourceData, wg K8SGroup, computes []kvmvm.ComputeGetResp) {
|
||||
d.Set("annotations", wg.Annotations)
|
||||
d.Set("cpu", wg.CPU)
|
||||
d.Set("detailed_info", flattenDetailedInfo(wg.DetailedInfo, computes))
|
||||
d.Set("disk", wg.Disk)
|
||||
d.Set("guid", wg.GUID)
|
||||
d.Set("labels", wg.Labels)
|
||||
d.Set("name", wg.Name)
|
||||
d.Set("num", wg.Num)
|
||||
d.Set("ram", wg.RAM)
|
||||
d.Set("taints", wg.Taints)
|
||||
}
|
||||
|
||||
func dataSourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("dataSourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int))
|
||||
|
||||
k8s, err := utilityDataK8sCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId(strconv.Itoa(d.Get("wg_id").(int)))
|
||||
|
||||
var id int
|
||||
if d.Id() != "" {
|
||||
id, err = strconv.Atoi(d.Id())
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
id = d.Get("wg_id").(int)
|
||||
}
|
||||
|
||||
curWg := K8SGroup{}
|
||||
for _, wg := range k8s.K8SGroups.Workers {
|
||||
if wg.ID == uint64(id) {
|
||||
curWg = wg
|
||||
break
|
||||
}
|
||||
}
|
||||
if curWg.ID == 0 {
|
||||
return diag.Errorf("Not found wg with id: %v in k8s cluster: %v", id, k8s.ID)
|
||||
}
|
||||
|
||||
workersComputeList := make([]kvmvm.ComputeGetResp, 0, 0)
|
||||
for _, info := range curWg.DetailedInfo {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
workersComputeList = append(workersComputeList, *compute)
|
||||
}
|
||||
|
||||
flattenWgData(d, curWg, workersComputeList)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceK8sWgSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"k8s_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of k8s instance.",
|
||||
},
|
||||
"wg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of k8s worker Group.",
|
||||
},
|
||||
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the worker group.",
|
||||
},
|
||||
|
||||
"num": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Number of worker nodes to create.",
|
||||
},
|
||||
|
||||
"cpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Worker node CPU count.",
|
||||
},
|
||||
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Worker node RAM in MB.",
|
||||
},
|
||||
|
||||
"disk": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.",
|
||||
},
|
||||
"detailed_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: detailedInfoSchemaMake(),
|
||||
},
|
||||
},
|
||||
"labels": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"annotations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"taints": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceK8sWg() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceK8sWgRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceK8sWgSchemaMake(),
|
||||
}
|
||||
}
|
||||
247
internal/service/cloudapi/k8s/flattens.go
Normal file
247
internal/service/cloudapi/k8s/flattens.go
Normal file
@@ -0,0 +1,247 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/kvmvm"
|
||||
)
|
||||
|
||||
func flattenAclList(aclList ACLList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, acl := range aclList {
|
||||
temp := map[string]interface{}{
|
||||
"explicit": acl.Explicit,
|
||||
"guid": acl.GUID,
|
||||
"right": acl.Right,
|
||||
"status": acl.Status,
|
||||
"type": acl.Type,
|
||||
"user_group_id": acl.UserGroupID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAcl(acl ACLGroup) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"account_acl": flattenAclList(acl.AccountACL),
|
||||
"k8s_acl": flattenAclList(acl.K8SACL),
|
||||
"rg_acl": flattenAclList(acl.RGACL),
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenInterfaces(interfaces []kvmvm.InterfaceRecord) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, interfaceCompute := range interfaces {
|
||||
temp := map[string]interface{}{
|
||||
"def_gw": interfaceCompute.DefaultGW,
|
||||
"ip_address": interfaceCompute.IPAddress,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDetailedInfo(detailedInfoList DetailedInfoList, computes []kvmvm.ComputeGetResp) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
if computes != nil {
|
||||
for i, detailedInfo := range detailedInfoList {
|
||||
temp := map[string]interface{}{
|
||||
"compute_id": detailedInfo.ID,
|
||||
"name": detailedInfo.Name,
|
||||
"status": detailedInfo.Status,
|
||||
"tech_status": detailedInfo.TechStatus,
|
||||
"interfaces": flattenInterfaces(computes[i].Interfaces),
|
||||
"natable_vins_ip": computes[i].NatableVinsIP,
|
||||
"natable_vins_network": computes[i].NatableVinsNet,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
} else {
|
||||
for _, detailedInfo := range detailedInfoList {
|
||||
temp := map[string]interface{}{
|
||||
"compute_id": detailedInfo.ID,
|
||||
"name": detailedInfo.Name,
|
||||
"status": detailedInfo.Status,
|
||||
"tech_status": detailedInfo.TechStatus,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenMasterGroup(mastersGroup MasterGroup, masters []kvmvm.ComputeGetResp) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": mastersGroup.CPU,
|
||||
"detailed_info": flattenDetailedInfo(mastersGroup.DetailedInfo, masters),
|
||||
"disk": mastersGroup.Disk,
|
||||
"master_id": mastersGroup.ID,
|
||||
"name": mastersGroup.Name,
|
||||
"num": mastersGroup.Num,
|
||||
"ram": mastersGroup.RAM,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenK8sGroup(k8SGroupList K8SGroupList, workers []kvmvm.ComputeGetResp) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, k8sGroup := range k8SGroupList {
|
||||
temp := map[string]interface{}{
|
||||
"annotations": k8sGroup.Annotations,
|
||||
"cpu": k8sGroup.CPU,
|
||||
"detailed_info": flattenDetailedInfo(k8sGroup.DetailedInfo, workers),
|
||||
"disk": k8sGroup.Disk,
|
||||
"guid": k8sGroup.GUID,
|
||||
"id": k8sGroup.ID,
|
||||
"labels": k8sGroup.Labels,
|
||||
"name": k8sGroup.Name,
|
||||
"num": k8sGroup.Num,
|
||||
"ram": k8sGroup.RAM,
|
||||
"taints": k8sGroup.Taints,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenK8sGroups(k8sGroups K8SGroups, masters []kvmvm.ComputeGetResp, workers []kvmvm.ComputeGetResp) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"masters": flattenMasterGroup(k8sGroups.Masters, masters),
|
||||
"workers": flattenK8sGroup(k8sGroups.Workers, workers),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenK8sData(d *schema.ResourceData, k8s K8SRecord, masters []kvmvm.ComputeGetResp, workers []kvmvm.ComputeGetResp) {
|
||||
d.Set("acl", flattenAcl(k8s.ACL))
|
||||
d.Set("account_id", k8s.AccountID)
|
||||
d.Set("account_name", k8s.AccountName)
|
||||
d.Set("bservice_id", k8s.BServiceID)
|
||||
d.Set("k8sci_id", k8s.CIID)
|
||||
d.Set("created_by", k8s.CreatedBy)
|
||||
d.Set("created_time", k8s.CreatedTime)
|
||||
d.Set("deleted_by", k8s.DeletedBy)
|
||||
d.Set("deleted_time", k8s.DeletedTime)
|
||||
d.Set("k8s_ci_name", k8s.K8CIName)
|
||||
d.Set("masters", flattenMasterGroup(k8s.K8SGroups.Masters, masters))
|
||||
d.Set("workers", flattenK8sGroup(k8s.K8SGroups.Workers, workers))
|
||||
d.Set("lb_id", k8s.LBID)
|
||||
d.Set("name", k8s.Name)
|
||||
d.Set("rg_id", k8s.RGID)
|
||||
d.Set("rg_name", k8s.RGName)
|
||||
d.Set("status", k8s.Status)
|
||||
d.Set("tech_status", k8s.TechStatus)
|
||||
d.Set("updated_by", k8s.UpdatedBy)
|
||||
d.Set("updated_time", k8s.UpdatedTime)
|
||||
}
|
||||
|
||||
func flattenServiceAccount(serviceAccount ServiceAccount) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"guid": serviceAccount.GUID,
|
||||
"password": serviceAccount.Password,
|
||||
"username": serviceAccount.Username,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenWorkersGroup(workersGroups K8SGroupList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, worker := range workersGroups {
|
||||
temp := map[string]interface{}{
|
||||
"annotations": worker.Annotations,
|
||||
"cpu": worker.CPU,
|
||||
"detailed_info": flattenDetailedInfo(worker.DetailedInfo, nil),
|
||||
"disk": worker.Disk,
|
||||
"guid": worker.GUID,
|
||||
"detailed_info_id": worker.ID,
|
||||
"labels": worker.Labels,
|
||||
"name": worker.Name,
|
||||
"num": worker.Num,
|
||||
"ram": worker.RAM,
|
||||
"taints": worker.Taints,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenConfig(config interface{}) map[string]interface{} {
|
||||
return config.(map[string]interface{})
|
||||
}
|
||||
|
||||
func flattenK8sItems(k8sItems K8SList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, item := range k8sItems {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": item.AccountID,
|
||||
"account_name": item.Name,
|
||||
"acl": item.ACL,
|
||||
"bservice_id": item.BServiceID,
|
||||
"ci_id": item.CIID,
|
||||
"created_by": item.CreatedBy,
|
||||
"created_time": item.CreatedTime,
|
||||
"deleted_by": item.DeletedBy,
|
||||
"deleted_time": item.DeletedTime,
|
||||
"desc": item.Description,
|
||||
"extnet_id": item.ExtNetID,
|
||||
"gid": item.GID,
|
||||
"guid": item.GUID,
|
||||
"k8s_id": item.ID,
|
||||
"lb_id": item.LBID,
|
||||
"milestones": item.Milestones,
|
||||
"k8s_name": item.Name,
|
||||
"rg_id": item.RGID,
|
||||
"rg_name": item.RGName,
|
||||
"service_account": flattenServiceAccount(item.ServiceAccount),
|
||||
"status": item.Status,
|
||||
"tech_status": item.TechStatus,
|
||||
"updated_by": item.UpdatedBy,
|
||||
"updated_time": item.UpdatedTime,
|
||||
"vins_id": item.VINSID,
|
||||
"workers_groups": flattenWorkersGroup(item.WorkersGroup),
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenK8sList(d *schema.ResourceData, k8sItems K8SList) {
|
||||
d.Set("items", flattenK8sItems(k8sItems))
|
||||
}
|
||||
|
||||
func flattenResourceK8s(d *schema.ResourceData, k8s K8SRecord, masters []kvmvm.ComputeGetResp, workers []kvmvm.ComputeGetResp) {
|
||||
d.Set("acl", flattenAcl(k8s.ACL))
|
||||
d.Set("account_id", k8s.AccountID)
|
||||
d.Set("account_name", k8s.AccountName)
|
||||
d.Set("bservice_id", k8s.BServiceID)
|
||||
d.Set("created_by", k8s.CreatedBy)
|
||||
d.Set("created_time", k8s.CreatedTime)
|
||||
d.Set("deleted_by", k8s.DeletedBy)
|
||||
d.Set("deleted_time", k8s.DeletedTime)
|
||||
d.Set("k8s_ci_name", k8s.K8CIName)
|
||||
d.Set("masters", flattenMasterGroup(k8s.K8SGroups.Masters, masters))
|
||||
d.Set("workers", flattenK8sGroup(k8s.K8SGroups.Workers, workers))
|
||||
d.Set("lb_id", k8s.LBID)
|
||||
d.Set("rg_id", k8s.RGID)
|
||||
d.Set("rg_name", k8s.RGName)
|
||||
d.Set("status", k8s.Status)
|
||||
d.Set("tech_status", k8s.TechStatus)
|
||||
d.Set("updated_by", k8s.UpdatedBy)
|
||||
d.Set("updated_time", k8s.UpdatedTime)
|
||||
d.Set("default_wg_id", k8s.K8SGroups.Workers[0].ID)
|
||||
}
|
||||
@@ -64,8 +64,11 @@ type K8sRecord struct {
|
||||
Name string `json:"name"`
|
||||
RgID int `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
VinsID int `json:"vinsId"`
|
||||
}
|
||||
|
||||
type K8sRecordList []K8sRecord
|
||||
|
||||
//LbRecord represents load balancer instance
|
||||
type LbRecord struct {
|
||||
ID int `json:"id"`
|
||||
@@ -129,3 +132,124 @@ type SshKeyConfig struct {
|
||||
SshKey string
|
||||
UserShell string
|
||||
}
|
||||
|
||||
//FromSDK
|
||||
type K8SGroup struct {
|
||||
Annotations []string `json:"annotations"`
|
||||
CPU uint64 `json:"cpu"`
|
||||
DetailedInfo DetailedInfoList `json:"detailedInfo"`
|
||||
Disk uint64 `json:"disk"`
|
||||
GUID string `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Labels []string `json:"labels"`
|
||||
Name string `json:"name"`
|
||||
Num uint64 `json:"num"`
|
||||
RAM uint64 `json:"ram"`
|
||||
Taints []string `json:"taints"`
|
||||
}
|
||||
|
||||
type K8SGroupList []K8SGroup
|
||||
|
||||
type DetailedInfo struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
}
|
||||
|
||||
type DetailedInfoList []DetailedInfo
|
||||
|
||||
type K8SRecord struct {
|
||||
ACL ACLGroup `json:"ACL"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
BServiceID uint64 `json:"bserviceId"`
|
||||
CIID uint64 `json:"ciId"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ID uint64 `json:"id"`
|
||||
K8CIName string `json:"k8ciName"`
|
||||
K8SGroups K8SGroups `json:"k8sGroups"`
|
||||
LBID uint64 `json:"lbId"`
|
||||
Name string `json:"name"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type K8SRecordList []K8SRecord
|
||||
|
||||
type K8SGroups struct {
|
||||
Masters MasterGroup `json:"masters"`
|
||||
Workers K8SGroupList `json:"workers"`
|
||||
}
|
||||
|
||||
type MasterGroup struct {
|
||||
CPU uint64 `json:"cpu"`
|
||||
DetailedInfo DetailedInfoList `json:"detailedInfo"`
|
||||
Disk uint64 `json:"disk"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Num uint64 `json:"num"`
|
||||
RAM uint64 `json:"ram"`
|
||||
}
|
||||
|
||||
type ACLGroup struct {
|
||||
AccountACL ACLList `json:"accountAcl"`
|
||||
K8SACL ACLList `json:"k8sAcl"`
|
||||
RGACL ACLList `json:"rgAcl"`
|
||||
}
|
||||
|
||||
type ACL struct {
|
||||
Explicit bool `json:"explicit"`
|
||||
GUID string `json:"guid"`
|
||||
Right string `json:"right"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
UserGroupID string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
type ACLList []ACL
|
||||
|
||||
type K8SItem struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
ACL []interface{} `json:"acl"`
|
||||
BServiceID uint64 `json:"bserviceId"`
|
||||
CIID uint64 `json:"ciId"`
|
||||
Config interface{} `json:"config"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
ExtNetID uint64 `json:"extnetId"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
LBID uint64 `json:"lbId"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
ServiceAccount ServiceAccount `json:"serviceAccount"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
VINSID uint64 `json:"vinsId"`
|
||||
WorkersGroup K8SGroupList `json:"workersGroups"`
|
||||
}
|
||||
|
||||
type ServiceAccount struct {
|
||||
GUID string `json:"guid"`
|
||||
Password string `json:"password"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type K8SList []K8SItem
|
||||
|
||||
@@ -103,3 +103,59 @@ func nodeK8sSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func mastersSchemaMake() map[string]*schema.Schema {
|
||||
masters := masterGroupSchemaMake()
|
||||
masters["num"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Number of nodes to create.",
|
||||
}
|
||||
masters["cpu"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Node CPU count.",
|
||||
}
|
||||
masters["ram"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Node RAM in MB.",
|
||||
}
|
||||
masters["disk"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Node boot disk size in GB.",
|
||||
}
|
||||
return masters
|
||||
}
|
||||
|
||||
func workersSchemaMake() map[string]*schema.Schema {
|
||||
workers := k8sGroupListSchemaMake()
|
||||
workers["num"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Number of nodes to create.",
|
||||
}
|
||||
workers["cpu"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Node CPU count.",
|
||||
}
|
||||
workers["ram"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Node RAM in MB.",
|
||||
}
|
||||
workers["disk"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Node boot disk size in GB.",
|
||||
}
|
||||
return workers
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/kvmvm"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -79,10 +80,11 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
urlValues.Add("workerRam", strconv.Itoa(workerNode.Ram))
|
||||
urlValues.Add("workerDisk", strconv.Itoa(workerNode.Disk))
|
||||
|
||||
//if withLB, ok := d.GetOk("with_lb"); ok {
|
||||
//urlValues.Add("withLB", strconv.FormatBool(withLB.(bool)))
|
||||
//}
|
||||
urlValues.Add("withLB", strconv.FormatBool(true))
|
||||
if withLB, ok := d.GetOk("with_lb"); ok {
|
||||
urlValues.Add("withLB", strconv.FormatBool(withLB.(bool)))
|
||||
} else {
|
||||
urlValues.Add("withLB", strconv.FormatBool(true))
|
||||
}
|
||||
|
||||
if extNet, ok := d.GetOk("extnet_id"); ok {
|
||||
urlValues.Add("extnetId", strconv.Itoa(extNet.(int)))
|
||||
@@ -90,9 +92,9 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
urlValues.Add("extnetId", "0")
|
||||
}
|
||||
|
||||
//if desc, ok := d.GetOk("desc"); ok {
|
||||
//urlValues.Add("desc", desc.(string))
|
||||
//}
|
||||
if desc, ok := d.GetOk("desc"); ok {
|
||||
urlValues.Add("desc", desc.(string))
|
||||
}
|
||||
|
||||
resp, err := c.DecortAPICall(ctx, "POST", K8sCreateAPI, urlValues)
|
||||
if err != nil {
|
||||
@@ -126,59 +128,57 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
time.Sleep(time.Second * 10)
|
||||
}
|
||||
|
||||
k8s, err := utilityK8sCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.Set("default_wg_id", k8s.Groups.Workers[0].ID)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
|
||||
|
||||
resp, err = c.DecortAPICall(ctx, "POST", LbGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
var lb LbRecord
|
||||
if err := json.Unmarshal([]byte(resp), &lb); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.Set("extnet_id", lb.ExtNetID)
|
||||
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
kubeconfig, err := c.DecortAPICall(ctx, "POST", K8sGetConfigAPI, urlValues)
|
||||
if err != nil {
|
||||
log.Warnf("could not get kubeconfig: %v", err)
|
||||
}
|
||||
d.Set("kubeconfig", kubeconfig)
|
||||
|
||||
return nil
|
||||
return resourceK8sRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceK8sRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
||||
//log.Debugf("resourceK8sRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
||||
|
||||
k8s, err := utilityK8sCheckPresence(ctx, d, m)
|
||||
if k8s == nil {
|
||||
k8s, err := utilityDataK8sCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
k8sList, err := utilityK8sListCheckPresence(ctx, d, m, K8sListAPI)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
curK8s := K8SItem{}
|
||||
for _, k8sCluster := range k8sList {
|
||||
if k8sCluster.ID == k8s.ID {
|
||||
curK8s = k8sCluster
|
||||
}
|
||||
}
|
||||
if curK8s.ID == 0 {
|
||||
return diag.Errorf("Cluster with id %d not found", k8s.ID)
|
||||
}
|
||||
d.Set("vins_id", curK8s.VINSID)
|
||||
|
||||
d.Set("name", k8s.Name)
|
||||
d.Set("rg_id", k8s.RgID)
|
||||
d.Set("k8sci_id", k8s.CI)
|
||||
d.Set("wg_name", k8s.Groups.Workers[0].Name)
|
||||
d.Set("masters", nodeToResource(k8s.Groups.Masters))
|
||||
d.Set("workers", nodeToResource(k8s.Groups.Workers[0]))
|
||||
d.Set("default_wg_id", k8s.Groups.Workers[0].ID)
|
||||
masterComputeList := make([]kvmvm.ComputeGetResp, 0, len(k8s.K8SGroups.Masters.DetailedInfo))
|
||||
workersComputeList := make([]kvmvm.ComputeGetResp, 0, len(k8s.K8SGroups.Workers))
|
||||
for _, masterNode := range k8s.K8SGroups.Masters.DetailedInfo {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m, masterNode.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
masterComputeList = append(masterComputeList, *compute)
|
||||
}
|
||||
for _, worker := range k8s.K8SGroups.Workers {
|
||||
for _, info := range worker.DetailedInfo {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
workersComputeList = append(workersComputeList, *compute)
|
||||
}
|
||||
}
|
||||
|
||||
flattenResourceK8s(d, *k8s, masterComputeList, workersComputeList)
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
|
||||
urlValues.Add("lbId", strconv.FormatUint(k8s.LBID, 10))
|
||||
|
||||
resp, err := c.DecortAPICall(ctx, "POST", LbGetAPI, urlValues)
|
||||
if err != nil {
|
||||
@@ -225,21 +225,21 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
wg := k8s.Groups.Workers[0]
|
||||
wg := k8s.K8SGroups.Workers[0]
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
urlValues.Add("workersGroupId", strconv.Itoa(wg.ID))
|
||||
urlValues.Add("workersGroupId", strconv.FormatUint(wg.ID, 10))
|
||||
|
||||
newWorkers := parseNode(d.Get("workers").([]interface{}))
|
||||
|
||||
if newWorkers.Num > wg.Num {
|
||||
urlValues.Add("num", strconv.Itoa(newWorkers.Num-wg.Num))
|
||||
if uint64(newWorkers.Num) > wg.Num {
|
||||
urlValues.Add("num", strconv.FormatUint(uint64(newWorkers.Num)-wg.Num, 10))
|
||||
if _, err := c.DecortAPICall(ctx, "POST", K8sWorkerAddAPI, urlValues); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
for i := wg.Num - 1; i >= newWorkers.Num; i-- {
|
||||
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
|
||||
for i := int(wg.Num) - 1; i >= newWorkers.Num; i-- {
|
||||
urlValues.Set("workerId", strconv.FormatUint(wg.DetailedInfo[i].ID, 10))
|
||||
if _, err := c.DecortAPICall(ctx, "POST", K8sWorkerDeleteAPI, urlValues); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -306,10 +306,11 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
"masters": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: nodeK8sSubresourceSchemaMake(),
|
||||
Schema: mastersSchemaMake(),
|
||||
},
|
||||
Description: "Master node(s) configuration.",
|
||||
},
|
||||
@@ -317,20 +318,21 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
"workers": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: nodeK8sSubresourceSchemaMake(),
|
||||
Schema: workersSchemaMake(),
|
||||
},
|
||||
Description: "Worker node(s) configuration.",
|
||||
},
|
||||
|
||||
//"with_lb": {
|
||||
//Type: schema.TypeBool,
|
||||
//Optional: true,
|
||||
//ForceNew: true,
|
||||
//Default: true,
|
||||
//Description: "Create k8s with load balancer if true.",
|
||||
//},
|
||||
"with_lb": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: true,
|
||||
Description: "Create k8s with load balancer if true.",
|
||||
},
|
||||
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
@@ -340,17 +342,80 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
|
||||
},
|
||||
|
||||
//"desc": {
|
||||
//Type: schema.TypeString,
|
||||
//Optional: true,
|
||||
//Description: "Text description of this instance.",
|
||||
//},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Text description of this instance.",
|
||||
},
|
||||
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: aclGroupSchemaMake(),
|
||||
},
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"bservice_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"k8s_ci_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"lb_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "IP address of default load balancer.",
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"default_wg_id": {
|
||||
Type: schema.TypeInt,
|
||||
@@ -363,6 +428,11 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Kubeconfig for cluster access.",
|
||||
},
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of default vins for this instace.",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +450,7 @@ func ResourceK8s() *schema.Resource {
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Create: &constants.Timeout30m,
|
||||
Read: &constants.Timeout300s,
|
||||
Update: &constants.Timeout300s,
|
||||
Delete: &constants.Timeout300s,
|
||||
|
||||
@@ -35,11 +35,13 @@ import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/kvmvm"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -91,23 +93,51 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
//time.Sleep(time.Second * 5)
|
||||
//}
|
||||
|
||||
return nil
|
||||
return resourceK8sWgRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int))
|
||||
log.Debugf("resourceK8sWgRead: called with %v", d.Id())
|
||||
|
||||
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
|
||||
if wg == nil {
|
||||
d.SetId("")
|
||||
k8s, err := utilityDataK8sCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.Set("name", wg.Name)
|
||||
d.Set("num", wg.Num)
|
||||
d.Set("cpu", wg.Cpu)
|
||||
d.Set("ram", wg.Ram)
|
||||
d.Set("disk", wg.Disk)
|
||||
var id int
|
||||
if d.Id() != "" {
|
||||
id, err = strconv.Atoi(strings.Split(d.Id(), "#")[0])
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
id = d.Get("wg_id").(int)
|
||||
}
|
||||
|
||||
curWg := K8SGroup{}
|
||||
for _, wg := range k8s.K8SGroups.Workers {
|
||||
if wg.ID == uint64(id) {
|
||||
curWg = wg
|
||||
break
|
||||
}
|
||||
}
|
||||
if curWg.ID == 0 {
|
||||
return diag.Errorf("Not found wg with id: %v in k8s cluster: %v", id, k8s.ID)
|
||||
}
|
||||
|
||||
workersComputeList := make([]kvmvm.ComputeGetResp, 0, 0)
|
||||
for _, info := range curWg.DetailedInfo {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
workersComputeList = append(workersComputeList, *compute)
|
||||
}
|
||||
|
||||
d.SetId(strings.Split(d.Id(), "#")[0])
|
||||
d.Set("k8s_id", k8s.ID)
|
||||
d.Set("wg_id", curWg.ID)
|
||||
flattenWgData(d, curWg, workersComputeList)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -126,15 +156,15 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||
urlValues.Add("workersGroupId", d.Id())
|
||||
|
||||
if newNum := d.Get("num").(int); newNum > wg.Num {
|
||||
urlValues.Add("num", strconv.Itoa(newNum-wg.Num))
|
||||
if newNum := d.Get("num").(int); uint64(newNum) > wg.Num {
|
||||
urlValues.Add("num", strconv.FormatUint(uint64(newNum)-wg.Num, 10))
|
||||
_, err := c.DecortAPICall(ctx, "POST", K8sWorkerAddAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
for i := wg.Num - 1; i >= newNum; i-- {
|
||||
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
|
||||
for i := int(wg.Num) - 1; i >= newNum; i-- {
|
||||
urlValues.Set("workerId", strconv.FormatUint(wg.DetailedInfo[i].ID, 10))
|
||||
_, err := c.DecortAPICall(ctx, "POST", K8sWorkerDeleteAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -159,7 +189,7 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||
urlValues.Add("workersGroupId", strconv.Itoa(wg.ID))
|
||||
urlValues.Add("workersGroupId", strconv.FormatUint(wg.ID, 10))
|
||||
|
||||
_, err = c.DecortAPICall(ctx, "POST", K8sWgDeleteAPI, urlValues)
|
||||
if err != nil {
|
||||
@@ -215,6 +245,43 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
|
||||
Default: 0,
|
||||
Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.",
|
||||
},
|
||||
"wg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of k8s worker Group.",
|
||||
},
|
||||
"detailed_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: detailedInfoSchemaMake(),
|
||||
},
|
||||
},
|
||||
"labels": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"annotations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"taints": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,15 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/kvmvm"
|
||||
)
|
||||
|
||||
func utilityK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8sRecord, error) {
|
||||
func utilityK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8SRecord, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
@@ -54,10 +57,76 @@ func utilityK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m inte
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var k8s K8sRecord
|
||||
k8s := K8SRecord{}
|
||||
if err := json.Unmarshal([]byte(resp), &k8s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &k8s, nil
|
||||
}
|
||||
|
||||
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}, computeID uint64) (*kvmvm.ComputeGetResp, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("computeId", strconv.FormatUint(computeID, 10))
|
||||
|
||||
computeRaw, err := c.DecortAPICall(ctx, "POST", kvmvm.ComputeGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
compute := &kvmvm.ComputeGetResp{}
|
||||
err = json.Unmarshal([]byte(computeRaw), compute)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return compute, nil
|
||||
}
|
||||
|
||||
func utilityDataK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8SRecord, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
if d.Get("k8s_id") != 0 && d.Get("k8s_id") != nil {
|
||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||
} else if id := d.Id(); id != "" {
|
||||
if strings.Contains(id, "#") {
|
||||
urlValues.Add("k8sId", strings.Split(d.Id(), "#")[1])
|
||||
} else {
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
}
|
||||
}
|
||||
k8sRaw, err := c.DecortAPICall(ctx, "POST", K8sGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8s := &K8SRecord{}
|
||||
err = json.Unmarshal([]byte(k8sRaw), k8s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return k8s, nil
|
||||
}
|
||||
|
||||
func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}, api string) (K8SList, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("includedeleted", "false")
|
||||
urlValues.Add("page", "0")
|
||||
urlValues.Add("size", "0")
|
||||
|
||||
k8sListRaw, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sList := K8SList{}
|
||||
|
||||
err = json.Unmarshal([]byte(k8sListRaw), &k8sList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return k8sList, nil
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ package k8s
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
@@ -41,7 +42,7 @@ import (
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8sNodeRecord, error) {
|
||||
func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8SGroup, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||
@@ -52,24 +53,29 @@ func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m in
|
||||
}
|
||||
|
||||
if resp == "" {
|
||||
return nil, nil
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var k8s K8sRecord
|
||||
var k8s K8SRecord
|
||||
if err := json.Unmarshal([]byte(resp), &k8s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(d.Id())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var id int
|
||||
if d.Id() != "" {
|
||||
id, err = strconv.Atoi(d.Id())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
id = d.Get("wg_id").(int)
|
||||
}
|
||||
|
||||
for _, wg := range k8s.Groups.Workers {
|
||||
if wg.ID == id {
|
||||
for _, wg := range k8s.K8SGroups.Workers {
|
||||
if wg.ID == uint64(id) {
|
||||
return &wg, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return nil, fmt.Errorf("Not found wg with id: %v in k8s cluster: %v", id, k8s.ID)
|
||||
}
|
||||
|
||||
@@ -49,4 +49,7 @@ const (
|
||||
ComputeUpdateAPI = "/restmachine/cloudapi/compute/update"
|
||||
ComputeDiskAddAPI = "/restmachine/cloudapi/compute/diskAdd"
|
||||
ComputeDiskDeleteAPI = "/restmachine/cloudapi/compute/diskDel"
|
||||
ComputeRestoreAPI = "/restmachine/cloudapi/compute/restore"
|
||||
ComputeEnableAPI = "/restmachine/cloudapi/compute/enable"
|
||||
ComputeDisableAPI = "/restmachine/cloudapi/compute/disable"
|
||||
)
|
||||
|
||||
@@ -40,10 +40,12 @@ import (
|
||||
// "net/url"
|
||||
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/status"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
// "github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
||||
)
|
||||
|
||||
@@ -176,14 +178,17 @@ func flattenCompute(d *schema.ResourceData, compFacts string) error {
|
||||
d.Set("image_id", model.ImageID)
|
||||
}
|
||||
d.Set("description", model.Desc)
|
||||
d.Set("enabled", false)
|
||||
if model.Status == status.Enabled {
|
||||
d.Set("enabled", true)
|
||||
}
|
||||
|
||||
d.Set("cloud_init", "applied") // NOTE: for existing compute we hard-code this value as an indicator for DiffSuppress fucntion
|
||||
// d.Set("status", model.Status)
|
||||
// d.Set("tech_status", model.TechStatus)
|
||||
|
||||
d.Set("started", false)
|
||||
if model.TechStatus == "STARTED" {
|
||||
d.Set("started", true)
|
||||
} else {
|
||||
d.Set("started", false)
|
||||
}
|
||||
|
||||
bootDisk := findBootDisk(model.Disks)
|
||||
@@ -270,6 +275,12 @@ func DataSourceCompute() *schema.Resource {
|
||||
Description: "ID of the resource group where this compute instance is located.",
|
||||
},
|
||||
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "If true - enable the compute, else - disable",
|
||||
},
|
||||
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -339,16 +350,67 @@ func DataSourceCompute() *schema.Resource {
|
||||
Description: "IDs of the extra disk(s) attached to this compute.",
|
||||
},
|
||||
|
||||
/*
|
||||
"disks": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceDiskSchemaMake(), // ID, type, name, size, account ID, SEP ID, SEP type, pool, status, tech status, compute ID, image ID
|
||||
"disks": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"disk_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Name for disk",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Disk size in GiB",
|
||||
},
|
||||
"disk_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"B", "D"}, false),
|
||||
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'",
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Description: "Storage endpoint provider ID; by default the same with boot disk",
|
||||
},
|
||||
"pool": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Description: "Pool name; by default will be chosen automatically",
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Description: "Optional description",
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Description: "Specify image id for create disk from template",
|
||||
},
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Disk ID",
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Disk deletion status",
|
||||
},
|
||||
},
|
||||
Description: "Detailed specification for all disks attached to this compute instance (including bood disk).",
|
||||
},
|
||||
*/
|
||||
},
|
||||
|
||||
"network": {
|
||||
Type: schema.TypeSet,
|
||||
@@ -384,7 +446,7 @@ func DataSourceCompute() *schema.Resource {
|
||||
"started": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Computed: true,
|
||||
Description: "Is compute started.",
|
||||
},
|
||||
},
|
||||
|
||||
@@ -34,6 +34,7 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -41,6 +42,7 @@ import (
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/statefuncs"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/status"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
@@ -208,6 +210,20 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if enabled, ok := d.GetOk("enabled"); ok {
|
||||
api := ComputeDisableAPI
|
||||
if enabled.(bool) {
|
||||
api = ComputeEnableAPI
|
||||
}
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", fmt.Sprintf("%d", compId))
|
||||
log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", compId, enabled)
|
||||
if _, err := c.DecortAPICall(ctx, "POST", api, urlValues); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if !cleanup {
|
||||
if disks, ok := d.GetOk("disks"); ok {
|
||||
log.Debugf("resourceComputeCreate: Create disks on ComputeID: %d", compId)
|
||||
@@ -258,6 +274,8 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
log.Debugf("resourceComputeRead: called for Compute name %s, RG ID %d",
|
||||
d.Get("name").(string), d.Get("rg_id").(int))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
compFacts, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if compFacts == "" {
|
||||
if err != nil {
|
||||
@@ -267,6 +285,49 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
return nil
|
||||
}
|
||||
|
||||
compute := &ComputeGetResp{}
|
||||
err = json.Unmarshal([]byte(compFacts), compute)
|
||||
|
||||
log.Debugf("resourceComputeRead: compute is: %+v", compute)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
switch compute.Status {
|
||||
case status.Deleted:
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", d.Id())
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeRestoreAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
_, err = c.DecortAPICall(ctx, "POST", ComputeEnableAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceComputeCreate(ctx, d, m)
|
||||
case status.Disabled:
|
||||
log.Debugf("The compute is in status: %s, may troubles can be occured with update. Please, enable compute first.", compute.Status)
|
||||
case status.Redeploying:
|
||||
case status.Deleting:
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The compute is in progress with status: %s", compute.Status)
|
||||
case status.Modeled:
|
||||
return diag.Errorf("The compute is in status: %s, please, contant the support for more information", compute.Status)
|
||||
}
|
||||
|
||||
compFacts, err = utilityComputeCheckPresence(ctx, d, m)
|
||||
log.Debugf("resourceComputeRead: after changes compute is: %s", compFacts)
|
||||
if compFacts == "" {
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// Compute with such name and RG ID was not found
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = flattenCompute(d, compFacts); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -283,6 +344,56 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
computeRaw, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
compute := &ComputeGetResp{}
|
||||
err = json.Unmarshal([]byte(computeRaw), compute)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if d.HasChange("enabled") {
|
||||
enabled := d.Get("enabled")
|
||||
api := ComputeDisableAPI
|
||||
if enabled.(bool) {
|
||||
api = ComputeEnableAPI
|
||||
}
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", d.Id())
|
||||
log.Debugf("resourceComputeUpdate: enable=%t Compute ID %s after completing its resource configuration", d.Id(), enabled)
|
||||
if _, err := c.DecortAPICall(ctx, "POST", api, urlValues); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check compute statuses
|
||||
switch compute.Status {
|
||||
case status.Deleted:
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", d.Id())
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeRestoreAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
_, err = c.DecortAPICall(ctx, "POST", ComputeEnableAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceComputeCreate(ctx, d, m)
|
||||
case status.Disabled:
|
||||
log.Debugf("The compute is in status: %s, may troubles can be occured with update. Please, enable compute first.", compute.Status)
|
||||
case status.Redeploying:
|
||||
case status.Deleting:
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The compute is in progress with status: %s", compute.Status)
|
||||
case status.Modeled:
|
||||
return diag.Errorf("The compute is in status: %s, please, contant the support for more information", compute.Status)
|
||||
}
|
||||
|
||||
/*
|
||||
1. Resize CPU/RAM
|
||||
2. Resize (grow) boot disk
|
||||
@@ -348,7 +459,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
|
||||
// 4. Calculate and apply changes to network connections
|
||||
err := utilityComputeNetworksConfigure(ctx, d, m, true, false) // pass do_delta = true to apply changes, if any
|
||||
err = utilityComputeNetworksConfigure(ctx, d, m, true, false) // pass do_delta = true to apply changes, if any
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -678,6 +789,13 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Description: "Optional cloud_init parameters. Applied when creating new compute instance only, ignored in all other cases.",
|
||||
},
|
||||
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "If true - enable compute, else - disable",
|
||||
},
|
||||
|
||||
// The rest are Compute properties, which are "computed" once it is created
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
@@ -715,7 +833,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
"started": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Computed: true,
|
||||
Description: "Is compute started.",
|
||||
},
|
||||
"detach_disks": {
|
||||
|
||||
Reference in New Issue
Block a user