From 523d96189fd42070524663ce25ccae6a2756c74f Mon Sep 17 00:00:00 2001 From: Tim Tkachev Date: Fri, 19 May 2023 17:14:55 +0300 Subject: [PATCH] 4.0.1 --- .gitignore | 2 +- CHANGELOG.md | 31 +------- Makefile | 2 +- go.mod | 2 +- go.sum | 4 +- internal/service/cloudapi/k8s/resource_k8s.go | 4 +- .../service/cloudapi/k8s/resource_k8s_wg.go | 75 +++++++++++++------ .../cloudapi/kvmvm/resource_compute.go | 12 ++- internal/service/cloudapi/pfw/resource_pfw.go | 2 +- .../service/cloudbroker/pfw/resource_pfw.go | 2 +- 10 files changed, 72 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 37fbf2b..6e92c2a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ decort/vendor/ examples/ url_scrapping/ terraform-provider-decort* -.vscode/ +.vscode/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 939c454..43af9d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,5 @@ -## Version 4.0.0 - -### Features -- Updated provider to the newest DECORT version (3.8.6): - - resource_k8s now has "network_plugin" required field - - Added "start" argument to resource_k8s - - data_source_bservice, resource_bservice "computes" and "groups" fields now have more in-depth information - - resource_compute now has full boot disk information - - data_source_extnet now has additional field "e_burst" inside "default_qos" substructure - - data_source_rg_list, data_source_rg, resource_rg, resource_account and data_source_account now have two additional fields: - - cpu_allocation_parameter - - cpu_allocation_ratio - - unnecessary fields were removed from all disks data sources && resources (except for unattached disks), to be exact: - - boot_partition - - guid - - disk_path - - iqn - - login - - milestones - - password - - purge_attempts - - reality_device_number - - reference_id -- Removed automatic switch between cloudbroker/cloudapi (admin/user modes) +## Version 4.0.1 ## Bug Fix -- Fixed resource_compute error when creating a new instance with EXTNET type network -- Fixed quota record marshalling in decort_resgroup resource -- Fixed GID validation for multiple resources -- Fixed possible 'addUser' error when importing resource_account with already added user +- Fixed incorrect state reading when creating/deleting port_forwarding in decort_kvmvm +- Fixed possible segmentation fault with multiple concurrent resource manipulations diff --git a/Makefile b/Makefile index 743d914..7bfb4c8 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ ZIPDIR = ./zip BINARY=${NAME}.exe WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH} MAINPATH = ./cmd/decort/ -VERSION=4.0.0 +VERSION=4.0.1 #OS_ARCH=darwin_amd64 OS_ARCH=windows_amd64 #OS_ARCH=linux_amd64 diff --git a/go.mod b/go.mod index effc710..9edc823 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 github.com/sirupsen/logrus v1.9.0 golang.org/x/net v0.5.0 - repository.basistech.ru/BASIS/decort-golang-sdk v1.4.0 + repository.basistech.ru/BASIS/decort-golang-sdk v1.4.3 ) require ( diff --git a/go.sum b/go.sum index 7171a46..9a1d519 100644 --- a/go.sum +++ b/go.sum @@ -332,5 +332,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -repository.basistech.ru/BASIS/decort-golang-sdk v1.4.0 h1:y8F3bzEb8mROEYnoG495AxpbSTEkfSpFh97sZe42cJE= -repository.basistech.ru/BASIS/decort-golang-sdk v1.4.0/go.mod h1:YP57mpXh60xeRERVaCehn+l0S7Qe24trVll1EvrKzds= +repository.basistech.ru/BASIS/decort-golang-sdk v1.4.3 h1:jrBl90lRfp34bE3m30N3mYIDTSlaPySuo+pE7bK4eOI= +repository.basistech.ru/BASIS/decort-golang-sdk v1.4.3/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE= diff --git a/internal/service/cloudapi/k8s/resource_k8s.go b/internal/service/cloudapi/k8s/resource_k8s.go index c3bb819..4d06486 100644 --- a/internal/service/cloudapi/k8s/resource_k8s.go +++ b/internal/service/cloudapi/k8s/resource_k8s.go @@ -217,7 +217,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) return diag.FromErr(err) } - enableReq := k8s.DisabelEnableRequest{ + enableReq := k8s.DisableEnableRequest{ K8SID: id, } @@ -374,7 +374,7 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{ return diag.FromErr(err) } - enableReq := k8s.DisabelEnableRequest{ + enableReq := k8s.DisableEnableRequest{ K8SID: id, } diff --git a/internal/service/cloudapi/k8s/resource_k8s_wg.go b/internal/service/cloudapi/k8s/resource_k8s_wg.go index 71823d0..41d6bb5 100644 --- a/internal/service/cloudapi/k8s/resource_k8s_wg.go +++ b/internal/service/cloudapi/k8s/resource_k8s_wg.go @@ -60,11 +60,28 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac c := m.(*controller.ControllerCfg) req := k8s.WorkersGroupAddRequest{ - K8SID: uint64(d.Get("k8s_id").(int)), - Name: d.Get("name").(string), - WorkerNum: uint64(d.Get("num").(int)), - WorkerCPU: uint64(d.Get("cpu").(int)), - WorkerRAM: uint64(d.Get("ram").(int)), + K8SID: uint64(d.Get("k8s_id").(int)), + Name: d.Get("name").(string), + WorkerNum: uint64(d.Get("num").(int)), + WorkerCPU: uint64(d.Get("cpu").(int)), + WorkerRAM: uint64(d.Get("ram").(int)), + WorkerSEPID: uint64(d.Get("worker_sep_id").(int)), + WorkerSEPPool: d.Get("worker_sep_pool").(string), + } + + labels, _ := d.Get("labels").([]interface{}) + for _, label := range labels { + req.Labels = append(req.Labels, label.(string)) + } + + annotations, _ := d.Get("annotations").([]interface{}) + for _, annotation := range annotations { + req.Annotations = append(req.Annotations, annotation.(string)) + } + + taints, _ := d.Get("taints").([]interface{}) + for _, taint := range taints { + req.Taints = append(req.Taints, taint.(string)) } if d.Get("disk") == nil { @@ -111,6 +128,7 @@ func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{ } else { d.Set("k8s_id", d.Get("k8s_id")) } + d.SetId(strings.Split(d.Id(), "#")[0]) flattenWg(d, *wg, workersComputeList) @@ -234,32 +252,18 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema { Computed: true, 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, + Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, }, }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, "annotations": { Type: schema.TypeList, Computed: true, + Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -267,10 +271,35 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema { "taints": { Type: schema.TypeList, Computed: true, + Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, }, }, + "worker_sep_id": { + Type: schema.TypeInt, + Optional: true, + }, + "worker_sep_pool": { + Type: schema.TypeString, + Optional: true, + }, + "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(), + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, } } @@ -289,8 +318,8 @@ func ResourceK8sWg() *schema.Resource { Timeouts: &schema.ResourceTimeout{ Create: &constants.Timeout600s, - Read: &constants.Timeout300s, - Update: &constants.Timeout300s, + Read: &constants.Timeout600s, + Update: &constants.Timeout600s, Delete: &constants.Timeout300s, Default: &constants.Timeout300s, }, diff --git a/internal/service/cloudapi/kvmvm/resource_compute.go b/internal/service/cloudapi/kvmvm/resource_compute.go index e6372e5..295fe9e 100644 --- a/internal/service/cloudapi/kvmvm/resource_compute.go +++ b/internal/service/cloudapi/kvmvm/resource_compute.go @@ -373,7 +373,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf req := compute.PFWAddRequest{ ComputeID: computeId, PublicPortStart: uint64(pfwItem["public_port_start"].(int)), - PublicPortEnd: uint64(pfwItem["public_port_end"].(int)), + PublicPortEnd: int64(pfwItem["public_port_end"].(int)), LocalBasePort: uint64(pfwItem["local_port"].(int)), Proto: pfwItem["proto"].(string), } @@ -630,6 +630,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf Force: true, } + warnings := dc.Warnings{} + oldCpu, newCpu := d.GetChange("cpu") if oldCpu.(int) != newCpu.(int) { resizeReq.CPU = uint64(newCpu.(int)) @@ -1059,7 +1061,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf _, err := c.CloudAPI().Compute().PFWDel(ctx, req) if err != nil { - return diag.FromErr(err) + warnings.Add(err) } } } @@ -1071,7 +1073,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf req := compute.PFWAddRequest{ ComputeID: computeRec.ID, PublicPortStart: uint64(pfwItem["public_port_start"].(int)), - PublicPortEnd: uint64(pfwItem["public_port_end"].(int)), + PublicPortEnd: int64(pfwItem["public_port_end"].(int)), LocalBasePort: uint64(pfwItem["local_port"].(int)), Proto: pfwItem["proto"].(string), } @@ -1311,7 +1313,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf // we may reuse dataSourceComputeRead here as we maintain similarity // between Compute resource and Compute data source schemas - return resourceComputeRead(ctx, d, m) + defer resourceComputeRead(ctx, d, m) + return warnings.Get() } func isChangeDisk(els []interface{}, el interface{}) bool { @@ -1696,6 +1699,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { "network": { Type: schema.TypeSet, + Computed: true, Optional: true, MinItems: 1, MaxItems: constants.MaxNetworksPerCompute, diff --git a/internal/service/cloudapi/pfw/resource_pfw.go b/internal/service/cloudapi/pfw/resource_pfw.go index 99d2fd8..8aceeb2 100644 --- a/internal/service/cloudapi/pfw/resource_pfw.go +++ b/internal/service/cloudapi/pfw/resource_pfw.go @@ -57,7 +57,7 @@ func resourcePfwCreate(ctx context.Context, d *schema.ResourceData, m interface{ } if portEnd, ok := d.GetOk("public_port_end"); ok { - req.PublicPortEnd = uint64(portEnd.(int)) + req.PublicPortEnd = int64(portEnd.(int)) } pfwId, err := c.CloudAPI().Compute().PFWAdd(ctx, req) diff --git a/internal/service/cloudbroker/pfw/resource_pfw.go b/internal/service/cloudbroker/pfw/resource_pfw.go index 9c0a00b..b0c151c 100644 --- a/internal/service/cloudbroker/pfw/resource_pfw.go +++ b/internal/service/cloudbroker/pfw/resource_pfw.go @@ -55,7 +55,7 @@ func resourcePfwCreate(ctx context.Context, d *schema.ResourceData, m interface{ req.Proto = d.Get("proto").(string) if portEnd, ok := d.GetOk("public_port_end"); ok { - req.PublicPortEnd = uint64(portEnd.(int)) + req.PublicPortEnd = int64(portEnd.(int)) } pfwId, err := c.CloudBroker().Compute().PFWAdd(ctx, req)