This commit is contained in:
2024-05-31 14:05:21 +03:00
parent 84b7a80e1b
commit db1760cb72
815 changed files with 58194 additions and 11049 deletions

View File

@@ -50,7 +50,7 @@ func dataSourceVinsListDeletedRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenVinsList(vinsList))
d.Set("items", flattenVinsListDeleted(vinsList))
d.Set("entry_count", vinsList.EntryCount)
return nil

View File

@@ -406,6 +406,7 @@ func flattenVinsListInterfaces(i vins.ListInterfaces) []map[string]interface{} {
"net_id": v.NetID,
"net_mask": v.NetMask,
"net_type": v.NetType,
"node_id": v.NodeID,
"pci_slot": v.PCISlot,
"qos": flattenVinsQOS(v.QOS),
"target": v.Target,
@@ -418,6 +419,50 @@ func flattenVinsListInterfaces(i vins.ListInterfaces) []map[string]interface{} {
}
func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(vl.Data))
for _, v := range vl.Data {
temp := map[string]interface{}{
"account_id": v.AccountID,
"account_name": v.AccountName,
"created_by": v.CreatedBy,
"created_time": v.CreatedTime,
"default_gw": v.DefaultGW,
"default_qos": flattenVinsQOS(v.DefaultQOS),
"deleted_by": v.DeletedBy,
"deleted_time": v.DeletedTime,
"description": v.Description,
"external_ip": v.ExternalIP,
"extnet_id": v.ExtnetId,
"free_ips": v.FreeIPs,
"gid": v.GID,
"guid": v.GUID,
"vins_id": v.ID,
"name": v.Name,
"lock_status": v.LockStatus,
"manager_id": v.ManagerID,
"manager_type": v.ManagerType,
"milestones": v.Milestones,
"netmask": v.NetMask,
"network": v.Network,
"pre_reservations_num": v.PreReservationsNum,
"pri_vnf_dev_id": v.PriVNFDevID,
"redundant": v.Redundant,
"rg_id": v.RGID,
"rg_name": v.RGName,
"sec_vnf_dev_id": v.SecVNFDevID,
"status": v.Status,
"updated_by": v.UpdatedBy,
"updated_time": v.UpdatedTime,
"user_managed": v.UserManaged,
"vnfs": flattenVinsVNFs(v.VNFs),
"vxlan_id": v.VXLANID,
}
res = append(res, temp)
}
return res
}
func flattenVinsListDeleted(vl *vins.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(vl.Data))
for _, v := range vl.Data {
temp := map[string]interface{}{

View File

@@ -34,6 +34,7 @@ package vins
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
@@ -77,6 +78,13 @@ func createVinsInAcc(ctx context.Context, d *schema.ResourceData, m interface{},
}
req.Routes = routes
}
if dns, ok := d.GetOk("dns"); ok {
dnsInterface := dns.(*schema.Set).List()
req.DNSList = make([]string, 0, len(dnsInterface))
for _, item := range dnsInterface {
req.DNSList = append(req.DNSList, item.(string))
}
}
return req, nil
}
@@ -123,6 +131,13 @@ func createVinsInRG(ctx context.Context, d *schema.ResourceData, m interface{},
}
req.Routes = routes
}
if dns, ok := d.GetOk("dns"); ok {
dnsInterface := dns.(*schema.Set).List()
req.DNSList = make([]string, 0, len(dnsInterface))
for _, item := range dnsInterface {
req.DNSList = append(req.DNSList, item.(string))
}
}
return req, nil
}

View File

