4.5.0-alpha
This commit is contained in:
@@ -56,7 +56,7 @@ func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
|
||||
func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"net_id": {
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
@@ -116,10 +116,6 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ipcidr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -198,6 +194,10 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"domain_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -50,14 +50,14 @@ func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
d.Set("net_id", extnetId)
|
||||
d.Set("extnet_id", extnetId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"net_id": {
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func dataSourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRoute, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(staticRoute.ID, 10))
|
||||
flattenStaticRouteData(d, staticRoute)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaticRouteSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the ExtNet",
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the static route",
|
||||
},
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
func DataSourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func dataSourceStaticRouteListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRouteList, err := utilityStaticRouteListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenStaticRouteList(staticRouteList))
|
||||
d.Set("entry_count", staticRouteList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaticRouteListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of ExtNet",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceStaticRouteList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -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, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -46,6 +46,7 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
|
||||
"ckey": item.CKey,
|
||||
"meta": flattens.FlattenMeta(item.Meta),
|
||||
"default": item.Default,
|
||||
"default_qos": flattenExtnetDefaultQos(item.DefaultQOS),
|
||||
"desc": item.Description,
|
||||
"free_ips": item.FreeIPs,
|
||||
"gid": item.GID,
|
||||
@@ -62,6 +63,7 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
|
||||
"status": item.Status,
|
||||
"vlan_id": item.VLANID,
|
||||
"check_ips": item.CheckIPs,
|
||||
"vnfs": flattenExtnetVNFS(item.VNFs),
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
@@ -73,7 +75,6 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
|
||||
func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) {
|
||||
d.Set("ckey", recNet.CKey)
|
||||
d.Set("meta", flattens.FlattenMeta(recNet.Meta))
|
||||
|
||||
d.Set("default", recNet.Default)
|
||||
d.Set("desc", recNet.Description)
|
||||
d.Set("free_ips", recNet.FreeIPs)
|
||||
@@ -96,17 +97,49 @@ func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) {
|
||||
d.Set("gateway", recNet.Gateway)
|
||||
d.Set("network", recNet.Network)
|
||||
d.Set("prefix", recNet.Prefix)
|
||||
|
||||
d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS))
|
||||
d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs))
|
||||
d.Set("reservations", flattenExtnetReservations(recNet.Reservations))
|
||||
}
|
||||
|
||||
func flattenRecordExtnetResource(d *schema.ResourceData, recNet *extnet.RecordExtNet, staticRouteList *extnet.ListStaticRoutes) {
|
||||
d.Set("ckey", recNet.CKey)
|
||||
d.Set("meta", flattens.FlattenMeta(recNet.Meta))
|
||||
d.Set("default", recNet.Default)
|
||||
d.Set("desc", recNet.Description)
|
||||
d.Set("free_ips", recNet.FreeIPs)
|
||||
d.Set("gid", recNet.GID)
|
||||
d.Set("guid", recNet.GUID)
|
||||
d.Set("extnet_id", recNet.ID)
|
||||
d.Set("ipcidr", recNet.IPCIDR)
|
||||
d.Set("milestones", recNet.Milestones)
|
||||
d.Set("name", recNet.Name)
|
||||
d.Set("network_id", recNet.NetworkID)
|
||||
d.Set("ovs_bridge", recNet.OVSBridge)
|
||||
d.Set("pre_reservations_num", recNet.PreReservationsNum)
|
||||
d.Set("pri_vnfdev_id", recNet.PriVNFDevID)
|
||||
d.Set("shared_with", recNet.SharedWith)
|
||||
d.Set("status", recNet.Status)
|
||||
d.Set("vlan_id", recNet.VLANID)
|
||||
d.Set("check_ips", recNet.CheckIPs)
|
||||
d.Set("dns", recNet.DNS)
|
||||
d.Set("excluded", flattenExtnetExcluded(recNet.Excluded))
|
||||
d.Set("gateway", recNet.Gateway)
|
||||
d.Set("network", recNet.Network)
|
||||
d.Set("prefix", recNet.Prefix)
|
||||
d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS))
|
||||
d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs))
|
||||
d.Set("reservations", flattenExtnetReservations(recNet.Reservations))
|
||||
d.Set("routes", flattenStaticRouteList(staticRouteList))
|
||||
}
|
||||
|
||||
|
||||
func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, er := range ers {
|
||||
temp := map[string]interface{}{
|
||||
"client_type": er.ClientType,
|
||||
"desc": er.Description,
|
||||
"domain_name": er.DomainName,
|
||||
"hostname": er.Hostname,
|
||||
"ip": er.IP,
|
||||
@@ -159,3 +192,29 @@ func flattenExtnetDefaultQos(edqos extnet.QOS) []map[string]interface{} {
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStaticRouteList(sr *extnet.ListStaticRoutes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(sr.Data))
|
||||
for _, staticRoute := range sr.Data {
|
||||
temp := map[string]interface{}{
|
||||
"route_id": staticRoute.ID,
|
||||
"destination": staticRoute.Destination,
|
||||
"gateway": staticRoute.Gateway,
|
||||
"guid": staticRoute.GUID,
|
||||
"netmask": staticRoute.Netmask,
|
||||
"compute_ids": staticRoute.ComputeIds,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStaticRouteData(d *schema.ResourceData, route *extnet.ItemRoutes) {
|
||||
d.Set("destination", route.Destination)
|
||||
d.Set("gateway", route.Gateway)
|
||||
d.Set("guid", route.GUID)
|
||||
d.Set("netmask", route.Netmask)
|
||||
d.Set("compute_ids", route.ComputeIds)
|
||||
d.Set("route_id", route.ID)
|
||||
}
|
||||
@@ -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, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -43,12 +43,17 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
|
||||
)
|
||||
|
||||
func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("cloudbroker: resourceExtnetCreate called with name '%s'", d.Get("name").(string))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
if err := ic.ExistGID(ctx, uint64(d.Get("gid").(int)), c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := extnet.CreateRequest{
|
||||
Name: d.Get("name").(string),
|
||||
GID: uint64(d.Get("gid").(int)),
|
||||
@@ -122,6 +127,7 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(netID, 10))
|
||||
d.Set("extnet_id", netID)
|
||||
log.Debugf("cloudbroker: Extnet with id %d successfully created on platform", netID)
|
||||
|
||||
if d.Get("excluded_ips").(*schema.Set).Len() > 0 {
|
||||
@@ -163,8 +169,12 @@ func resourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
staticRouteList, err := utilityStaticRouteListInResourceCheckPresence(ctx, m, recNet.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenRecordExtnet(d, recNet)
|
||||
flattenRecordExtnetResource(d, recNet, staticRouteList)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -219,6 +229,35 @@ func resourceExtnetUpdate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("excluded_ips_range") {
|
||||
if err := handleExcludedIPsRangeUpdate(ctx, d, c, recNet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("shared_with") {
|
||||
if err := handleSharedWithUpdate(ctx, d, c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("virtual") {
|
||||
if err := handleVirtualUpdate(ctx, d, c, recNet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("restart") {
|
||||
if err := handleRestartUpdate(ctx, d, c, recNet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
if d.HasChange("migrate") {
|
||||
if err := handleMigrateUpdate(ctx, d, c, recNet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceExtnetRead(ctx, d, m)
|
||||
}
|
||||
|
||||
@@ -253,13 +292,13 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
"ipcidr": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
// ForceNew: true,
|
||||
Description: "IP network CIDR",
|
||||
},
|
||||
"vlan_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
// ForceNew: true,
|
||||
Description: "VLAN ID",
|
||||
},
|
||||
"gateway": {
|
||||
@@ -352,6 +391,23 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
Description: "IPs to exclude in current extnet pool",
|
||||
},
|
||||
"excluded_ips_range": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"ip_start": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"ip_end": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Description: "Range of IPs to exclude in current extnet pool",
|
||||
},
|
||||
"default_qos": {
|
||||
Type: schema.TypeList,
|
||||
MaxItems: 1,
|
||||
@@ -381,6 +437,15 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"restart":{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "restart extnet vnf device",
|
||||
},
|
||||
"migrate":{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -488,6 +553,41 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"reservations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
@@ -540,6 +640,10 @@ func ResourceExtnetCB() *schema.Resource {
|
||||
UpdateContext: resourceExtnetUpdate,
|
||||
DeleteContext: resourceExtnetDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout300s,
|
||||
Create: &constants.Timeout300s,
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func resourceStaticRouteCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
if err := ic.ExistExtNet(ctx, uint64(d.Get("extnet_id").(int)), c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := extnet.StaticRouteAddRequest{
|
||||
ExtNetId: uint64(d.Get("extnet_id").(int)),
|
||||
Destination: d.Get("destination").(string),
|
||||
Netmask: d.Get("netmask").(string),
|
||||
Gateway: d.Get("gateway").(string),
|
||||
}
|
||||
|
||||
if computesIDS, ok := d.GetOk("compute_ids"); ok {
|
||||
ids := computesIDS.([]interface{})
|
||||
|
||||
res := make([]uint64, 0, len (ids))
|
||||
|
||||
for _, id := range ids {
|
||||
computeId := uint64(id.(int))
|
||||
res = append(res, computeId)
|
||||
}
|
||||
|
||||
req.ComputeIds = res
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().StaticRouteAdd(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
staticRouteData, err := getStaticRouteData(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(fmt.Sprintf("%d#%d", req.ExtNetId, staticRouteData.ID))
|
||||
|
||||
return resourceStaticRouteRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenStaticRouteData(d, staticRouteData)
|
||||
|
||||
return warnings.Get()
|
||||
}
|
||||
|
||||
func resourceStaticRouteUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
if err := ic.ExistExtNet(ctx, uint64(d.Get("extnet_id").(int)), c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if d.HasChange("compute_ids") {
|
||||
deletedIds := make([]uint64, 0)
|
||||
addedIds := make([]uint64, 0)
|
||||
|
||||
oldComputeIds, newComputeIds := d.GetChange("compute_ids")
|
||||
oldComputeIdsSlice := oldComputeIds.([]interface{})
|
||||
newComputeIdsSlice := newComputeIds.([]interface{})
|
||||
|
||||
for _, el := range oldComputeIdsSlice {
|
||||
if !isContainsIds(newComputeIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
deletedIds = append(deletedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newComputeIdsSlice {
|
||||
if !isContainsIds(oldComputeIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
addedIds = append(addedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedIds) > 0 {
|
||||
req := extnet.StaticRouteAccessRevokeRequest{
|
||||
ExtNetID: uint64(d.Get("extnet_id").(int)),
|
||||
RouteId: staticRouteData.ID,
|
||||
ComputeIds: deletedIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().StaticRouteAccessRevoke(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedIds) > 0 {
|
||||
req := extnet.StaticRouteAccessGrantRequest{
|
||||
ExtNetID: uint64(d.Get("extnet_id").(int)),
|
||||
RouteId: staticRouteData.ID,
|
||||
ComputeIds: addedIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().StaticRouteAccessGrant(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceStaticRouteRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceStaticRouteDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteDelRequest{}
|
||||
|
||||
arr := strings.Split(d.Id(), "#")
|
||||
if len(arr) != 2 {
|
||||
return diag.Errorf("broken state id - %s", d.Id())
|
||||
}
|
||||
|
||||
req.ExtNetID, _ = strconv.ParseUint(arr[0], 10, 64)
|
||||
req.RouteId, _ = strconv.ParseUint(arr[1], 10, 64)
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().StaticRouteDel(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceStaticRouteSchemaMake() map[string]*schema.Schema {
|
||||
rets := dataSourceStaticRouteSchemaMake()
|
||||
rets["route_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
}
|
||||
rets["compute_ids"] = &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
}
|
||||
rets["destination"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
rets["gateway"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
rets["netmask"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func isContainsIds(els []interface{}, el interface{}) bool {
|
||||
convEl := el.(int)
|
||||
for _, elOld := range els {
|
||||
if convEl == elOld.(int) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ResourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceStaticRouteCreate,
|
||||
ReadContext: resourceStaticRouteRead,
|
||||
UpdateContext: resourceStaticRouteUpdate,
|
||||
DeleteContext: resourceStaticRouteDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout20m,
|
||||
Read: &constants.Timeout600s,
|
||||
Update: &constants.Timeout20m,
|
||||
Delete: &constants.Timeout600s,
|
||||
Default: &constants.Timeout600s,
|
||||
},
|
||||
|
||||
Schema: resourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -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, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -38,245 +38,20 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
)
|
||||
|
||||
func handleExcludedIPsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
old_set, new_set := d.GetChange("excluded_ips")
|
||||
|
||||
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
|
||||
if detach_set.Len() > 0 {
|
||||
ips := make([]string, 0)
|
||||
for _, detach_ip := range detach_set.List() {
|
||||
ips = append(ips, detach_ip.(string))
|
||||
}
|
||||
|
||||
log.Debugf("cloudbroker: removing %d IP address(es) from excluded list", detach_set.Len())
|
||||
req := extnet.IPsIncludeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPs: ips,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsInclude(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
if attach_set.Len() > 0 {
|
||||
ips := make([]string, 0)
|
||||
for _, attach_ip := range attach_set.List() {
|
||||
ips = append(ips, attach_ip.(string))
|
||||
}
|
||||
|
||||
log.Debugf("cloudbroker: excluding %d IP address(es) from extnet with id %d", attach_set.Len(), recNet.ID)
|
||||
req := extnet.IPsExcludeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPs: ips,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSetDefault(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
set_default := d.Get("set_default").(bool)
|
||||
if set_default && recNet.Default == false {
|
||||
req := extnet.SetDefaultRequest{
|
||||
NetID: recNet.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().SetDefault(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
doBasicUpdate := false
|
||||
basiUpdateReq := extnet.UpdateRequest{NetID: recNet.ID}
|
||||
|
||||
if d.HasChange("name") {
|
||||
basiUpdateReq.Name = d.Get("name").(string)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
if d.HasChange("desc") {
|
||||
basiUpdateReq.Description = d.Get("desc").(string)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
|
||||
if doBasicUpdate {
|
||||
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
enable := d.Get("enable").(bool)
|
||||
if enable {
|
||||
if recNet.Status == status.Disabled {
|
||||
req := extnet.EnableRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().Enable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if recNet.Status == status.Enabled {
|
||||
req := extnet.DisableRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().Disable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDefaultQOSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
qos := d.Get("default_qos").([]interface{})[0].(map[string]interface{})
|
||||
|
||||
req := extnet.DefaultQOSUpdateRequest{
|
||||
NetID: recNet.ID,
|
||||
IngressRate: uint64(qos["in_rate"].(int)),
|
||||
IngressBurst: uint64(qos["in_burst"].(int)),
|
||||
EgressRate: uint64(qos["e_rate"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DefaultQOSUpdate(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleNTPUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
changed_list := d.Get("ntp").([]interface{})
|
||||
|
||||
ntp_list := make([]string, 0)
|
||||
for _, ntp_address := range changed_list {
|
||||
ntp_list = append(ntp_list, ntp_address.(string))
|
||||
}
|
||||
|
||||
req := extnet.NTPApplyRequest{
|
||||
NetID: recNet.ID,
|
||||
NTPList: ntp_list,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().NTPApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDNSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
changed_list := d.Get("dns").([]interface{})
|
||||
|
||||
dns_list := make([]string, 0)
|
||||
for _, dns_address := range changed_list {
|
||||
dns_list = append(dns_list, dns_address.(string))
|
||||
}
|
||||
|
||||
req := extnet.DNSApplyRequest{
|
||||
NetID: recNet.ID,
|
||||
DNSList: dns_list,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DNSApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityExtnetDefaultCheckPresence(ctx context.Context, m interface{}) (uint64, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
return c.CloudBroker().ExtNet().GetDefault(ctx)
|
||||
}
|
||||
|
||||
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNet, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := extnet.ListRequest{}
|
||||
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(accountId.(int))
|
||||
}
|
||||
|
||||
if by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if network, ok := d.GetOk("network"); ok {
|
||||
req.Network = network.(string)
|
||||
}
|
||||
|
||||
if vlan_id, ok := d.GetOk("vlan_id"); ok {
|
||||
req.VLANID = uint64(vlan_id.(int))
|
||||
}
|
||||
|
||||
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
|
||||
req.VNFDevID = uint64(vnfdev_id.(int))
|
||||
}
|
||||
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(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))
|
||||
}
|
||||
|
||||
res, err := c.CloudBroker().ExtNet().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func utilityExtnetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.RecordExtNet, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
var netId uint64
|
||||
|
||||
if id, ok := d.GetOk("net_id"); ok {
|
||||
netId = uint64(id.(int))
|
||||
req := extnet.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
netId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.NetID = netId
|
||||
} else {
|
||||
parsed, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
netId = parsed
|
||||
}
|
||||
|
||||
req := extnet.GetRequest{
|
||||
NetID: netId,
|
||||
req.NetID = uint64(d.Get("extnet_id").(int))
|
||||
}
|
||||
|
||||
res, err := c.CloudBroker().ExtNet().Get(ctx, req)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
<<<<<<<< HEAD:internal/dc/utils.go
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
========
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
>>>>>>>> dev:internal/service/cloudbroker/extnet/utility_extnet_default.go
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
<<<<<<<< HEAD:internal/dc/utils.go
|
||||
Nikita Sorokin, <nesorokin@basistech.ru>
|
||||
========
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
>>>>>>>> dev:internal/service/cloudbroker/extnet/utility_extnet_default.go
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityExtnetDefaultCheckPresence(ctx context.Context, m interface{}) (uint64, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
return c.CloudBroker().ExtNet().GetDefault(ctx)
|
||||
}
|
||||
91
internal/service/cloudbroker/extnet/utility_extnet_list.go
Normal file
91
internal/service/cloudbroker/extnet/utility_extnet_list.go
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNet, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := extnet.ListRequest{}
|
||||
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(accountId.(int))
|
||||
}
|
||||
|
||||
if by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if network, ok := d.GetOk("network"); ok {
|
||||
req.Network = network.(string)
|
||||
}
|
||||
|
||||
if vlan_id, ok := d.GetOk("vlan_id"); ok {
|
||||
req.VLANID = uint64(vlan_id.(int))
|
||||
}
|
||||
|
||||
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
|
||||
req.VNFDevID = uint64(vnfdev_id.(int))
|
||||
}
|
||||
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(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))
|
||||
}
|
||||
|
||||
res, err := c.CloudBroker().ExtNet().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
360
internal/service/cloudbroker/extnet/utility_extnet_resource.go
Normal file
360
internal/service/cloudbroker/extnet/utility_extnet_resource.go
Normal file
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
)
|
||||
|
||||
func handleExcludedIPsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
old_set, new_set := d.GetChange("excluded_ips")
|
||||
|
||||
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
|
||||
if detach_set.Len() > 0 {
|
||||
ips := make([]string, 0)
|
||||
for _, detach_ip := range detach_set.List() {
|
||||
ips = append(ips, detach_ip.(string))
|
||||
}
|
||||
|
||||
log.Debugf("cloudbroker: removing %d IP address(es) from excluded list", detach_set.Len())
|
||||
req := extnet.IPsIncludeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPs: ips,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsInclude(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
if attach_set.Len() > 0 {
|
||||
ips := make([]string, 0)
|
||||
for _, attach_ip := range attach_set.List() {
|
||||
ips = append(ips, attach_ip.(string))
|
||||
}
|
||||
|
||||
log.Debugf("cloudbroker: excluding %d IP address(es) from extnet with id %d", attach_set.Len(), recNet.ID)
|
||||
req := extnet.IPsExcludeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPs: ips,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSetDefault(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
set_default := d.Get("set_default").(bool)
|
||||
if set_default && !recNet.Default {
|
||||
req := extnet.SetDefaultRequest{
|
||||
NetID: recNet.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().SetDefault(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
doBasicUpdate := false
|
||||
basiUpdateReq := extnet.UpdateRequest{NetID: recNet.ID}
|
||||
|
||||
if d.HasChange("name") {
|
||||
basiUpdateReq.Name = d.Get("name").(string)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
if d.HasChange("desc") {
|
||||
basiUpdateReq.Description = d.Get("desc").(string)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
|
||||
if doBasicUpdate {
|
||||
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
enable := d.Get("enable").(bool)
|
||||
if enable {
|
||||
if recNet.Status == status.Disabled {
|
||||
req := extnet.EnableRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().Enable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if recNet.Status == status.Enabled {
|
||||
req := extnet.DisableRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().Disable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDefaultQOSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
qos := d.Get("default_qos").([]interface{})[0].(map[string]interface{})
|
||||
|
||||
req := extnet.DefaultQOSUpdateRequest{
|
||||
NetID: recNet.ID,
|
||||
IngressRate: uint64(qos["in_rate"].(int)),
|
||||
IngressBurst: uint64(qos["in_burst"].(int)),
|
||||
EgressRate: uint64(qos["e_rate"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DefaultQOSUpdate(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleNTPUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
changed_list := d.Get("ntp").([]interface{})
|
||||
|
||||
ntp_list := make([]string, 0)
|
||||
for _, ntp_address := range changed_list {
|
||||
ntp_list = append(ntp_list, ntp_address.(string))
|
||||
}
|
||||
|
||||
req := extnet.NTPApplyRequest{
|
||||
NetID: recNet.ID,
|
||||
NTPList: ntp_list,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().NTPApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDNSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
changed_list := d.Get("dns").([]interface{})
|
||||
|
||||
dns_list := make([]string, 0)
|
||||
for _, dns_address := range changed_list {
|
||||
dns_list = append(dns_list, dns_address.(string))
|
||||
}
|
||||
|
||||
req := extnet.DNSApplyRequest{
|
||||
NetID: recNet.ID,
|
||||
DNSList: dns_list,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DNSApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleExcludedIPsRangeUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
old_set, new_set := d.GetChange("excluded_ips_range")
|
||||
|
||||
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
|
||||
if detach_set.Len() > 0 {
|
||||
for _, detach_ip_range := range detach_set.List() {
|
||||
|
||||
log.Debugf("cloudbroker: removing range of IP addreses from excluded range list")
|
||||
|
||||
req := extnet.IPsIncludeRangeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPStart: detach_ip_range.(map[string]interface{})["ip_start"].(string),
|
||||
IPEnd: detach_ip_range.(map[string]interface{})["ip_end"].(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsIncludeRange(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
if attach_set.Len() > 0 {
|
||||
for _, attach_ip_range := range attach_set.List() {
|
||||
|
||||
log.Debugf("cloudbroker: excluding range of IP addreses from excluded range list")
|
||||
|
||||
req := extnet.IPsExcludeRangeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPStart: attach_ip_range.(map[string]interface{})["ip_start"].(string),
|
||||
IPEnd: attach_ip_range.(map[string]interface{})["ip_end"].(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsExcludeRange(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSharedWithUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) error {
|
||||
deletedIds := make([]uint64, 0)
|
||||
addedIds := make([]uint64, 0)
|
||||
|
||||
oldAccountIds, newAccountIds := d.GetChange("shared_with")
|
||||
oldAccountIdsSlice := oldAccountIds.([]interface{})
|
||||
newAccountIdsSlice := newAccountIds.([]interface{})
|
||||
|
||||
for _, el := range oldAccountIdsSlice {
|
||||
if !isContainsIds(newAccountIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
deletedIds = append(deletedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newAccountIdsSlice {
|
||||
if !isContainsIds(oldAccountIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
addedIds = append(addedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedIds) > 0 {
|
||||
for _, accountId := range deletedIds {
|
||||
req := extnet.AccessRemoveRequest{
|
||||
NetID: uint64(d.Get("extnet_id").(int)),
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().AccessRemove(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedIds) > 0 {
|
||||
for _, accountId := range addedIds {
|
||||
req := extnet.AccessAddRequest{
|
||||
NetID: uint64(d.Get("extnet_id").(int)),
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().AccessAdd(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleVirtualUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
virtualOld, virtualNew := d.GetChange("virtual")
|
||||
|
||||
if virtualOld == false && virtualNew == true {
|
||||
req := extnet.DeviceRemoveRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().DeviceRemove(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
} else if virtualOld == true && virtualNew == false {
|
||||
req := extnet.DeviceDeployRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().DeviceDeploy(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleRestartUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
restartOld, restartNew := d.GetChange("restart")
|
||||
|
||||
if restartOld == false && restartNew == true {
|
||||
req := extnet.DeviceRestartRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().DeviceRestart(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleMigrateUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
stackId := uint64(d.Get("migrate").(int))
|
||||
|
||||
if err := ic.ExistStack(ctx, stackId, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := extnet.DeviceMigrateRequest{
|
||||
NetID: recNet.ID,
|
||||
StackID: stackId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DeviceMigrate(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityDataStaticRouteCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ItemRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteListRequest{}
|
||||
var routeId uint64
|
||||
|
||||
if d.Id() != "" {
|
||||
arr := strings.Split(d.Id(), "#")
|
||||
if len(arr) != 2 {
|
||||
return nil, fmt.Errorf("broken state id")
|
||||
}
|
||||
|
||||
req.ExtNetID, _ = strconv.ParseUint(arr[0], 10, 64)
|
||||
routeId, _ = strconv.ParseUint(arr[1], 10, 64)
|
||||
} else {
|
||||
req.ExtNetID = uint64(d.Get("extnet_id").(int))
|
||||
routeId = uint64(d.Get("route_id").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityStaticRouteCheckPresence, extnet id: %v", req.ExtNetID)
|
||||
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("utilityStaticRouteCheckPresence: ROUTE ID %v", routeId)
|
||||
|
||||
staticRoute := extnet.ItemRoutes{}
|
||||
for _, route := range staticRouteList.Data {
|
||||
if routeId == route.ID {
|
||||
staticRoute = route
|
||||
return &staticRoute, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("static route not found")
|
||||
}
|
||||
|
||||
func getStaticRouteData(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ItemRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteListRequest{}
|
||||
req.ExtNetID = uint64(d.Get("extnet_id").(int))
|
||||
|
||||
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
destination := d.Get("destination").(string)
|
||||
gateway := d.Get("gateway").(string)
|
||||
|
||||
staticRoute := extnet.ItemRoutes{}
|
||||
for _, route := range staticRouteList.Data {
|
||||
if destination == route.Destination && gateway == route.Gateway {
|
||||
staticRoute = route
|
||||
return &staticRoute, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("static route not found")
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityStaticRouteListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListStaticRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteListRequest{}
|
||||
|
||||
req.ExtNetID = uint64(d.Get("extnet_id").(int))
|
||||
|
||||
log.Debugf("utilityStaticRouteListCheckPresence")
|
||||
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return staticRouteList, nil
|
||||
}
|
||||
|
||||
func utilityStaticRouteListInResourceCheckPresence(ctx context.Context, m interface{}, extnetId uint64) (*extnet.ListStaticRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteListRequest{
|
||||
ExtNetID: extnetId,
|
||||
}
|
||||
|
||||
log.Debugf("utilityStaticRouteListInResourceCheckPresence")
|
||||
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return staticRouteList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user