4.5.0-alpha

This commit is contained in:
Nikita Sorokin
2023-11-07 18:26:09 +03:00
parent 2453a32d01
commit 2bc0fbae9a
198 changed files with 18877 additions and 4003 deletions

View File

@@ -0,0 +1,219 @@
/*
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>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package flipgroup
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 dataSourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
flipgroup, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenFlipgroup(d, flipgroup)
d.SetId(strconv.Itoa(d.Get("flipgroup_id").(int)))
return nil
}
func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"flipgroup_id": {
Type: schema.TypeInt,
Required: true,
Description: "flipgroup_id",
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
Description: "account_id",
},
"account_name": {
Type: schema.TypeString,
Computed: true,
Description: "account_name",
},
"client_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "client_ids",
},
"client_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "client_names",
},
"client_type": {
Type: schema.TypeString,
Computed: true,
Description: "client_type",
},
"conn_id": {
Type: schema.TypeInt,
Computed: true,
Description: "conn_id",
},
"conn_type": {
Type: schema.TypeString,
Computed: true,
Description: "conn_type",
},
"created_by": {
Type: schema.TypeString,
Computed: true,
Description: "created_by",
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
Description: "created_time",
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
Description: "default_gw",
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
Description: "deleted_by",
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
Description: "deleted_time",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "description",
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"guid": {
Type: schema.TypeInt,
Computed: true,
Description: "guid",
},
"ip": {
Type: schema.TypeString,
Computed: true,
Description: "ip",
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
Description: "milestones",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "name",
},
"net_id": {
Type: schema.TypeInt,
Computed: true,
Description: "net_id",
},
"net_type": {
Type: schema.TypeString,
Computed: true,
Description: "net_type",
},
"network": {
Type: schema.TypeString,
Computed: true,
Description: "network",
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
Description: "rg_id",
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
Description: "rg_name",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "status",
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
Description: "updated_by",
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
Description: "updated_time",
},
}
return rets
}
func DataSourceFlipgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceFlipgroupRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceFlipgroupSchemaMake(),
}
}

View File

@@ -0,0 +1,243 @@
/*
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>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package flipgroup
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 dataSourceFlipgroupListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
flipgroupsList, err := utilityFlipgroupListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenFlipgroupsList(flipgroupsList))
d.Set("entry_count", flipgroupsList.EntryCount)
return nil
}
func dataSourceFlipgroupItemSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"ckey": {
Type: schema.TypeString,
Computed: true,
Description: "ckey",
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
Description: "account_id",
},
"client_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "client_ids",
},
"client_type": {
Type: schema.TypeString,
Computed: true,
Description: "client_type",
},
"conn_id": {
Type: schema.TypeInt,
Computed: true,
Description: "conn_id",
},
"conn_type": {
Type: schema.TypeString,
Computed: true,
Description: "conn_type",
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
Description: "default_gw",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "description",
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"guid": {
Type: schema.TypeInt,
Computed: true,
Description: "guid",
},
"flipgroup_id": {
Type: schema.TypeInt,
Computed: true,
Description: "flipgroup_id",
},
"ip": {
Type: schema.TypeString,
Computed: true,
Description: "ip",
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
Description: "milestones",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "name",
},
"net_id": {
Type: schema.TypeInt,
Computed: true,
Description: "net_id",
},
"net_type": {
Type: schema.TypeString,
Computed: true,
Description: "net_type",
},
"net_mask": {
Type: schema.TypeInt,
Computed: true,
Description: "net_mask",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "status",
},
}
return rets
}
func dataSourceFlipgroupsListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "name",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Description: "vins_id",
},
"vins_name": {
Type: schema.TypeString,
Optional: true,
Description: "vins_name",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Description: "extnet_id",
},
"by_ip": {
Type: schema.TypeString,
Optional: true,
Description: "by_ip",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "rg_id",
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "by_id",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: dataSourceFlipgroupItemSchemaMake(),
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry_count",
},
}
return res
}
func DataSourceFlipgroupList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceFlipgroupListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceFlipgroupsListSchemaMake(),
}
}

View File

@@ -0,0 +1,100 @@
/*
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>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package flipgroup
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenFlipgroup(d *schema.ResourceData, flip *flipgroup.RecordFLIPGroup) {
d.Set("flipgroup_id", flip.ID)
d.Set("account_id", flip.AccountID)
d.Set("account_name", flip.AccountName)
d.Set("client_ids", flip.ClientIDs)
d.Set("client_names", flip.ClientNames)
d.Set("client_type", flip.ClientType)
d.Set("conn_id", flip.ConnID)
d.Set("conn_type", flip.ConnType)
d.Set("created_by", flip.CreatedBy)
d.Set("created_time", flip.CreatedTime)
d.Set("default_gw", flip.DefaultGW)
d.Set("deleted_by", flip.DeletedBy)
d.Set("deleted_time", flip.DeletedTime)
d.Set("description", flip.Description)
d.Set("gid", flip.GID)
d.Set("guid", flip.GUID)
d.Set("ip", flip.IP)
d.Set("milestones", flip.Milestones)
d.Set("name", flip.Name)
d.Set("net_id", flip.NetID)
d.Set("net_type", flip.NetType)
d.Set("network", flip.Network)
d.Set("rg_id", flip.RGID)
d.Set("rg_name", flip.RGName)
d.Set("status", flip.Status)
d.Set("updated_by", flip.UpdatedBy)
d.Set("updated_time", flip.UpdatedTime)
}
func flattenFlipgroupsList(fg *flipgroup.ListFLIPGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(fg.Data))
for _, flip := range fg.Data {
temp := map[string]interface{}{
"ckey": flip.CKey,
"meta": flattens.FlattenMeta(flip.Meta),
"flipgroup_id": flip.ID,
"account_id": flip.AccountID,
"client_ids": flip.ClientIDs,
"client_type": flip.ClientType,
"conn_id": flip.ConnID,
"conn_type": flip.ConnType,
"default_gw": flip.DefaultGW,
"description": flip.Description,
"gid": flip.GID,
"guid": flip.GUID,
"ip": flip.IP,
"milestones": flip.Milestones,
"name": flip.Name,
"net_id": flip.NetID,
"net_type": flip.NetType,
"net_mask": flip.NetMask,
"status": flip.Status,
}
res = append(res, temp)
}
return res
}

View File

@@ -0,0 +1,70 @@
/*
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>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package flipgroup
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
)
func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
c := m.(*controller.ControllerCfg)
accountId := uint64(d.Get("account_id").(int))
req := account.ListRequest{}
accountList, err := c.CloudBroker().Account().List(ctx, req)
if err != nil {
return false, err
}
return len(accountList.FilterByID(accountId).Data) != 0, nil
}
func existNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
c := m.(*controller.ControllerCfg)
netID := uint64(d.Get("net_id").(int))
req := vins.ListRequest {}
vinsList, err := c.CloudBroker().VINS().List(ctx, req)
if err != nil {
return false, err
}
return len(vinsList.FilterByID(netID).Data) != 0, nil
}

View File

@@ -0,0 +1,364 @@
/*
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>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package flipgroup
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
"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"
log "github.com/sirupsen/logrus"
)
func resourceFlipgroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceFlipgroupCreate called with name: %s, accountID %v", d.Get("name").(string), d.Get("account_id").(int))
c := m.(*controller.ControllerCfg)
req := flipgroup.CreateRequest{
Name: d.Get("name").(string),
NetType: d.Get("net_type").(string),
ClientType: d.Get("client_type").(string),
}
haveAccount, err := existAccountID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveAccount {
return diag.Errorf("resourceFlipgroupCreate: can't create Flipgroup because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
}
req.AccountID = uint64(d.Get("account_id").(int))
haveVINS, err := existNetID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveVINS {
return diag.Errorf("resourceFlipgroupCreate: can't create Flipgroup because VinsID %d is not allowed or does not exist", d.Get("net_id").(int))
}
req.NetID = uint64(d.Get("net_id").(int))
if IP, ok := d.GetOk("ip"); ok {
req.IP = IP.(string)
}
if description, ok := d.GetOk("desc"); ok {
req.Description = description.(string)
}
resp, err := c.CloudBroker().FLIPGroup().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(fmt.Sprint(resp.ID))
var warnings dc.Warnings
if client_ids, ok := d.GetOk("client_ids"); ok {
casted := client_ids.([]interface{})
addComputesAfterCreation(ctx, &warnings, c, casted, resp.ID)
}
return append(warnings.Get(), resourceFlipgroupRead(ctx, d, m)...)
}
func resourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenFlipgroup(d, fg)
return nil
}
func resourceFlipgroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceFlipgroupUpdate called with id: %v", d.Get("flipgroup_id").(int))
c := m.(*controller.ControllerCfg)
haveAccount, err := existAccountID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveAccount {
return diag.Errorf("resourceFlipgroupUpdate: can't update Flipgroup because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
}
haveVINS, err := existNetID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveVINS {
return diag.Errorf("resourceFlipgroupUpdate: can't update Flipgroup because VinsID %d is not allowed or does not exist", d.Get("net_id").(int))
}
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
var warnings dc.Warnings
basicUpdate := false
req := flipgroup.EditRequest{FLIPGroupID: fg.ID}
if d.HasChange("desc") {
req.Description = d.Get("desc").(string)
basicUpdate = true
}
if d.HasChange("name") {
req.Name = d.Get("name").(string)
basicUpdate = true
}
if basicUpdate {
_, err := c.CloudBroker().FLIPGroup().Edit(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("client_ids") {
handleClientIDsUpdate(ctx, d, c, fg, &warnings)
}
return append(warnings.Get(), resourceFlipgroupRead(ctx, d, m)...)
}
func resourceFlipgroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceFlipgroupDelete called with id: %v", d.Get("flipgroup_id").(int))
c := m.(*controller.ControllerCfg)
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
req := flipgroup.DeleteRequest{
FLIPGroupID: fg.ID,
}
_, err = c.CloudBroker().FLIPGroup().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
return nil
}
func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Required: true,
Description: "Account ID",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Flipgroup name",
},
"net_id": {
Type: schema.TypeInt,
Required: true,
Description: "EXTNET or ViNS ID",
},
"net_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS"}, true),
Description: "Network type, EXTNET or VINS",
},
"client_type": {
Type: schema.TypeString,
Required: true,
Description: "Type of client, 'compute' ('vins' will be later)",
ValidateFunc: validation.StringInSlice([]string{"compute"}, true),
},
"ip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "IP address to associate with this group. If empty, the platform will autoselect IP address",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Text description of this Flipgroup instance",
},
"client_ids": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "List of clients attached to this Flipgroup instance",
},
"client_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "client_names",
},
"account_name": {
Type: schema.TypeString,
Computed: true,
Description: "account_name",
},
"flipgroup_id": {
Type: schema.TypeInt,
Computed: true,
},
"conn_id": {
Type: schema.TypeInt,
Computed: true,
},
"conn_type": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
Description: "created_by",
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
Description: "created_time",
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
Description: "deleted_by",
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
Description: "deleted_time",
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
Description: "network",
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
Description: "rg_id",
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
Description: "rg_name",
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
Description: "updated_by",
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
Description: "updated_time",
},
"net_mask": {
Type: schema.TypeInt,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
}
}
func ResourceFlipgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
CreateContext: resourceFlipgroupCreate,
ReadContext: resourceFlipgroupRead,
UpdateContext: resourceFlipgroupUpdate,
DeleteContext: resourceFlipgroupDelete,
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout300s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceFlipgroupSchemaMake(),
}
}

View File

@@ -0,0 +1,66 @@
/*
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>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package flipgroup
import (
"context"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.RecordFLIPGroup, error) {
c := m.(*controller.ControllerCfg)
req := flipgroup.GetRequest{}
if d.Id() != "" {
id, _ := strconv.ParseUint(d.Id(), 10, 64)
req.FLIPGroupID = id
} else {
req.FLIPGroupID = uint64(d.Get("flipgroup_id").(int))
}
log.Debugf("utilityDiskCheckPresence: load disk")
flipgroup, err := c.CloudBroker().FLIPGroup().Get(ctx, req)
if err != nil {
return nil, err
}
return flipgroup, nil
}

View File

@@ -0,0 +1,86 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package flipgroup
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityFlipgroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.ListFLIPGroups, error) {
c := m.(*controller.ControllerCfg)
req := flipgroup.ListRequest{}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if vinsId, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vinsId.(int))
}
if vinsName, ok := d.GetOk("vins_name"); ok {
req.VINSName = vinsName.(string)
}
if extnetId, ok := d.GetOk("extnet_id"); ok {
req.ExtNetID = uint64(extnetId.(int))
}
if byIp, ok := d.GetOk("by_ip"); ok {
req.ByIP = byIp.(string)
}
if rgId, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rgId.(int))
}
if byID, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byID.(int))
}
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("utilityFlipgroupListCheckPresence: load flipgroup list")
flipgroupList, err := c.CloudBroker().FLIPGroup().List(ctx, req)
if err != nil {
return nil, err
}
return flipgroupList, nil
}

View File

@@ -0,0 +1,127 @@
/*
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>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package flipgroup
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/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
)
func addComputesAfterCreation(ctx context.Context, warnings *dc.Warnings, c *controller.ControllerCfg, compute_ids []interface{}, flipgroupID uint64) {
if len(compute_ids) == 0 {
return
}
log.Debugf("Adding %v computes to flipgroup [id=%v]...", len(compute_ids), flipgroupID)
for _, elem := range compute_ids {
compute_id := uint64(elem.(int))
req := flipgroup.ComputeAddRequest{
FLIPGroupID: flipgroupID,
ComputeID: compute_id,
}
_, err := c.CloudBroker().FLIPGroup().ComputeAdd(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
func handleClientIDsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, fg *flipgroup.RecordFLIPGroup, warn *dc.Warnings) {
addedClients := make([]interface{}, 0)
removedClients := make([]interface{}, 0)
old_set, new_set := d.GetChange("client_ids")
oldSlice := old_set.([]interface{})
newSlice := new_set.([]interface{})
for _, oldElem := range oldSlice {
if !containsClient(newSlice, oldElem) {
removedClients = append(removedClients, oldElem)
}
}
for _, newElem := range newSlice {
if !containsClient(oldSlice, newElem) {
addedClients = append(addedClients, newElem)
}
}
log.Debugf("Found client_ids change with %v deletion(s) and %v addition(s) [flipgroupID=%v]", len(removedClients), len(addedClients), fg.ID)
if len(addedClients) > 0 {
for _, id := range addedClients {
req := flipgroup.ComputeAddRequest{
FLIPGroupID: fg.ID,
ComputeID: uint64(id.(int)),
}
if _, err := c.CloudBroker().FLIPGroup().ComputeAdd(ctx, req); err != nil {
warn.Add(err)
}
}
}
if len(removedClients) > 0 {
for _, id := range removedClients {
req := flipgroup.ComputeRemoveRequest{
FLIPGroupID: fg.ID,
ComputeID: uint64(id.(int)),
}
if _, err := c.CloudBroker().FLIPGroup().ComputeRemove(ctx, req); err != nil {
warn.Add(err)
}
}
}
}
func containsClient(set []interface{}, check interface{}) bool {
for _, elem := range set {
elemConv := elem.(int)
checkConv := check.(int)
if elemConv == checkConv {
return true
}
}
return false
}