@@ -284,6 +284,12 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.HasChange("dns") {
if err := resourceVinsChangeDNS(ctx, d, m); err != nil {
warnings.Add(err)
}
}
if d.HasChange("default_qos") {
if err := resourceVinsChangeDefaultQos(ctx, d, m); err != nil {
warnings.Add(err)
@@ -441,9 +447,12 @@ func resourceVinsNatRuleAdd(ctx context.Context, d *schema.ResourceData, m inter
req := vins.NATRuleAddRequest{
VINSID: vinsId,
IntIP: natRule["int_ip"].(string),
IntPort: uint64(natRule["int_port"].(int)),
ExtPortStart: uint64(natRule["ext_port_start"].(int)),
}
if intPort, ok := natRule["int_port"]; ok {
req.IntPort = uint64(intPort.(int))
}
if extPortEnd, ok := natRule["ext_port_end"]; ok {
req.ExtPortEnd = uint64(extPortEnd.(int))
}
@@ -646,10 +655,12 @@ func resourceVinsChangeNatRule(ctx context.Context, d *schema.ResourceData, m in
req := vins.NATRuleAddRequest{
VINSID: vinsId,
IntIP: natRule["int_ip"].(string),
IntPort: uint64(natRule["int_port"].(int)),
ExtPortStart: uint64(natRule["ext_port_start"].(int)),
}
if natRule["int_port"].(int) != 0 {
req.IntPort = uint64(natRule["int_port"].(int))
}
if natRule["ext_port_end"].(int) != 0 {
req.ExtPortEnd = uint64(natRule["ext_port_end"].(int))
}
@@ -667,6 +678,31 @@ func resourceVinsChangeNatRule(ctx context.Context, d *schema.ResourceData, m in
return errs
}
func resourceVinsChangeDNS(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
vinsId := uint64(d.Get("vins_id").(int))
// empty "dns" is allowed, it will update vnfs.dhcp.config.dns from current values to empty list
dnsInterface := d.Get("dns").(*schema.Set).List()
dnsList := make([]string, 0, len(dnsInterface))
for _, item := range dnsInterface {
dnsList = append(dnsList, item.(string))
}
req := vins.DNSApplyRequest{
VINSID: vinsId,
DNSList: dnsList,
}
_, err := c.CloudBroker().VINS().DNSApply(ctx, req)
if err != nil {
return err
}
return nil
}
func resourceVinsChangeDefaultQos(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)

View File

@@ -215,6 +215,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "net type",
},
"node_id": {
Type: schema.TypeInt,
Computed: true,
},
"pci_slot": {
Type: schema.TypeInt,
Computed: true,
@@ -1187,12 +1191,22 @@ func dataSourceVinsListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Find by ext ip",
},
"vnfdev_id": {
Type: schema.TypeInt,
Optional: true,
Description: "find by VNF Device id",
},
"include_deleted": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "include deleted computes",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -1268,6 +1282,14 @@ func dataSourceVinsListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"extnet_id": {
Type: schema.TypeInt,
Computed: true,
},
"free_ips": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
@@ -1423,6 +1445,11 @@ func dataSourceVinsListDeletedSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Filter by external IP",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -2025,7 +2052,8 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
},
"int_port": {
Type: schema.TypeInt,
Required: true,
Optional: true,
Computed: true,
},
"ext_port_start": {
Type: schema.TypeInt,
@@ -2103,6 +2131,13 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
},
},
},
"dns": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
// other resource fields
"vins_id": {
@@ -2309,6 +2344,10 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "net type",
},
"node_id": {
Type: schema.TypeInt,
Computed: true,
},
"pci_slot": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -1,80 +1,86 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package vins
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) {
c := m.(*controller.ControllerCfg)
req := vins.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if rgId, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rgId.(int))
}
if extIp, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = extIp.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if includeDeleted, ok := d.GetOk("include_deleted"); ok {
req.IncludeDeleted = includeDeleted.(bool)
}
log.Debugf("utilityVinsListCheckPresence")
vinsList, err := c.CloudBroker().VINS().List(ctx, req)
if err != nil {
return nil, err
}
return vinsList, nil
}
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package vins
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) {
c := m.(*controller.ControllerCfg)
req := vins.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if rgId, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rgId.(int))
}
if extIp, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = extIp.(string)
}
if VNFDevId, ok := d.GetOk("vnfdev_id"); ok {
req.VNFDevID = uint64(VNFDevId.(int))
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if includeDeleted, ok := d.GetOk("include_deleted"); ok {
req.IncludeDeleted = includeDeleted.(bool)
}
log.Debugf("utilityVinsListCheckPresence")
vinsList, err := c.CloudBroker().VINS().List(ctx, req)
if err != nil {
return nil, err
}
return vinsList, nil
}

View File

@@ -60,6 +60,9 @@ func utilityVinsListDeletedCheckPresence(ctx context.Context, d *schema.Resource
if ext_ip, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = ext_ip.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}