This commit is contained in:
2026-06-19 17:43:58 +03:00
parent c734dcfff7
commit c00c608ce9
1307 changed files with 1 additions and 197134 deletions

View File

@@ -1,70 +0,0 @@
/*
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 lb
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 dataSourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lb, err := utilityLBCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(lb.ID, 10))
flattenLB(d, lb)
return nil
}
func DataSourceLB() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceLBRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dsLBSchemaMake(),
}
}

View File

@@ -1,72 +0,0 @@
/*
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 lb
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 dataSourceLBListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lbList, err := utilityLBListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenLBList(lbList))
d.Set("entry_count", lbList.EntryCount)
return nil
}
func DataSourceLBList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceLBListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dsLBListSchemaMake(),
}
}

View File

@@ -1,72 +0,0 @@
/*
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 lb
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 dataSourceLBListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lbList, err := utilityLBListDeletedCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenLBList(lbList))
d.Set("entry_count", lbList.EntryCount)
return nil
}
func DataSourceLBListDeleted() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceLBListDeletedRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dsLBListDeletedSchemaMake(),
}
}

View File

@@ -1,280 +0,0 @@
/*
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 lb
import (
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenLBFrontendBind(d *schema.ResourceData, b *lb.ItemBinding, lbId int64, frontendName string) {
d.Set("lb_id", lbId)
d.Set("frontend_name", frontendName)
d.Set("name", b.Name)
d.Set("address", b.Address)
d.Set("guid", b.GUID)
d.Set("port", b.Port)
}
func flattenLBFrontend(d *schema.ResourceData, f *lb.ItemFrontend, lbId int64) {
d.Set("lb_id", lbId)
d.Set("backend_name", f.Backend)
d.Set("name", f.Name)
d.Set("guid", f.GUID)
d.Set("bindings", flattendBindings(f.Bindings))
}
func flattenResourceLBBackendServer(d *schema.ResourceData, s *lb.ItemServer, lbId int64, backendName string) {
d.Set("lb_id", lbId)
d.Set("backend_name", backendName)
d.Set("name", s.Name)
d.Set("port", s.Port)
d.Set("address", s.Address)
d.Set("check", s.Check)
d.Set("guid", s.GUID)
d.Set("downinter", s.ServerSettings.DownInter)
d.Set("fall", s.ServerSettings.Fall)
d.Set("inter", s.ServerSettings.Inter)
d.Set("maxconn", s.ServerSettings.MaxConn)
d.Set("maxqueue", s.ServerSettings.MaxQueue)
d.Set("rise", s.ServerSettings.Rise)
d.Set("slowstart", s.ServerSettings.SlowStart)
d.Set("weight", s.ServerSettings.Weight)
}
func flattenResourceLBBackend(d *schema.ResourceData, b *lb.ItemBackend, lbId int64) {
d.Set("lb_id", lbId)
d.Set("name", b.Name)
d.Set("algorithm", b.Algorithm)
d.Set("guid", b.GUID)
d.Set("downinter", b.ServerDefaultSettings.DownInter)
d.Set("fall", b.ServerDefaultSettings.Fall)
d.Set("inter", b.ServerDefaultSettings.Inter)
d.Set("maxconn", b.ServerDefaultSettings.MaxConn)
d.Set("maxqueue", b.ServerDefaultSettings.MaxQueue)
d.Set("rise", b.ServerDefaultSettings.Rise)
d.Set("slowstart", b.ServerDefaultSettings.SlowStart)
d.Set("weight", b.ServerDefaultSettings.Weight)
d.Set("servers", flattenServers(b.Servers))
}
func flattenLB(d *schema.ResourceData, lb *lb.RecordLB) {
d.Set("account_id", lb.AccountID)
d.Set("ha_mode", lb.HAMode)
d.Set("ckey", lb.CKey)
d.Set("meta", flattens.FlattenMeta(lb.Meta))
d.Set("acl", flattenACl(lb.ACL))
d.Set("backend_haip", lb.BackendHAIP)
d.Set("backends", flattenLBBackends(lb.Backends))
d.Set("desc", lb.Description)
d.Set("dp_api_user", lb.DPAPIUser)
d.Set("dp_api_password", lb.DPAPIPassword)
d.Set("extnet_id", lb.ExtNetID)
d.Set("frontend_haip", lb.FrontendHAIP)
d.Set("frontends", flattenFrontends(lb.Frontends))
d.Set("gid", lb.GID)
d.Set("guid", lb.GUID)
d.Set("lb_id", lb.ID)
d.Set("manager_id", lb.ManagerId)
d.Set("manager_type", lb.ManagerType)
d.Set("image_id", lb.ImageID)
d.Set("milestones", lb.Milestones)
d.Set("name", lb.Name)
d.Set("part_k8s", lb.PartK8s)
d.Set("primary_node", flattenNode(lb.PrimaryNode))
d.Set("rg_id", lb.RGID)
d.Set("secondary_node", flattenNode(lb.SecondaryNode))
d.Set("status", lb.Status)
d.Set("tech_status", lb.TechStatus)
d.Set("user_managed", lb.UserManaged)
d.Set("vins_id", lb.VINSID)
d.Set("zone_id", lb.ZoneID)
}
func flattenNode(node lb.Node) []map[string]interface{} {
temp := make([]map[string]interface{}, 0)
n := map[string]interface{}{
"backend_ip": node.BackendIP,
"compute_id": node.ComputeID,
"frontend_ip": node.FrontendIP,
"guid": node.GUID,
"mgmt_ip": node.MGMTIP,
"network_id": node.NetworkID,
}
temp = append(temp, n)
return temp
}
func flattendBindings(bs []lb.ItemBinding) []map[string]interface{} {
temp := make([]map[string]interface{}, 0, len(bs))
for _, b := range bs {
t := map[string]interface{}{
"address": b.Address,
"guid": b.GUID,
"name": b.Name,
"port": b.Port,
}
temp = append(temp, t)
}
return temp
}
func flattenFrontends(fs []lb.ItemFrontend) []map[string]interface{} {
temp := make([]map[string]interface{}, 0, len(fs))
for _, f := range fs {
t := map[string]interface{}{
"backend": f.Backend,
"bindings": flattendBindings(f.Bindings),
"guid": f.GUID,
"name": f.Name,
}
temp = append(temp, t)
}
return temp
}
func flattenServers(servers []lb.ItemServer) []map[string]interface{} {
temp := make([]map[string]interface{}, 0, len(servers))
for _, server := range servers {
t := map[string]interface{}{
"address": server.Address,
"check": server.Check,
"guid": server.GUID,
"name": server.Name,
"port": server.Port,
"server_settings": flattenServerSettings(server.ServerSettings),
}
temp = append(temp, t)
}
return temp
}
func flattenServerSettings(defSet lb.ServerSettings) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"downinter": defSet.DownInter,
"fall": defSet.Fall,
"guid": defSet.GUID,
"inter": defSet.Inter,
"maxconn": defSet.MaxConn,
"maxqueue": defSet.MaxQueue,
"rise": defSet.Rise,
"slowstart": defSet.SlowStart,
"weight": defSet.Weight,
}
res = append(res, temp)
return res
}
func flattenLBBackends(backends []lb.ItemBackend) []map[string]interface{} {
temp := make([]map[string]interface{}, 0, len(backends))
for _, item := range backends {
t := map[string]interface{}{
"algorithm": item.Algorithm,
"guid": item.GUID,
"name": item.Name,
"server_default_settings": flattenServerSettings(item.ServerDefaultSettings),
"servers": flattenServers(item.Servers),
}
temp = append(temp, t)
}
return temp
}
func flattenLBList(lbl *lb.ListLB) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(lbl.Data))
for _, lb := range lbl.Data {
temp := map[string]interface{}{
"ha_mode": lb.HAMode,
"acl": flattenACl(lb.ACL),
"backend_haip": lb.BackendHAIP,
"backends": flattenLBBackends(lb.Backends),
"created_by": lb.CreatedBy,
"created_time": lb.CreatedTime,
"deleted_by": lb.DeletedBy,
"deleted_time": lb.DeletedTime,
"desc": lb.Description,
"dp_api_user": lb.DPAPIUser,
"dp_api_password": lb.DPAPIPassword,
"extnet_id": lb.ExtNetID,
"frontend_haip": lb.FrontendHAIP,
"frontends": flattenFrontends(lb.Frontends),
"gid": lb.GID,
"guid": lb.GUID,
"lb_id": lb.ID,
"manager_id": lb.ManagerId,
"manager_type": lb.ManagerType,
"milestones": lb.Milestones,
"name": lb.Name,
"part_k8s": lb.PartK8s,
"primary_node": flattenNode(lb.PrimaryNode),
"rg_id": lb.RGID,
"rg_name": lb.RGName,
"secondary_node": flattenNode(lb.SecondaryNode),
"status": lb.Status,
"tech_status": lb.TechStatus,
"updated_by": lb.UpdatedBy,
"updated_time": lb.UpdatedTime,
"user_managed": lb.UserManaged,
"vins_id": lb.VINSID,
"zone_id": lb.ZoneID,
}
res = append(res, temp)
}
return res
}
func flattenACl(m interface{}) string {
switch d := m.(type) {
case string:
return d
case int:
return strconv.Itoa(d)
case int64:
return strconv.FormatInt(d, 10)
case float64:
return strconv.FormatInt(int64(d), 10)
default:
return ""
}
}

View File

@@ -1,34 +0,0 @@
package lb
import (
"context"
"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/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
)
func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
errs := []error{}
if err := ic.ExistRG(ctx, uint64(d.Get("rg_id").(int)), c); err != nil {
errs = append(errs, err)
}
if err := ic.ExistExtNetInLb(ctx, uint64(d.Get("extnet_id").(int)), c); err != nil {
errs = append(errs, err)
}
if err := ic.ExistVinsInLb(ctx, uint64(d.Get("vins_id").(int)), c); err != nil {
errs = append(errs, err)
}
return dc.ErrorsToDiagnostics(errs)
}
func checkParamsExistenceLb(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
err := ic.ExistLB(ctx, uint64(d.Get("lb_id").(int)), c)
return diag.FromErr(err)
}

View File

@@ -1,600 +0,0 @@
/*
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 lb
import (
"context"
"strconv"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"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/status"
)
func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBCreate called with name: %s", d.Get("name").(string))
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistence(ctx, d, c); diags != nil {
return diags
}
req := lb.CreateRequest{
Name: d.Get("name").(string),
RGID: uint64(d.Get("rg_id").(int)),
ExtNetID: int64(d.Get("extnet_id").(int)),
VINSID: uint64(d.Get("vins_id").(int)),
}
if start, ok := d.GetOk("start"); ok {
req.Start = start.(bool)
}
if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string)
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
if haMode, ok := d.GetOk("ha_mode"); ok {
req.HighlyAvailable = haMode.(bool)
}
if sysctlParams, ok := d.GetOk("sysctl_params"); ok {
syscrlSliceMaps := sysctlParams.([]interface{})
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
for _, syscrlMap := range syscrlSliceMaps {
tempMap := make(map[string]interface{})
for k, v := range syscrlMap.(map[string]interface{}) {
if intVal, err := strconv.Atoi(v.(string)); err == nil {
tempMap[k] = intVal
continue
}
tempMap[k] = v.(string)
}
res = append(res, tempMap)
}
req.SysctlParams = res
}
lbId, err := c.CloudBroker().LB().Create(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(lbId, 10))
d.Set("lb_id", lbId)
var warnings dc.Warnings
if enable, ok := d.GetOk("enable"); ok {
if enable.(bool) {
if err := resourceLbEnable(ctx, lbId, m); err != nil {
warnings.Add(err)
}
} else {
if err := resourceLbDisable(ctx, lbId, m); err != nil {
warnings.Add(err)
}
}
}
return append(warnings.Get(), resourceLBRead(ctx, d, m)...)
}
func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBRead called for lb_id %s", d.Id())
// c := m.(*controller.ControllerCfg)
lbRec, err := utilityLBCheckPresence(ctx, d, m)
if lbRec == nil {
d.SetId("")
return diag.FromErr(err)
}
hasChanged := false
switch lbRec.Status {
case status.Modeled:
return diag.Errorf("The LB is in status: %s, please, contact support for more information", lbRec.Status)
case status.Creating:
case status.Created:
case status.Deleting:
case status.Deleted:
// lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
// restoreReq := lb.RestoreRequest{LBID: lbId}
// _, err := c.CloudBroker().LB().Restore(ctx, restoreReq)
// if err != nil {
// return diag.FromErr(err)
// }
// if enable := d.Get("enable"); enable.(bool) {
// req := lb.EnableRequest{
// LBID: lbId,
// }
// _, err := c.CloudBroker().LB().Enable(ctx, req)
// if err != nil {
// return diag.FromErr(err)
// }
// }
// if start := d.Get("start"); start.(bool) {
// if enable := d.Get("enable"); enable.(bool) {
// req := lb.StartRequest{
// LBID: lbId,
// }
// _, err := c.CloudBroker().LB().Start(ctx, req)
// if err != nil {
// return diag.FromErr(err)
// }
// } else {
// return diag.Errorf("To start the LB, please, enable LB first.")
// }
// }
// hasChanged = true
case status.Destroying:
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be read because it has been destroyed")
// return resourceLBCreate(ctx, d, m)
case status.Enabled:
case status.Enabling:
case status.Disabling:
case status.Disabled:
log.Debugf("The LB is in status: %s, troubles may occur with update. Please, enable LB first.", lbRec.Status)
case status.Restoring:
}
if hasChanged {
lbRec, err = utilityLBCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
flattenLB(d, lbRec)
return nil
}
func resourceLBDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBDelete called with lb id: %v", d.Get("lb_id").(int))
_, err := utilityLBCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := lb.DeleteRequest{
LBID: uint64(d.Get("lb_id").(int)),
}
if permanently, ok := d.GetOk("permanently"); ok {
req.Permanently = permanently.(bool)
}
_, err = c.CloudBroker().LB().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBUpdate called for lb_id %s", d.Id())
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistence(ctx, d, c); diags != nil {
return diags
}
lbRec, err := utilityLBCheckPresence(ctx, d, m)
if lbRec == nil {
d.SetId("")
return diag.FromErr(err)
}
hasChanged := false
switch lbRec.Status {
case status.Modeled:
return diag.Errorf("The LB is in status: %s, please, contact support for more information", lbRec.Status)
case status.Creating:
case status.Created:
case status.Deleting:
case status.Deleted:
restore, ok := d.GetOk("restore")
if ok && restore.(bool) {
if err := resourceLbRestore(ctx, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
enable, ok := d.GetOk("enable")
if ok && enable.(bool) {
if err := resourceLbEnable(ctx, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
start, ok := d.GetOk("start")
if ok && start.(bool) {
if enable.(bool) {
if err := resourceLbStart(ctx, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
} else {
return diag.Errorf("to start the LB, please, enable LB first.")
}
}
hasChanged = true
case status.Destroying:
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceLBCreate(ctx, d, m)
case status.Enabled:
case status.Enabling:
case status.Disabling:
case status.Disabled:
log.Debugf("The LB is in status: %s, troubles may occur with update. Please, enable LB first.", lbRec.Status)
case status.Restoring:
}
if hasChanged {
_, err = utilityLBCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
if d.HasChange("enable") {
if err := resourceLbChangeEnable(ctx, d, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("ha_mode") {
if err := resourceLbChangeHaMode(ctx, d, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("zone_id") {
if err := resourceLbChangeZoneID(ctx, d, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("sysctl_params") {
if err := resourceLbChangeSysctlParams(ctx, d, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("start") {
if err := resourceLbChangeStart(ctx, d, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("desc") {
if err := resourceLbChangeDesc(ctx, d, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("restart") {
if err := resourceLbChangeRestart(ctx, d, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("config_reset") {
if err := resourceLbChangeConfigReset(ctx, d, lbRec.ID, m); err != nil {
return diag.FromErr(err)
}
}
return resourceLBRead(ctx, d, m)
}
func resourceLbEnable(ctx context.Context, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
req := lb.EnableRequest{
LBID: lbId,
}
_, err := c.CloudBroker().LB().Enable(ctx, req)
return err
}
func resourceLbChangeSysctlParams(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
syscrlSliceMaps := d.Get("sysctl_params").([]interface{})
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
for _, syscrlMap := range syscrlSliceMaps {
tempMap := make(map[string]interface{})
for k, v := range syscrlMap.(map[string]interface{}) {
if intVal, err := strconv.Atoi(v.(string)); err == nil {
tempMap[k] = intVal
continue
}
tempMap[k] = v.(string)
}
res = append(res, tempMap)
}
if len(res) > 0 {
req := lb.UpdateSysctParamsRequest{
LBID: lbId,
SysctlParams: res,
}
_, err := c.CloudBroker().LB().UpdateSysctlParams(ctx, req)
return err
}
return nil
}
func resourceLbDisable(ctx context.Context, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
req := lb.DisableRequest{
LBID: lbId,
}
_, err := c.CloudBroker().LB().Disable(ctx, req)
return err
}
func resourceLbRestore(ctx context.Context, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
restoreReq := lb.RestoreRequest{
LBID: lbId,
}
_, err := c.CloudBroker().LB().Restore(ctx, restoreReq)
return err
}
func resourceLbStart(ctx context.Context, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
req := lb.StartRequest{
LBID: lbId,
}
_, err := c.CloudBroker().LB().Start(ctx, req)
return err
}
func resourceLbChangeEnable(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
enable := d.Get("enable").(bool)
if enable {
if err := resourceLbEnable(ctx, lbId, m); err != nil {
return err
}
} else {
if err := resourceLbDisable(ctx, lbId, m); err != nil {
return err
}
}
return nil
}
func resourceLbChangeHaMode(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
haModeOn := d.Get("ha_mode").(bool)
if haModeOn {
req := lb.HighlyAvailableRequest{
LBID: lbId,
}
if _, err := c.CloudBroker().LB().HighlyAvailable(ctx, req); err != nil {
return err
}
}
return nil
}
func resourceLbChangeZoneID(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
start := d.Get("start").(bool)
if start {
reqStop := lb.StopRequest{
LBID: uint64(d.Get("lb_id").(int)),
}
_, err := c.CloudBroker().LB().Stop(ctx, reqStop)
if err != nil {
return err
}
}
req := lb.MigrateToZoneRequest{
LBID: uint64(d.Get("lb_id").(int)),
ZoneID: uint64(d.Get("zone_id").(int)),
}
_, err := c.CloudBroker().LB().MigrateToZone(ctx, req)
if err != nil {
return err
}
if start {
reqStart := lb.StartRequest{
LBID: uint64(d.Get("lb_id").(int)),
}
_, err = c.CloudBroker().LB().Start(ctx, reqStart)
if err != nil {
return err
}
}
return nil
}
func resourceLbChangeStart(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
start := d.Get("start").(bool)
if start {
req := lb.StartRequest{LBID: lbId}
if _, err := c.CloudBroker().LB().Start(ctx, req); err != nil {
return err
}
} else {
req := lb.StopRequest{LBID: lbId}
if _, err := c.CloudBroker().LB().Stop(ctx, req); err != nil {
return err
}
}
return nil
}
func resourceLbChangeDesc(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
desc := d.Get("desc").(string)
req := lb.UpdateRequest{
LBID: lbId,
Description: desc,
}
if _, err := c.CloudBroker().LB().Update(ctx, req); err != nil {
return err
}
return nil
}
func resourceLbChangeRestart(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
restart := d.Get("restart").(bool)
if restart {
req := lb.RestartRequest{
LBID: lbId,
}
if safe, ok := d.GetOk("safe"); ok {
req.Safe = safe.(bool)
}
if _, err := c.CloudBroker().LB().Restart(ctx, req); err != nil {
return err
}
}
return nil
}
func resourceLbChangeRestore(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
restore := d.Get("restore").(bool)
if restore {
req := lb.RestoreRequest{
LBID: lbId,
}
if _, err := c.CloudBroker().LB().Restore(ctx, req); err != nil {
return err
}
}
return nil
}
func resourceLbChangeConfigReset(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
cfgReset := d.Get("config_reset").(bool)
if cfgReset {
req := lb.ConfigResetRequest{
LBID: lbId,
}
if _, err := c.CloudBroker().LB().ConfigReset(ctx, req); err != nil {
return err
}
}
return nil
}
func ResourceLB() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceLBCreate,
ReadContext: resourceLBRead,
UpdateContext: resourceLBUpdate,
DeleteContext: resourceLBDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: lbResourceSchemaMake(),
}
}

View File

@@ -1,212 +0,0 @@
/*
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 lb
import (
"context"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceLBBackendCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBBackendCreate: call for lb_backend id %s", d.Id())
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistenceLb(ctx, d, c); diags != nil {
return diags
}
req := lb.BackendCreateRequest{
LBID: uint64(d.Get("lb_id").(int)),
BackendName: d.Get("name").(string),
}
if algorithm, ok := d.GetOk("algorithm"); ok {
req.Algorithm = algorithm.(string)
}
if inter, ok := d.GetOk("inter"); ok {
req.Inter = uint64(inter.(int))
}
if downinter, ok := d.GetOk("downinter"); ok {
req.DownInter = uint64(downinter.(int))
}
if rise, ok := d.GetOk("rise"); ok {
req.Rise = uint64(rise.(int))
}
if fall, ok := d.GetOk("fall"); ok {
req.Fall = uint64(fall.(int))
}
if slowstart, ok := d.GetOk("slowstart"); ok {
req.SlowStart = uint64(slowstart.(int))
}
if maxconn, ok := d.GetOk("maxconn"); ok {
req.MaxConn = uint64(maxconn.(int))
}
if maxqueue, ok := d.GetOk("maxqueue"); ok {
req.MaxQueue = uint64(maxqueue.(int))
}
if weight, ok := d.GetOk("weight"); ok {
req.Weight = uint64(weight.(int))
}
_, err := c.CloudBroker().LB().BackendCreate(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("lb_id").(int)) + "#" + d.Get("name").(string))
return resourceLBBackendRead(ctx, d, m)
}
func resourceLBBackendRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBBackendRead: call for lb_backend id %s", d.Id())
b, err := utilityLBBackendCheckPresence(ctx, d, m)
if b == nil {
d.SetId("")
return diag.FromErr(err)
}
lbId, _ := strconv.ParseInt(strings.Split(d.Id(), "#")[0], 10, 32)
flattenResourceLBBackend(d, b, lbId)
return nil
}
func resourceLBBackendDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBBackendDelete: call for lb_backend id %s", d.Id())
_, err := utilityLBBackendCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := lb.BackendDeleteRequest{
LBID: uint64(d.Get("lb_id").(int)),
BackendName: d.Get("name").(string),
}
_, err = c.CloudBroker().LB().BackendDelete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceLBBackendUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBBackendUpdate: call for lb_backend id %s", d.Id())
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistenceLb(ctx, d, c); diags != nil {
return diags
}
req := lb.BackendUpdateRequest{
LBID: uint64(d.Get("lb_id").(int)),
BackendName: d.Get("name").(string),
}
if algorithm, ok := d.GetOk("algorithm"); ok {
req.Algorithm = algorithm.(string)
}
if inter, ok := d.GetOk("inter"); ok {
req.Inter = uint64(inter.(int))
}
if downinter, ok := d.GetOk("downinter"); ok {
req.DownInter = uint64(downinter.(int))
}
if rise, ok := d.GetOk("rise"); ok {
req.Rise = uint64(rise.(int))
}
if fall, ok := d.GetOk("fall"); ok {
req.Fall = uint64(fall.(int))
}
if slowstart, ok := d.GetOk("slowstart"); ok {
req.SlowStart = uint64(slowstart.(int))
}
if maxconn, ok := d.GetOk("maxconn"); ok {
req.MaxConn = uint64(maxconn.(int))
}
if maxqueue, ok := d.GetOk("maxqueue"); ok {
req.MaxQueue = uint64(maxqueue.(int))
}
if weight, ok := d.GetOk("weight"); ok {
req.Weight = uint64(weight.(int))
}
_, err := c.CloudBroker().LB().BackendUpdate(ctx, req)
if err != nil {
return diag.FromErr(err)
}
return resourceLBBackendRead(ctx, d, m)
}
func ResourceLBBackend() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceLBBackendCreate,
ReadContext: resourceLBBackendRead,
UpdateContext: resourceLBBackendUpdate,
DeleteContext: resourceLBBackendDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceLbBackendSchemaMake(),
}
}

View File

@@ -1,223 +0,0 @@
/*
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 lb
import (
"context"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceLBBackendServerCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBBackendServerCreate: call for lb_id %d, backend_name %s, server_name %s",
d.Get("lb_id").(int),
d.Get("backend_name").(string),
d.Get("name").(string))
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistenceLb(ctx, d, c); diags != nil {
return diags
}
req := lb.BackendServerAddRequest{
BackendName: d.Get("backend_name").(string),
ServerName: d.Get("name").(string),
Address: d.Get("address").(string),
LBID: uint64(d.Get("lb_id").(int)),
Port: uint64(d.Get("port").(int)),
}
if check, ok := d.GetOk("check"); ok {
req.Check = check.(string)
}
if inter, ok := d.GetOk("inter"); ok {
req.Inter = uint64(inter.(int))
}
if downinter, ok := d.GetOk("downinter"); ok {
req.DownInter = uint64(downinter.(int))
}
if rise, ok := d.GetOk("rise"); ok {
req.Rise = uint64(rise.(int))
}
if fall, ok := d.GetOk("fall"); ok {
req.Fall = uint64(fall.(int))
}
if slowstart, ok := d.GetOk("slowstart"); ok {
req.SlowStart = uint64(slowstart.(int))
}
if maxconn, ok := d.GetOk("maxconn"); ok {
req.MaxConn = uint64(maxconn.(int))
}
if maxqueue, ok := d.GetOk("maxqueue"); ok {
req.MaxQueue = uint64(maxqueue.(int))
}
if weight, ok := d.GetOk("weight"); ok {
req.Weight = uint64(weight.(int))
}
_, err := c.CloudBroker().LB().BackendServerAdd(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("lb_id").(int)) + "#" + d.Get("backend_name").(string) + "#" + d.Get("name").(string))
return resourceLBBackendServerRead(ctx, d, m)
}
func resourceLBBackendServerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBBackendServerRead: call for id %s", d.Id())
s, err := utilityLBBackendServerCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
lbId, _ := strconv.ParseInt(strings.Split(d.Id(), "#")[0], 10, 32)
backendName := strings.Split(d.Id(), "#")[1]
flattenResourceLBBackendServer(d, s, lbId, backendName)
return nil
}
func resourceLBBackendServerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBBackendServerDelete: call for id %s", d.Id())
_, err := utilityLBBackendServerCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := lb.BackendServerDeleteRequest{
LBID: uint64(d.Get("lb_id").(int)),
BackendName: d.Get("backend_name").(string),
ServerName: d.Get("name").(string),
}
_, err = c.CloudBroker().LB().BackendServerDelete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceLBBackendServerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBBackendServerEdit: call for id %s", d.Id())
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistenceLb(ctx, d, c); diags != nil {
return diags
}
req := lb.BackendServerUpdateRequest{
BackendName: d.Get("backend_name").(string),
LBID: uint64(d.Get("lb_id").(int)),
ServerName: d.Get("name").(string),
Address: d.Get("address").(string),
Port: uint64(d.Get("port").(int)),
}
if check, ok := d.GetOk("check"); ok {
req.Check = check.(string)
}
if inter, ok := d.GetOk("inter"); ok {
req.Inter = uint64(inter.(int))
}
if downinter, ok := d.GetOk("downinter"); ok {
req.DownInter = uint64(downinter.(int))
}
if rise, ok := d.GetOk("rise"); ok {
req.Rise = uint64(rise.(int))
}
if fall, ok := d.GetOk("fall"); ok {
req.Fall = uint64(fall.(int))
}
if slowstart, ok := d.GetOk("slowstart"); ok {
req.SlowStart = uint64(slowstart.(int))
}
if maxconn, ok := d.GetOk("maxconn"); ok {
req.MaxConn = uint64(maxconn.(int))
}
if maxqueue, ok := d.GetOk("maxqueue"); ok {
req.MaxQueue = uint64(maxqueue.(int))
}
if weight, ok := d.GetOk("weight"); ok {
req.Weight = uint64(weight.(int))
}
_, err := c.CloudBroker().LB().BackendServerUpdate(ctx, req)
if err != nil {
return diag.FromErr(err)
}
return resourceLBBackendServerRead(ctx, d, m)
}
func ResourceLBBackendServer() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceLBBackendServerCreate,
ReadContext: resourceLBBackendServerRead,
UpdateContext: resourceLBBackendServerUpdate,
DeleteContext: resourceLBBackendServerDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceLbBackendServerSchemaMake(),
}
}

View File

@@ -1,145 +0,0 @@
/*
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 lb
import (
"context"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceLBFrontendCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBFrontendCreate: call for lb_id %d, backend %s to create frontend %s",
d.Get("lb_id").(int),
d.Get("backend_name").(string),
d.Get("name").(string))
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistenceLb(ctx, d, c); diags != nil {
return diags
}
req := lb.FrontendCreateRequest{
BackendName: d.Get("backend_name").(string),
LBID: uint64(d.Get("lb_id").(int)),
FrontendName: d.Get("name").(string),
}
_, err := c.CloudBroker().LB().FrontendCreate(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("lb_id").(int)) + "#" + d.Get("name").(string))
return resourceLBFrontendRead(ctx, d, m)
}
func resourceLBFrontendRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBFrontendRead: call for id %s", d.Id())
f, err := utilityLBFrontendCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
lbId, _ := strconv.ParseInt(strings.Split(d.Id(), "#")[0], 10, 32)
flattenLBFrontend(d, f, lbId)
return nil
}
func resourceLBFrontendDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBFrontendDelete: call for id %s", d.Id())
_, err := utilityLBFrontendCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := lb.FrontendDeleteRequest{
LBID: uint64(d.Get("lb_id").(int)),
FrontendName: d.Get("name").(string),
}
_, err = c.CloudBroker().LB().FrontendDelete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceLBFrontendEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
return nil
}
func ResourceLBFrontend() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceLBFrontendCreate,
ReadContext: resourceLBFrontendRead,
UpdateContext: resourceLBFrontendEdit,
DeleteContext: resourceLBFrontendDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceLbFrontendSchemaMake(),
}
}

View File

@@ -1,171 +0,0 @@
/*
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 lb
import (
"context"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceLBFrontendBindCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBFrontendBindCreate: call for lb_id %d, frontend %s to create bind %s",
d.Get("lb_id").(int),
d.Get("frontend_name").(string),
d.Get("name").(string))
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistenceLb(ctx, d, c); diags != nil {
return diags
}
req := lb.FrontendBindRequest{
LBID: uint64(d.Get("lb_id").(int)),
FrontendName: d.Get("frontend_name").(string),
BindingName: d.Get("name").(string),
BindingAddress: d.Get("address").(string),
BindingPort: uint64(d.Get("port").(int)),
}
_, err := c.CloudBroker().LB().FrontendBind(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("lb_id").(int)) + "#" + d.Get("frontend_name").(string) + "#" + d.Get("name").(string))
return resourceLBFrontendBindRead(ctx, d, m)
}
func resourceLBFrontendBindRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBFrontendBindRead: call for %s", d.Id())
b, err := utilityLBFrontendBindCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
lbId, _ := strconv.ParseInt(strings.Split(d.Id(), "#")[0], 10, 32)
frontendName := strings.Split(d.Id(), "#")[1]
flattenLBFrontendBind(d, b, lbId, frontendName)
return nil
}
func resourceLBFrontendBindDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBFrontendBindDelete: call for %s", d.Id())
_, err := utilityLBFrontendBindCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := lb.FrontendBindDeleteRequest{
LBID: uint64(d.Get("lb_id").(int)),
FrontendName: d.Get("frontend_name").(string),
BindingName: d.Get("name").(string),
}
_, err = c.CloudBroker().LB().FrontendBindDelete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceLBFrontendBindUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBFrontendBindEdit: call for %s", d.Id())
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistenceLb(ctx, d, c); diags != nil {
return diags
}
req := lb.FrontendBindUpdateRequest{
FrontendName: d.Get("frontend_name").(string),
BindingName: d.Get("name").(string),
LBID: uint64(d.Get("lb_id").(int)),
}
if d.HasChange("address") || d.HasChange("port") {
req.BindingAddress = d.Get("address").(string)
req.BindingPort = uint64(d.Get("port").(int))
}
_, err := c.CloudBroker().LB().FrontendBindUpdate(ctx, req)
if err != nil {
return diag.FromErr(err)
}
return resourceLBFrontendBindRead(ctx, d, m)
}
func ResourceLBFrontendBind() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceLBFrontendBindCreate,
ReadContext: resourceLBFrontendBindRead,
UpdateContext: resourceLBFrontendBindUpdate,
DeleteContext: resourceLBFrontendBindDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceLbFrontendBindSchemaMake(),
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,61 +0,0 @@
/*
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 lb
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityLBCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.RecordLB, error) {
c := m.(*controller.ControllerCfg)
req := lb.GetRequest{}
if d.Id() != "" {
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.LBID = rgId
} else {
req.LBID = uint64(d.Get("lb_id").(int))
}
lb, err := c.CloudBroker().LB().Get(ctx, req)
if err != nil {
return nil, err
}
return lb, nil
}

View File

@@ -1,73 +0,0 @@
/*
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 lb
import (
"context"
"fmt"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityLBBackendCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ItemBackend, error) {
c := m.(*controller.ControllerCfg)
req := lb.GetRequest{}
bName := d.Get("name").(string)
if d.Id() != "" {
parameters := strings.Split(d.Id(), "#")
lbId, _ := strconv.ParseUint(parameters[0], 10, 64)
req.LBID = lbId
bName = parameters[1]
} else {
req.LBID = uint64(d.Get("lb_id").(int))
}
lbRec, err := c.CloudBroker().LB().Get(ctx, req)
if err != nil {
return nil, err
}
backends := lbRec.Backends
for _, b := range backends {
if b.Name == bName {
return &b, nil
}
}
return nil, fmt.Errorf("can not find backend with name: %s for lb: %d", bName, lbRec.ID)
}

View File

@@ -1,88 +0,0 @@
/*
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 lb
import (
"context"
"fmt"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityLBBackendServerCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ItemServer, error) {
c := m.(*controller.ControllerCfg)
req := lb.GetRequest{}
bName := d.Get("backend_name").(string)
sName := d.Get("name").(string)
if d.Id() != "" {
parameters := strings.Split(d.Id(), "#")
lbId, _ := strconv.ParseUint(parameters[0], 10, 64)
req.LBID = lbId
bName = parameters[1]
sName = parameters[2]
} else {
req.LBID = uint64(d.Get("lb_id").(int))
}
foundLB, err := c.CloudBroker().LB().Get(ctx, req)
if err != nil {
return nil, err
}
backend := &lb.ItemBackend{}
backends := foundLB.Backends
for i, b := range backends {
if b.Name == bName {
backend = &backends[i]
break
}
}
if backend.Name == "" {
return nil, fmt.Errorf("can not find backend with name: %s for lb: %d", bName, foundLB.ID)
}
for _, s := range backend.Servers {
if s.Name == sName {
return &s, nil
}
}
return nil, fmt.Errorf("can not find server with name: %s for backend: %s for lb: %d", sName, bName, foundLB.ID)
}

View File

@@ -1,74 +0,0 @@
/*
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 lb
import (
"context"
"fmt"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityLBFrontendCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ItemFrontend, error) {
c := m.(*controller.ControllerCfg)
req := lb.GetRequest{}
fName := d.Get("name").(string)
if d.Id() != "" {
parameters := strings.Split(d.Id(), "#")
lbId, _ := strconv.ParseUint(parameters[0], 10, 64)
req.LBID = lbId
fName = parameters[1]
} else {
req.LBID = uint64(d.Get("lb_id").(int))
}
foundLB, err := c.CloudBroker().LB().Get(ctx, req)
if err != nil {
return nil, err
}
frontends := foundLB.Frontends
for _, f := range frontends {
if f.Name == fName {
return &f, nil
}
}
return nil, fmt.Errorf("can not find frontend with name: %s for lb: %d", fName, foundLB.ID)
}

View File

@@ -1,87 +0,0 @@
/*
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 lb
import (
"context"
"fmt"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityLBFrontendBindCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ItemBinding, error) {
c := m.(*controller.ControllerCfg)
req := lb.GetRequest{}
fName := d.Get("frontend_name").(string)
bName := d.Get("name").(string)
if d.Id() != "" {
parameters := strings.Split(d.Id(), "#")
lbId, _ := strconv.ParseUint(parameters[0], 10, 64)
req.LBID = lbId
fName = parameters[1]
bName = parameters[2]
} else {
req.LBID = uint64(d.Get("lb_id").(int))
}
foundLB, err := c.CloudBroker().LB().Get(ctx, req)
if err != nil {
return nil, err
}
frontend := &lb.ItemFrontend{}
frontends := foundLB.Frontends
for i, f := range frontends {
if f.Name == fName {
frontend = &frontends[i]
break
}
}
if frontend.Name == "" {
return nil, fmt.Errorf("can not find frontend with name: %s for lb: %d", fName, foundLB.ID)
}
for _, b := range frontend.Bindings {
if b.Name == bName {
return &b, nil
}
}
return nil, fmt.Errorf("can not find bind with name: %s for frontend: %s for lb: %d", bName, fName, foundLB.ID)
}

View File

@@ -1,108 +0,0 @@
/*
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 lb
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityLBListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) {
c := m.(*controller.ControllerCfg)
req := lb.ListRequest{}
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 account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if front_ip, ok := d.GetOk("front_ip"); ok {
req.FrontIP = front_ip.(string)
}
if back_ip, ok := d.GetOk("back_ip"); ok {
req.BackIP = back_ip.(string)
}
if includedeleted, ok := d.GetOk("includedeleted"); ok {
req.IncludeDeleted = includedeleted.(bool)
}
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 zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
log.Debugf("utilityLBListCheckPresence: load lb list")
lbList, err := c.CloudBroker().LB().List(ctx, req)
if err != nil {
return nil, err
}
return lbList, nil
}

View File

@@ -1,96 +0,0 @@
/*
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 lb
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityLBListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) {
c := m.(*controller.ControllerCfg)
req := lb.ListDeletedRequest{}
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 account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if front_ip, ok := d.GetOk("front_ip"); ok {
req.FrontIP = front_ip.(string)
}
if back_ip, ok := d.GetOk("back_ip"); ok {
req.BackIP = back_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))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
log.Debugf("utilityLBListDeletedCheckPresence: load lb list")
lbList, err := c.CloudBroker().LB().ListDeleted(ctx, req)
if err != nil {
return nil, err
}
return lbList, nil
}