From c89574c3e6b6427d994f4144da6b923a83e712b4 Mon Sep 17 00:00:00 2001 From: Nikita Sorokin Date: Fri, 22 Sep 2023 12:49:22 +0300 Subject: [PATCH] 4.3.7 --- .gitignore | 2 + CHANGELOG.md | 6 +- Makefile | 2 +- go.mod | 2 +- go.sum | 4 +- .../service/cloudapi/vins/data_source_vins.go | 42 ++++++++++---- .../cloudapi/vins/data_source_vins_audits.go | 2 +- .../vins/data_source_vins_ext_net_list.go | 8 ++- .../cloudapi/vins/data_source_vins_ip_list.go | 8 ++- .../cloudapi/vins/data_source_vins_list.go | 2 +- .../vins/data_source_vins_list_deleted.go | 2 +- .../vins/data_source_vins_nat_rule_list.go | 8 ++- internal/service/cloudapi/vins/flattens.go | 57 +++++++++++-------- .../service/cloudapi/vins/resource_vins.go | 33 ++++++----- .../service/cloudapi/vins/utility_vins.go | 25 +++----- .../cloudapi/vins/utility_vins_audits.go | 12 +++- .../vins/utility_vins_ext_net_list.go | 10 +++- .../cloudapi/vins/utility_vins_ip_list.go | 12 +++- .../cloudapi/vins/utility_vins_list.go | 2 +- .../vins/utility_vins_list_deleted.go | 2 +- .../vins/utility_vins_nat_rule_list.go | 12 +++- 21 files changed, 160 insertions(+), 93 deletions(-) diff --git a/.gitignore b/.gitignore index 37fbf2b..0e42255 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ examples/ url_scrapping/ terraform-provider-decort* .vscode/ +.DS_Store + diff --git a/CHANGELOG.md b/CHANGELOG.md index 969b87e..913b876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ -## Version 4.3.6 +## Version 4.3.7 ## Bugfix -- Fixed bug with disks resize error \ No newline at end of file +- Fixed bug with get request. Update cloudapi/vins +- Updated decort-golang-sdk version + diff --git a/Makefile b/Makefile index 99ba99c..560f7de 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ ZIPDIR = ./zip BINARY=${NAME} WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH} MAINPATH = ./cmd/decort/ -VERSION=4.3.6 +VERSION=4.3.7 OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) FILES = ${BINARY}_${VERSION}_darwin_amd64\ diff --git a/go.mod b/go.mod index c5930ae..d3844aa 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.12.0 - repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3 + repository.basistech.ru/BASIS/decort-golang-sdk v1.5.8 ) require ( diff --git a/go.sum b/go.sum index 9ce6f53..7c34f4c 100644 --- a/go.sum +++ b/go.sum @@ -339,5 +339,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.5.3 h1:Rt5tE4EZcUr4ONK9u/XYe2mG1CC37xLUnNuCLYKDwYs= -repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE= +repository.basistech.ru/BASIS/decort-golang-sdk v1.5.8 h1:NQ9cEZmWhqXzG3Gxsh0zkQjnqR/HI7JWbN9+EOqGUnE= +repository.basistech.ru/BASIS/decort-golang-sdk v1.5.8/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE= diff --git a/internal/service/cloudapi/vins/data_source_vins.go b/internal/service/cloudapi/vins/data_source_vins.go index 23cd81b..711ca39 100644 --- a/internal/service/cloudapi/vins/data_source_vins.go +++ b/internal/service/cloudapi/vins/data_source_vins.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -34,8 +34,8 @@ package vins import ( "context" - "strconv" + "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" @@ -47,8 +47,9 @@ func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface return diag.FromErr(err) } - d.SetId(strconv.FormatUint(vins.ID, 10)) - flattenVinsData(d, *vins) + id := uuid.New() + d.SetId(id.String()) + flattenVinsData(d, vins) return nil } @@ -640,7 +641,7 @@ func rulesSchemaMake() map[string]*schema.Schema { } } -func configSchrmaMake() map[string]*schema.Schema { +func natConfigSchemaMake() map[string]*schema.Schema { return map[string]*schema.Schema{ "net_mask": { Type: schema.TypeInt, @@ -678,7 +679,7 @@ func natSchemaMake() map[string]*schema.Schema { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ - Schema: configSchrmaMake(), + Schema: natConfigSchemaMake(), }, }, "devices": { @@ -768,7 +769,6 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema { Required: true, Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.", }, - "vnf_dev": { Type: schema.TypeList, Computed: true, @@ -776,10 +776,6 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema { Schema: vnfDevSchemaMake(), }, }, - "_ckey": { - Type: schema.TypeString, - Computed: true, - }, "account_id": { Type: schema.TypeInt, Computed: true, @@ -797,6 +793,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema { Schema: vinsComputeSchemaMake(), }, }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, "default_gw": { Type: schema.TypeString, Computed: true, @@ -808,6 +812,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema { Schema: qosSchemaMake(), }, }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, "desc": { Type: schema.TypeString, Computed: true, @@ -874,6 +886,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, "user_managed": { Type: schema.TypeBool, Computed: true, diff --git a/internal/service/cloudapi/vins/data_source_vins_audits.go b/internal/service/cloudapi/vins/data_source_vins_audits.go index 2ba379e..6d870dd 100644 --- a/internal/service/cloudapi/vins/data_source_vins_audits.go +++ b/internal/service/cloudapi/vins/data_source_vins_audits.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, diff --git a/internal/service/cloudapi/vins/data_source_vins_ext_net_list.go b/internal/service/cloudapi/vins/data_source_vins_ext_net_list.go index d68a580..6f3fa22 100644 --- a/internal/service/cloudapi/vins/data_source_vins_ext_net_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_ext_net_list.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -49,7 +49,7 @@ func dataSourceVinsExtNetListRead(ctx context.Context, d *schema.ResourceData, m id := uuid.New() d.SetId(id.String()) d.Set("items", flattenVinsExtNetList(extNetList)) - + d.Set("entry_count", extNetList.EntryCount) return nil } @@ -92,6 +92,10 @@ func DataSourceVinsExtNetListchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return rets } diff --git a/internal/service/cloudapi/vins/data_source_vins_ip_list.go b/internal/service/cloudapi/vins/data_source_vins_ip_list.go index 167ca7a..554656e 100644 --- a/internal/service/cloudapi/vins/data_source_vins_ip_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_ip_list.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -49,7 +49,7 @@ func dataSourceVinsIpListRead(ctx context.Context, d *schema.ResourceData, m int id := uuid.New() d.SetId(id.String()) d.Set("items", flattenVinsIpList(ips)) - + d.Set("entry_count", ips.EntryCount) return nil } @@ -96,6 +96,10 @@ func DataSourceVinsIpListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return rets } diff --git a/internal/service/cloudapi/vins/data_source_vins_list.go b/internal/service/cloudapi/vins/data_source_vins_list.go index 598d60c..526e631 100644 --- a/internal/service/cloudapi/vins/data_source_vins_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_list.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, diff --git a/internal/service/cloudapi/vins/data_source_vins_list_deleted.go b/internal/service/cloudapi/vins/data_source_vins_list_deleted.go index 1b4b112..d240d3a 100644 --- a/internal/service/cloudapi/vins/data_source_vins_list_deleted.go +++ b/internal/service/cloudapi/vins/data_source_vins_list_deleted.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, diff --git a/internal/service/cloudapi/vins/data_source_vins_nat_rule_list.go b/internal/service/cloudapi/vins/data_source_vins_nat_rule_list.go index eb93700..16211a5 100644 --- a/internal/service/cloudapi/vins/data_source_vins_nat_rule_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_nat_rule_list.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -49,6 +49,8 @@ func dataSourceVinsNatRuleListRead(ctx context.Context, d *schema.ResourceData, id := uuid.New() d.SetId(id.String()) d.Set("items", flattenVinsNatRuleList(natRules)) + d.Set("entry_count", natRules.EntryCount) + return nil } @@ -99,6 +101,10 @@ func DataSourceVinsNatRuleListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return rets } diff --git a/internal/service/cloudapi/vins/flattens.go b/internal/service/cloudapi/vins/flattens.go index 7fb545f..b6afe6b 100644 --- a/internal/service/cloudapi/vins/flattens.go +++ b/internal/service/cloudapi/vins/flattens.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -49,7 +49,7 @@ func flattenMGMT(mgmt vins.RecordMGMT) []map[string]interface{} { return res } -func flattenResources(resources *vins.RecordResources) []map[string]interface{} { +func flattenResources(resources vins.RecordResources) []map[string]interface{} { res := make([]map[string]interface{}, 0) temp := map[string]interface{}{ "cpu": resources.CPU, @@ -65,7 +65,7 @@ func flattenConfig(config vins.RecordVNFConfig) []map[string]interface{} { res := make([]map[string]interface{}, 0) temp := map[string]interface{}{ "mgmt": flattenMGMT(config.MGMT), - "resources": flattenResources(&config.Resources), + "resources": flattenResources(config.Resources), } res = append(res, temp) return res @@ -84,8 +84,7 @@ func flattenQOS(qos vins.QOS) []map[string]interface{} { } func flattenInterfaces(interfaces []vins.ItemVNFInterface) []map[string]interface{} { - res := make([]map[string]interface{}, 0) - + res := make([]map[string]interface{}, 0, len(interfaces)) for _, vnfInterface := range interfaces { temp := map[string]interface{}{ "conn_id": vnfInterface.ConnID, @@ -141,7 +140,7 @@ func flattenVNFDev(vnfDev vins.RecordVNFDev) []map[string]interface{} { } func flattenComputes(computes vins.ListVINSComputes) []map[string]interface{} { - res := make([]map[string]interface{}, 0) + res := make([]map[string]interface{}, 0, len(computes)) for _, compute := range computes { temp := map[string]interface{}{ "compute_id": compute.ID, @@ -154,7 +153,7 @@ func flattenComputes(computes vins.ListVINSComputes) []map[string]interface{} { } func flattenReservations(reservations vins.ListReservations) []map[string]interface{} { - res := make([]map[string]interface{}, 0) + res := make([]map[string]interface{}, 0, len(reservations)) for _, reservation := range reservations { temp := map[string]interface{}{ "client_type": reservation.ClientType, @@ -275,9 +274,9 @@ func flattenGW(gw vins.RecordGW) []map[string]interface{} { return res } -func flattenRules(rules vins.ListNATRules) []map[string]interface{} { - res := make([]map[string]interface{}, 0) - for _, rule := range rules.Data { +func flattenRules(rules vins.ListNATRulesConfig) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(rules)) + for _, rule := range rules { tmp := map[string]interface{}{ "rule_id": rule.ID, "local_ip": rule.LocalIP, @@ -343,9 +342,9 @@ func flattenVNFS(vnfs vins.RecordVNFs) []map[string]interface{} { return res } -func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} { - res := make([]map[string]interface{}, 0) - for _, rule := range rules.Data { +func flattenRuleBlock(rules vins.ListNATRulesConfig) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(rules)) + for _, rule := range rules { tmp := map[string]interface{}{ "int_ip": rule.LocalIP, "int_port": rule.LocalPort, @@ -359,15 +358,18 @@ func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} { return res } -func flattenVins(d *schema.ResourceData, vins vins.RecordVINS) { +func flattenVins(d *schema.ResourceData, vins *vins.RecordVINS) { d.Set("vins_id", vins.ID) d.Set("vnf_dev", flattenVNFDev(vins.VNFDev)) - d.Set("_ckey", vins.CKey) d.Set("account_id", vins.AccountID) d.Set("account_name", vins.AccountName) d.Set("computes", flattenComputes(vins.Computes)) + d.Set("created_by", vins.CreatedBy) + d.Set("created_time", vins.CreatedTime) d.Set("default_gw", vins.DefaultGW) d.Set("default_qos", flattenQOS(vins.DefaultQOS)) + d.Set("deleted_by", vins.DeletedBy) + d.Set("deleted_time", vins.DeletedTime) d.Set("desc", vins.Description) d.Set("gid", vins.GID) d.Set("guid", vins.GUID) @@ -384,21 +386,26 @@ func flattenVins(d *schema.ResourceData, vins vins.RecordVINS) { d.Set("rg_name", vins.RGName) d.Set("sec_vnf_dev_id", vins.SecVNFDevID) d.Set("status", vins.Status) + d.Set("updated_by", vins.UpdatedBy) + d.Set("updated_time", vins.UpdatedTime) d.Set("user_managed", vins.UserManaged) d.Set("vnfs", flattenVNFS(vins.VNFs)) d.Set("vxlan_id", vins.VXLANID) d.Set("nat_rule", flattenRuleBlock(vins.VNFs.NAT.Config.Rules)) } -func flattenVinsData(d *schema.ResourceData, vins vins.RecordVINS) { +func flattenVinsData(d *schema.ResourceData, vins *vins.RecordVINS) { d.Set("vins_id", vins.ID) d.Set("vnf_dev", flattenVNFDev(vins.VNFDev)) - d.Set("_ckey", vins.CKey) d.Set("account_id", vins.AccountID) d.Set("account_name", vins.AccountName) d.Set("computes", flattenComputes(vins.Computes)) + d.Set("created_by", vins.CreatedBy) + d.Set("created_time", vins.CreatedTime) d.Set("default_gw", vins.DefaultGW) d.Set("default_qos", flattenQOS(vins.DefaultQOS)) + d.Set("deleted_by", vins.DeletedBy) + d.Set("deleted_time", vins.DeletedTime) d.Set("desc", vins.Description) d.Set("gid", vins.GID) d.Set("guid", vins.GUID) @@ -415,14 +422,16 @@ func flattenVinsData(d *schema.ResourceData, vins vins.RecordVINS) { d.Set("rg_name", vins.RGName) d.Set("sec_vnf_dev_id", vins.SecVNFDevID) d.Set("status", vins.Status) + d.Set("updated_by", vins.UpdatedBy) + d.Set("updated_time", vins.UpdatedTime) d.Set("user_managed", vins.UserManaged) d.Set("vnfs", flattenVNFS(vins.VNFs)) d.Set("vxlan_id", vins.VXLANID) } -func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} { - res := make([]map[string]interface{}, 0) - for _, audit := range auidts { +func flattenVinsAudits(audits vins.ListAudits) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(audits)) + for _, audit := range audits { temp := map[string]interface{}{ "call": audit.Call, "response_time": audit.ResponseTime, @@ -437,7 +446,7 @@ func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} { } func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{} { - res := make([]map[string]interface{}, 0) + res := make([]map[string]interface{}, 0, len(extNetList.Data)) for _, extNet := range extNetList.Data { temp := map[string]interface{}{ "default_gw": extNet.DefaultGW, @@ -454,7 +463,7 @@ func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{ } func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} { - res := make([]map[string]interface{}, 0) + res := make([]map[string]interface{}, 0, len(ips.Data)) for _, ip := range ips.Data { temp := map[string]interface{}{ "client_type": ip.ClientType, @@ -472,7 +481,7 @@ func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} { } func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} { - res := make([]map[string]interface{}, 0) + res := make([]map[string]interface{}, 0, len(vl.Data)) for _, v := range vl.Data { temp := map[string]interface{}{ "account_id": v.AccountID, @@ -498,7 +507,7 @@ func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} { } func flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} { - res := make([]map[string]interface{}, 0) + res := make([]map[string]interface{}, 0, len(natRules.Data)) for _, natRule := range natRules.Data { temp := map[string]interface{}{ "id": natRule.ID, diff --git a/internal/service/cloudapi/vins/resource_vins.go b/internal/service/cloudapi/vins/resource_vins.go index 83ff2c9..61fe8a5 100644 --- a/internal/service/cloudapi/vins/resource_vins.go +++ b/internal/service/cloudapi/vins/resource_vins.go @@ -129,8 +129,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface if desc, ok := d.GetOk("desc"); ok { req.Description = desc.(string) } - req.PreReservationsNum = uint(d.Get("pre_reservations_num").(int)) - + if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok { + req.PreReservationsNum = uint64(preReservationsNum.(int)) + } + id, err := c.CloudAPI().VINS().CreateInRG(ctx, req) if err != nil { return diag.FromErr(err) @@ -141,7 +143,6 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface req := vins.CreateInAccountRequest{ Name: d.Get("name").(string), AccountID: uint64(accountId.(int)), - PreReservationsNum: uint64(d.Get("pre_reservations_num").(int)), } if gid, ok := d.GetOk("gid"); ok { @@ -153,7 +154,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface if desc, ok := d.GetOk("desc"); ok { req.Description = desc.(string) } - + if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok { + req.PreReservationsNum = uint64(preReservationsNum.(int)) + } + id, err := c.CloudAPI().VINS().CreateInAccount(ctx, req) if err != nil { return diag.FromErr(err) @@ -214,15 +218,15 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface } } - defer resourceVinsRead(ctx, d, m) - return warnings.Get() + + return append(warnings.Get(), resourceVinsRead(ctx, d, m)...) } func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*controller.ControllerCfg) warnings := dc.Warnings{} - vinsData, err := utilityVinsCheckPresence(ctx, d, m) + vinsData, err := utilityDataVinsCheckPresence(ctx, d, m) if err != nil { d.SetId("") return diag.FromErr(err) @@ -282,14 +286,14 @@ func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{} } if hasChangeState { - vinsData, err = utilityVinsCheckPresence(ctx, d, m) + vinsData, err = utilityDataVinsCheckPresence(ctx, d, m) if err != nil { d.SetId("") return diag.FromErr(err) } } - flattenVins(d, *vinsData) + flattenVins(d, vinsData) return warnings.Get() } @@ -366,7 +370,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface } } - vinsData, err := utilityVinsCheckPresence(ctx, d, m) + vinsData, err := utilityDataVinsCheckPresence(ctx, d, m) if err != nil { d.SetId("") return diag.FromErr(err) @@ -425,7 +429,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface } if hasChangeState { - vinsData, err = utilityVinsCheckPresence(ctx, d, m) + vinsData, err = utilityDataVinsCheckPresence(ctx, d, m) if err != nil { d.SetId("") return diag.FromErr(err) @@ -631,8 +635,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface } } - defer resourceVinsRead(ctx, d, m) - return warnings.Get() + return append (warnings.Get(), resourceVinsRead(ctx, d, m)...) } func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { @@ -658,7 +661,7 @@ func extNetSchemaMake() map[string]*schema.Schema { return map[string]*schema.Schema{ "ext_net_id": { Type: schema.TypeInt, - Default: 0, + Default: -1, Optional: true, }, "ext_net_ip": { @@ -674,6 +677,7 @@ func ipSchemaMake() map[string]*schema.Schema { "type": { Type: schema.TypeString, Required: true, + ValidateFunc: validation.StringInSlice([]string {"DHCP", "VIP", "EXCLUDE"}, false), }, "ip_addr": { Type: schema.TypeString, @@ -823,7 +827,6 @@ func resourceVinsSchemaMake() map[string]*schema.Schema { Optional: true, Default: false, } - rets["vins_id"] = &schema.Schema{ Type: schema.TypeInt, Computed: true, diff --git a/internal/service/cloudapi/vins/utility_vins.go b/internal/service/cloudapi/vins/utility_vins.go index 3f82826..575d932 100644 --- a/internal/service/cloudapi/vins/utility_vins.go +++ b/internal/service/cloudapi/vins/utility_vins.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -44,23 +44,13 @@ import ( func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) { c := m.(*controller.ControllerCfg) - req := vins.GetRequest{ - VINSID: uint64(d.Get("vins_id").(int)), - } + req := vins.GetRequest{} - vins, err := c.CloudAPI().VINS().Get(ctx, req) - if err != nil { - return nil, err - } - - return vins, nil -} - -func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) { - c := m.(*controller.ControllerCfg) - vinsId, _ := strconv.ParseUint(d.Id(), 10, 64) - req := vins.GetRequest{ - VINSID: vinsId, + if d.Id() != "" { + rgId, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = rgId + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) } vins, err := c.CloudAPI().VINS().Get(ctx, req) @@ -70,3 +60,4 @@ func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m int return vins, nil } + diff --git a/internal/service/cloudapi/vins/utility_vins_audits.go b/internal/service/cloudapi/vins/utility_vins_audits.go index a12d733..15d9418 100644 --- a/internal/service/cloudapi/vins/utility_vins_audits.go +++ b/internal/service/cloudapi/vins/utility_vins_audits.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -34,6 +34,7 @@ package vins import ( "context" + "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins" @@ -42,8 +43,13 @@ import ( func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListAudits, error) { c := m.(*controller.ControllerCfg) - req := vins.AuditsRequest{ - VINSID: uint64(d.Get("vins_id").(int)), + req := vins.AuditsRequest{} + + if d.Id() != "" { + rgId, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = rgId + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) } audits, err := c.CloudAPI().VINS().Audits(ctx, req) diff --git a/internal/service/cloudapi/vins/utility_vins_ext_net_list.go b/internal/service/cloudapi/vins/utility_vins_ext_net_list.go index fe210e2..b57ce12 100644 --- a/internal/service/cloudapi/vins/utility_vins_ext_net_list.go +++ b/internal/service/cloudapi/vins/utility_vins_ext_net_list.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -34,6 +34,7 @@ package vins import ( "context" + "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins" @@ -46,6 +47,13 @@ func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceD VINSID: uint64(d.Get("vins_id").(int)), } + if d.Id() != "" { + rgId, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = rgId + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) + } + extNetList, err := c.CloudAPI().VINS().ExtNetList(ctx, req) if err != nil { return nil, err diff --git a/internal/service/cloudapi/vins/utility_vins_ip_list.go b/internal/service/cloudapi/vins/utility_vins_ip_list.go index c7f24af..997c8ad 100644 --- a/internal/service/cloudapi/vins/utility_vins_ip_list.go +++ b/internal/service/cloudapi/vins/utility_vins_ip_list.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -34,6 +34,7 @@ package vins import ( "context" + "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins" @@ -42,8 +43,13 @@ import ( func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListIPs, error) { c := m.(*controller.ControllerCfg) - req := vins.IPListRequest{ - VINSID: uint64(d.Get("vins_id").(int)), + req := vins.IPListRequest{} + + if d.Id() != "" { + rgId, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = rgId + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) } ips, err := c.CloudAPI().VINS().IPList(ctx, req) diff --git a/internal/service/cloudapi/vins/utility_vins_list.go b/internal/service/cloudapi/vins/utility_vins_list.go index 67804ef..92af2b4 100644 --- a/internal/service/cloudapi/vins/utility_vins_list.go +++ b/internal/service/cloudapi/vins/utility_vins_list.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, diff --git a/internal/service/cloudapi/vins/utility_vins_list_deleted.go b/internal/service/cloudapi/vins/utility_vins_list_deleted.go index 3554c2c..520cb0a 100644 --- a/internal/service/cloudapi/vins/utility_vins_list_deleted.go +++ b/internal/service/cloudapi/vins/utility_vins_list_deleted.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, diff --git a/internal/service/cloudapi/vins/utility_vins_nat_rule_list.go b/internal/service/cloudapi/vins/utility_vins_nat_rule_list.go index b6fb116..5027591 100644 --- a/internal/service/cloudapi/vins/utility_vins_nat_rule_list.go +++ b/internal/service/cloudapi/vins/utility_vins_nat_rule_list.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, @@ -34,6 +34,7 @@ package vins import ( "context" + "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins" @@ -42,8 +43,13 @@ import ( func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListNATRules, error) { c := m.(*controller.ControllerCfg) - req := vins.NATRuleListRequest{ - VINSID: uint64(d.Get("vins_id").(int)), + req := vins.NATRuleListRequest{} + + if d.Id() != "" { + rgId, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = rgId + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) } natRuleList, err := c.CloudAPI().VINS().NATRuleList(ctx, req)