From f731cf246f39256f4f53326a34980212cd655d58 Mon Sep 17 00:00:00 2001 From: Tim Tkachev Date: Fri, 7 Jul 2023 11:54:41 +0300 Subject: [PATCH] 4.2.4 --- CHANGELOG.md | 6 +- Makefile | 2 +- cmd/decort/main.go | 1 + .../cloudapi/extnet/data_source_extnet.go | 8 +-- internal/service/cloudapi/extnet/flattens.go | 1 - .../cloudapi/kvmvm/network_subresource.go | 3 +- .../kvmvm/resource_check_input_values.go | 26 +++----- .../cloudapi/kvmvm/resource_compute.go | 62 ++++++++++--------- 8 files changed, 52 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 811fc94..78ff476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ -## Version 4.2.3 +## Version 4.2.4 ## Bug Fixes -- Made "ipcidr" field in decort_vins resource optional +- Fixed incorrect network validation in decort_kvmvm resource +- Fixed inability to remove all networks at once in decort_kvmvm resource +- Deleted "check__ips" (duplicate) field in decort_extnet data source diff --git a/Makefile b/Makefile index 5257f62..60b9c5a 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.2.3 +VERSION=4.2.4 #OS_ARCH=darwin_amd64 OS_ARCH=windows_amd64 #OS_ARCH=linux_amd64 diff --git a/cmd/decort/main.go b/cmd/decort/main.go index 738370f..6173032 100644 --- a/cmd/decort/main.go +++ b/cmd/decort/main.go @@ -4,6 +4,7 @@ Authors: Petr Krutov, Stanislav Solovev, Kasim Baybikov, +Tim Tkachev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/internal/service/cloudapi/extnet/data_source_extnet.go b/internal/service/cloudapi/extnet/data_source_extnet.go index 2a5565c..1bb6d6a 100644 --- a/internal/service/cloudapi/extnet/data_source_extnet.go +++ b/internal/service/cloudapi/extnet/data_source_extnet.go @@ -4,6 +4,7 @@ Authors: Petr Krutov, Stanislav Solovev, Kasim Baybikov, +Tim Tkachev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -71,13 +72,6 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema { }, Description: "meta", }, - "check__ips": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, "check_ips": { Type: schema.TypeList, Computed: true, diff --git a/internal/service/cloudapi/extnet/flattens.go b/internal/service/cloudapi/extnet/flattens.go index ce5408a..ec5969a 100644 --- a/internal/service/cloudapi/extnet/flattens.go +++ b/internal/service/cloudapi/extnet/flattens.go @@ -9,7 +9,6 @@ import ( func flattenExtnet(d *schema.ResourceData, e *extnet.RecordExtNet) { d.Set("ckey", e.CKey) d.Set("meta", flattens.FlattenMeta(e.Meta)) - d.Set("check__ips", e.CheckIPs) d.Set("check_ips", e.CheckIps) d.Set("default", e.Default) d.Set("default_qos", flattenExtnetDefaultQos(e.DefaultQOS)) diff --git a/internal/service/cloudapi/kvmvm/network_subresource.go b/internal/service/cloudapi/kvmvm/network_subresource.go index c9be582..6783bc2 100644 --- a/internal/service/cloudapi/kvmvm/network_subresource.go +++ b/internal/service/cloudapi/kvmvm/network_subresource.go @@ -4,6 +4,7 @@ Authors: Petr Krutov, Stanislav Solovev, Kasim Baybikov, +Tim Tkachev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -36,8 +37,8 @@ import ( "bytes" "hash/fnv" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs" log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs" "sort" diff --git a/internal/service/cloudapi/kvmvm/resource_check_input_values.go b/internal/service/cloudapi/kvmvm/resource_check_input_values.go index 3280dbd..367931a 100644 --- a/internal/service/cloudapi/kvmvm/resource_check_input_values.go +++ b/internal/service/cloudapi/kvmvm/resource_check_input_values.go @@ -4,6 +4,7 @@ Authors: Petr Krutov, Stanislav Solovev, Kasim Baybikov, +Tim Tkachev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -36,6 +37,7 @@ import ( "context" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg" @@ -91,43 +93,35 @@ func existExtNetIdInList(extId uint64, extList extnet.ListExtNets) bool { return false } -func existVinsId(ctx context.Context, d *schema.ResourceData, m interface{}) (int, bool) { +func existVinsId(ctx context.Context, m interface{}, id int) (int, bool) { c := m.(*controller.ControllerCfg) req := vins.ListRequest{IncludeDeleted: false} vinsList, err := c.CloudAPI().VINS().List(ctx, req) if err != nil { + log.Debugf("Unable to retrieve ViNS list, %s", err) return 0, false } - networks := d.Get("network").(*schema.Set).List() - - for _, networkInterface := range networks { - networkItem := networkInterface.(map[string]interface{}) - if !existVinsIdInList(uint64(networkItem["net_id"].(int)), vinsList) { - return networkItem["net_id"].(int), false - } + if !existVinsIdInList(uint64(id), vinsList) { + return id, false } return 0, true } -func existExtNetId(ctx context.Context, d *schema.ResourceData, m interface{}) (int, bool) { +func existExtNetId(ctx context.Context, m interface{}, id int) (int, bool) { c := m.(*controller.ControllerCfg) req := extnet.ListRequest{} extNetList, err := c.CloudAPI().ExtNet().List(ctx, req) if err != nil { + log.Debugf("Unable to retrieve extnet list, %s", err) return 0, false } - networks := d.Get("network").(*schema.Set).List() - - for _, networkInterface := range networks { - networkItem := networkInterface.(map[string]interface{}) - if !existExtNetIdInList(uint64(networkItem["net_id"].(int)), extNetList) { - return networkItem["net_id"].(int), false - } + if !existExtNetIdInList(uint64(id), extNetList) { + return id, false } return 0, true diff --git a/internal/service/cloudapi/kvmvm/resource_compute.go b/internal/service/cloudapi/kvmvm/resource_compute.go index d3eafcd..2dae70c 100644 --- a/internal/service/cloudapi/kvmvm/resource_compute.go +++ b/internal/service/cloudapi/kvmvm/resource_compute.go @@ -4,6 +4,7 @@ Authors: Petr Krutov, Stanislav Solovev, Kasim Baybikov, +Tim Tkachev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -77,14 +78,22 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf } if network, ok := d.GetOk("network"); ok { - networkData := network.(*schema.Set).List()[0].(map[string]interface{}) - if networkData["net_type"].(string) == "VINS" { - if vinsId, ok := existVinsId(ctx, d, m); !ok { - return diag.Errorf("resourceComputeCreate: can't create compute because vins ID %d is not allowed or does not exist", vinsId) - } - } else if networkData["net_type"].(string) == "EXTNET" { - if extNetId, ok := existExtNetId(ctx, d, m); !ok { - return diag.Errorf("resourceComputeCreate: can't create compute because extnet ID %d is not allowed or does not exist", extNetId) + networkList := network.(*schema.Set).List() + for _, elem := range networkList { + networkData := elem.(map[string]interface{}) + + switch networkData["net_type"].(string) { + case "VINS": + if vinsId, ok := existVinsId(ctx, m, networkData["net_id"].(int)); !ok { + return diag.Errorf("resourceComputeCreate: can't create compute because vins ID %d is not allowed or does not exist", vinsId) + } + case "EXTNET": + if extNetId, ok := existExtNetId(ctx, m, networkData["net_id"].(int)); !ok { + return diag.Errorf("resourceComputeCreate: can't create compute because extnet ID %d is not allowed or does not exist", extNetId) + } + + default: + continue } } } @@ -557,14 +566,22 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf } if network, ok := d.GetOk("network"); ok { - networkData := network.(*schema.Set).List()[0].(map[string]interface{}) - if networkData["net_type"].(string) == "VINS" { - if vinsId, ok := existVinsId(ctx, d, m); !ok { - return diag.Errorf("resourceComputeUpdate: can't create update because vins ID %d is not allowed or does not exist", vinsId) - } - } else if networkData["net_type"].(string) == "EXTNET" { - if extNetId, ok := existExtNetId(ctx, d, m); !ok { - return diag.Errorf("resourceComputeUpdate: can't create update because extnet ID %d is not allowed or does not exist", extNetId) + networkList := network.(*schema.Set).List() + for _, elem := range networkList { + networkData := elem.(map[string]interface{}) + + switch networkData["net_type"].(string) { + case "VINS": + if vinsId, ok := existVinsId(ctx, m, networkData["net_id"].(int)); !ok { + return diag.Errorf("resourceComputeUpdate: can't update compute because vins ID %d is not allowed or does not exist", vinsId) + } + case "EXTNET": + if extNetId, ok := existExtNetId(ctx, m, networkData["net_id"].(int)); !ok { + return diag.Errorf("resourceComputeUpdate: can't update compute because extnet ID %d is not allowed or does not exist", extNetId) + } + + default: + continue } } } @@ -1704,7 +1721,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { "network": { Type: schema.TypeSet, - Computed: true, Optional: true, MinItems: 1, MaxItems: constants.MaxNetworksPerCompute, @@ -1714,18 +1730,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.", }, - /* - "ssh_keys": { - Type: schema.TypeList, - Optional: true, - MaxItems: MaxSshKeysPerCompute, - Elem: &schema.Resource{ - Schema: sshSubresourceSchemaMake(), - }, - Description: "SSH keys to authorize on this compute instance.", - }, - */ - "tags": { Type: schema.TypeSet, Optional: true,