Nikita Sorokin 1 year ago
parent 2453a32d01
commit f4daf5035c

@ -1,8 +1,4 @@
## Version 4.4.2 ## Version 4.4.3
### Feature ### Feature
- Added state upgrade from schema version 2 to schema version 3 - Add in cloudbroker account and extnet data_source and resource
### Bugfix
- Fixed incorrect work data_source_static_route
- Fixed bug with old field "with_default_vins" in state

@ -7,7 +7,7 @@ ZIPDIR = ./zip
BINARY=${NAME} BINARY=${NAME}
WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH} WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH}
MAINPATH = ./cmd/decort/ MAINPATH = ./cmd/decort/
VERSION=4.4.2 VERSION=4.4.3
OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH)
FILES = ${BINARY}_${VERSION}_darwin_amd64\ FILES = ${BINARY}_${VERSION}_darwin_amd64\

@ -9,7 +9,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.0
golang.org/x/net v0.15.0 golang.org/x/net v0.15.0
repository.basistech.ru/BASIS/decort-golang-sdk v1.6.5 repository.basistech.ru/BASIS/decort-golang-sdk v1.6.8
) )
require ( require (

@ -339,5 +339,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
repository.basistech.ru/BASIS/decort-golang-sdk v1.6.5 h1:37OLNiSgF3SXjj0ZMRikVrBiNlNdS9NY8QxD9YFfHBY= repository.basistech.ru/BASIS/decort-golang-sdk v1.6.8 h1:O/Z4iWIcBAc9OJ/8OzBgvRDyZoOVC/NKXMTbLe/C2ec=
repository.basistech.ru/BASIS/decort-golang-sdk v1.6.5/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE= repository.basistech.ru/BASIS/decort-golang-sdk v1.6.8/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE=

@ -1,8 +1,12 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Nikita Sorokin, <nesorokin@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -29,7 +33,33 @@ builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package grid package dc
import "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
func ErrorsToDiagnostics(errs []error) diag.Diagnostics {
if len(errs) == 0 {
return nil
}
diags := diag.Diagnostics{}
for _, err := range errs {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: err.Error(),
})
}
return diags
}
func ErrorsToWarnings(errs []error) Warnings {
w := Warnings{}
for _, err := range errs {
w.Add(err)
}
const GridListGetAPI = "/restmachine/cloudbroker/grid/list" return w
const GridGetAPI = "/restmachine/cloudbroker/grid/get" }

@ -38,25 +38,25 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins"
cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account"
cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks" // cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks"
cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet"
cb_grid "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/grid" // cb_flipgroup "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/flipgroup"
cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image" // cb_grid "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/grid"
cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice" // cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image"
cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg" // cb_lb "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/lb"
cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep" // cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
cb_vgpu "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vgpu" // cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg"
// cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep"
// cb_stack "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/stack"
// cb_vgpu "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vgpu"
) )
func newDataSourcesMap() map[string]*schema.Resource { func newDataSourcesMap() map[string]*schema.Resource {
return map[string]*schema.Resource{ return map[string]*schema.Resource{
"decort_account": account.DataSourceAccount(), "decort_account": account.DataSourceAccount(),
"decort_account_resource_consumption_list": account.DataSourceAccountResourceConsumptionList(),
"decort_account_resource_consumption_get": account.DataSourceAccountResourceConsumptionGet(),
"decort_resgroup": rg.DataSourceResgroup(), "decort_resgroup": rg.DataSourceResgroup(),
"decort_kvmvm": kvmvm.DataSourceCompute(), "decort_kvmvm": kvmvm.DataSourceCompute(),
"decort_kvmvm_list": kvmvm.DataSourceComputeList(), "decort_kvmvm_list": kvmvm.DataSourceComputeList(),
"decort_kvmvm_list_deleted": kvmvm.DataSourceComputeListDeleted(),
"decort_kvmvm_audits": kvmvm.DataSourceComputeAudits(), "decort_kvmvm_audits": kvmvm.DataSourceComputeAudits(),
"decort_kvmvm_get_audits": kvmvm.DataSourceComputeGetAudits(), "decort_kvmvm_get_audits": kvmvm.DataSourceComputeGetAudits(),
"decort_kvmvm_get_console_url": kvmvm.DataSourceComputeGetConsoleUrl(), "decort_kvmvm_get_console_url": kvmvm.DataSourceComputeGetConsoleUrl(),
@ -64,15 +64,12 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_kvmvm_pfw_list": kvmvm.DataSourceComputePfwList(), "decort_kvmvm_pfw_list": kvmvm.DataSourceComputePfwList(),
"decort_kvmvm_user_list": kvmvm.DataSourceComputeUserList(), "decort_kvmvm_user_list": kvmvm.DataSourceComputeUserList(),
"decort_kvmvm_snapshot_usage": kvmvm.DataSourceComputeSnapshotUsage(), "decort_kvmvm_snapshot_usage": kvmvm.DataSourceComputeSnapshotUsage(),
"decort_kvmvm_vgpu_list": kvmvm.DataSourceComputeVGPUList(),
"decort_kvmvm_pci_device_list": kvmvm.DataSourceComputePCIDeviceList(),
"decort_k8s": k8s.DataSourceK8s(), "decort_k8s": k8s.DataSourceK8s(),
"decort_k8s_list": k8s.DataSourceK8sList(), "decort_k8s_list": k8s.DataSourceK8sList(),
"decort_k8s_list_deleted": k8s.DataSourceK8sListDeleted(), "decort_k8s_list_deleted": k8s.DataSourceK8sListDeleted(),
"decort_k8s_wg": k8s.DataSourceK8sWg(), "decort_k8s_wg": k8s.DataSourceK8sWg(),
"decort_k8s_wg_list": k8s.DataSourceK8sWgList(), "decort_k8s_wg_list": k8s.DataSourceK8sWgList(),
"decort_k8s_computes": k8s.DataSourceK8sComputes(), "decort_k8s_computes": k8s.DataSourceK8sComputes(),
"decort_k8s_wg_cloud_init": k8s.DataSourceK8sWgCloudInit(),
"decort_k8ci_list": k8s.DataSourceK8CIList(), "decort_k8ci_list": k8s.DataSourceK8CIList(),
"decort_vins": vins.DataSourceVins(), "decort_vins": vins.DataSourceVins(),
"decort_vins_list": vins.DataSourceVinsList(), "decort_vins_list": vins.DataSourceVinsList(),
@ -96,8 +93,6 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_rg_list_lb": rg.DataSourceRgListLb(), "decort_rg_list_lb": rg.DataSourceRgListLb(),
"decort_rg_list_pfw": rg.DataSourceRgListPfw(), "decort_rg_list_pfw": rg.DataSourceRgListPfw(),
"decort_rg_list_vins": rg.DataSourceRgListVins(), "decort_rg_list_vins": rg.DataSourceRgListVins(),
"decort_rg_resource_consumption_list": rg.DataSourceRGResourceConsumptionList(),
"decort_rg_resource_consumption_get": rg.DataSourceRGResourceConsumptionGet(),
"decort_rg_usage": rg.DataSourceRgUsage(), "decort_rg_usage": rg.DataSourceRgUsage(),
"decort_disk_list_types_detailed": disks.DataSourceDiskListTypesDetailed(), "decort_disk_list_types_detailed": disks.DataSourceDiskListTypesDetailed(),
"decort_disk_list_types": disks.DataSourceDiskListTypes(), "decort_disk_list_types": disks.DataSourceDiskListTypes(),
@ -137,6 +132,14 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_flipgroup_list": flipgroup.DataSourceFlipGroupList(), "decort_flipgroup_list": flipgroup.DataSourceFlipGroupList(),
"decort_stack": stack.DataSourceStack(), "decort_stack": stack.DataSourceStack(),
"decort_stack_list": stack.DataSourceStackList(), "decort_stack_list": stack.DataSourceStackList(),
"decort_account_resource_consumption_list": account.DataSourceAccountResourceConsumptionList(),
"decort_account_resource_consumption_get": account.DataSourceAccountResourceConsumptionGet(),
"decort_kvmvm_list_deleted": kvmvm.DataSourceComputeListDeleted(),
"decort_kvmvm_vgpu_list": kvmvm.DataSourceComputeVGPUList(),
"decort_kvmvm_pci_device_list": kvmvm.DataSourceComputePCIDeviceList(),
"decort_k8s_wg_cloud_init": k8s.DataSourceK8sWgCloudInit(),
"decort_rg_resource_consumption_list": rg.DataSourceRGResourceConsumptionList(),
"decort_rg_resource_consumption_get": rg.DataSourceRGResourceConsumptionGet(),
"decort_cb_account": cb_account.DataSourceAccount(), "decort_cb_account": cb_account.DataSourceAccount(),
"decort_cb_account_list": cb_account.DataSourceAccountList(), "decort_cb_account_list": cb_account.DataSourceAccountList(),
@ -146,27 +149,13 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_cb_account_flipgroups_list": cb_account.DataSourceAccountFlipGroupsList(), "decort_cb_account_flipgroups_list": cb_account.DataSourceAccountFlipGroupsList(),
"decort_cb_account_rg_list": cb_account.DataSourceAccountRGList(), "decort_cb_account_rg_list": cb_account.DataSourceAccountRGList(),
"decort_cb_account_vins_list": cb_account.DataSourceAccountVinsList(), "decort_cb_account_vins_list": cb_account.DataSourceAccountVinsList(),
"decort_cb_account_resource_consumption_get": cb_account.DataSourceAccountResourceConsumptionGet(),
"decort_cb_account_resource_consumption_list": cb_account.DataSourceAccountResourceConsumptionList(),
"decort_cb_account_audits_list": cb_account.DataSourceAccountAuditsList(), "decort_cb_account_audits_list": cb_account.DataSourceAccountAuditsList(),
"decort_cb_extnet": cb_extnet.DataSourceExtnetCB(), "decort_cb_extnet": cb_extnet.DataSourceExtnetCB(),
"decort_cb_extnet_list": cb_extnet.DataSourceExtnetListCB(), "decort_cb_extnet_list": cb_extnet.DataSourceExtnetListCB(),
"decort_cb_extnet_default": cb_extnet.DataSourceExtnetDefaultCB(), "decort_cb_extnet_default": cb_extnet.DataSourceExtnetDefaultCB(),
"decort_cb_disk": cb_disks.DataSourceDisk(), "decort_cb_extnet_static_route_list": cb_extnet.DataSourceStaticRouteList(),
"decort_cb_disk_list": cb_disks.DataSourceDiskList(), "decort_cb_extnet_static_route": cb_extnet.DataSourceStaticRoute(),
"decort_cb_image": cb_image.DataSourceImage(),
"decort_cb_grid": cb_grid.DataSourceGrid(),
"decort_cb_grid_list": cb_grid.DataSourceGridList(),
"decort_cb_image_list": cb_image.DataSourceImageList(),
"decort_cb_image_list_stacks": cb_image.DataSourceImageListStacks(),
"decort_cb_pcidevice": cb_pcidevice.DataSourcePcidevice(),
"decort_cb_pcidevice_list": cb_pcidevice.DataSourcePcideviceList(),
"decort_cb_sep_list": cb_sep.DataSourceSepList(),
"decort_cb_sep": cb_sep.DataSourceSep(),
"decort_cb_sep_consumption": cb_sep.DataSourceSepConsumption(),
"decort_cb_sep_disk_list": cb_sep.DataSourceSepDiskList(),
"decort_cb_sep_config": cb_sep.DataSourceSepConfig(),
"decort_cb_sep_pool": cb_sep.DataSourceSepPool(),
"decort_cb_vgpu": cb_vgpu.DataSourceVGPU(),
"decort_cb_rg_list": cb_rg.DataSourceRgList(),
} }
} }

@ -36,17 +36,19 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins"
cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account"
cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks" // cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks"
cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet"
cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image" // cb_flipgroup "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/flipgroup"
cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s" // cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image"
cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm" // cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s"
cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice" // cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm"
cb_pfw "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pfw" // cb_lb "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/lb"
cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg" // cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep" // cb_pfw "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pfw"
cb_snapshot "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/snapshot" // cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg"
cb_vins "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vins" // cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep"
// cb_snapshot "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/snapshot"
// cb_vins "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vins"
) )
func newResourcesMap() map[string]*schema.Resource { func newResourcesMap() map[string]*schema.Resource {
@ -76,20 +78,27 @@ func newResourcesMap() map[string]*schema.Resource {
"decort_cb_account": cb_account.ResourceAccount(), "decort_cb_account": cb_account.ResourceAccount(),
"decort_cb_extnet": cb_extnet.ResourceExtnetCB(), "decort_cb_extnet": cb_extnet.ResourceExtnetCB(),
"decort_cb_disk": cb_disks.ResourceDisk(), // "decort_cb_disk": cb_disks.ResourceDisk(),
"decort_cb_image": cb_image.ResourceImage(), // "decort_cb_image": cb_image.ResourceImage(),
"decort_cb_virtual_image": cb_image.ResourceVirtualImage(), // "decort_cb_virtual_image": cb_image.ResourceVirtualImage(),
"decort_cb_cdrom_image": cb_image.ResourceCDROMImage(), // "decort_cb_cdrom_image": cb_image.ResourceCDROMImage(),
"decort_cb_delete_images": cb_image.ResourceDeleteImages(), // "decort_cb_delete_images": cb_image.ResourceDeleteImages(),
"decort_cb_pcidevice": cb_pcidevice.ResourcePcidevice(), // "decort_cb_pcidevice": cb_pcidevice.ResourcePcidevice(),
"decort_cb_sep": cb_sep.ResourceSep(), // "decort_cb_sep": cb_sep.ResourceSep(),
"decort_cb_sep_config": cb_sep.ResourceSepConfig(), // "decort_cb_sep_config": cb_sep.ResourceSepConfig(),
"decort_cb_resgroup": cb_rg.ResourceResgroup(), // "decort_cb_resgroup": cb_rg.ResourceResgroup(),
"decort_cb_kvmvm": cb_kvmvm.ResourceCompute(), // "decort_cb_kvmvm": cb_kvmvm.ResourceCompute(),
"decort_cb_vins": cb_vins.ResourceVins(), // "decort_cb_vins": cb_vins.ResourceVins(),
"decort_cb_pfw": cb_pfw.ResourcePfw(), // "decort_cb_pfw": cb_pfw.ResourcePfw(),
"decort_cb_k8s": cb_k8s.ResourceK8s(), // "decort_cb_k8s": cb_k8s.ResourceK8s(),
"decort_cb_k8s_wg": cb_k8s.ResourceK8sWg(), // "decort_cb_k8s_wg": cb_k8s.ResourceK8sWg(),
"decort_cb_snapshot": cb_snapshot.ResourceSnapshot(), // "decort_cb_snapshot": cb_snapshot.ResourceSnapshot(),
// "decort_cb_flipgroup": cb_flipgroup.ResourceFlipgroup(),
// "decort_cb_lb": cb_lb.ResourceLB(),
// "decort_cb_lb_backend": cb_lb.ResourceLBBackend(),
// "decort_cb_lb_backend_server": cb_lb.ResourceLBBackendServer(),
// "decort_cb_lb_frontend": cb_lb.ResourceLBFrontend(),
// "decort_cb_lb_frontend_bind": cb_lb.ResourceLBFrontendBind(),
"decort_cb_extnet_static_route": cb_extnet.ResourceStaticRoute(),
} }
} }

@ -49,8 +49,8 @@ func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.Resou
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenBasicServiceSnapshots(basicServiceSnapshotList)) d.Set("items", flattenBasicServiceSnapshotsList(basicServiceSnapshotList))
d.Set("entry_count", basicServiceSnapshotList.EntryCount)
return nil return nil
} }

@ -111,7 +111,7 @@ func flattenBasicServiceComputes(bscs bservice.ListComputes) []map[string]interf
} }
func flattenBasicServiceSnapshots(bsrvss bservice.ListSnapshots) []map[string]interface{} { func flattenBasicServiceSnapshots(bsrvss bservice.ListSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0, len(bsrvss))
for _, bsrvs := range bsrvss { for _, bsrvs := range bsrvss {
temp := map[string]interface{}{ temp := map[string]interface{}{
"guid": bsrvs.GUID, "guid": bsrvs.GUID,
@ -123,3 +123,17 @@ func flattenBasicServiceSnapshots(bsrvss bservice.ListSnapshots) []map[string]in
} }
return res return res
} }
func flattenBasicServiceSnapshotsList(bsrvss *bservice.ListInfoSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(bsrvss.Data))
for _, bsrvs := range bsrvss.Data {
temp := map[string]interface{}{
"guid": bsrvs.GUID,
"label": bsrvs.Label,
"timestamp": bsrvs.Timestamp,
"valid": bsrvs.Valid,
}
res = append(res, temp)
}
return res
}

@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
) )
func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListSnapshots, error) { func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListInfoSnapshots, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
var id uint64 var id uint64

@ -0,0 +1,396 @@
package k8s
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceK8sCPSchemaV1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the cluster.",
},
"rg_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "Resource group ID that this instance belongs to.",
},
"k8sci_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "ID of the k8s catalog item to base this instance on.",
},
"network_plugin": {
Type: schema.TypeString,
Required: true,
Description: "Network plugin to be used",
ValidateFunc: validation.StringInSlice([]string{"flannel", "weavenet", "calico"}, true),
},
"num": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntInSlice([]int{1, 3}),
Description: "Number of VMs to create. Can be either 1 or 3",
},
"cpu": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Node CPU count.",
},
"ram": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Node RAM in MB.",
},
"disk": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Node boot disk size in GB.",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Storage Endpoint ID",
},
"sep_pool": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Storage Endpoint Pool",
},
"with_lb": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Create k8s with load balancer if true.",
},
"extnet_only": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Use only selected ExtNet for infrastructure connections",
},
// /4.4.0
"cloud_init": {
Type: schema.TypeString,
Optional: true,
Description: "Meta data for working group computes, format YAML 'user_data': 1111",
},
"join_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to configure the behavior and settings for joining a node to a cluster. It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting.",
},
"kube_proxy_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster. It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations. insert a valid JSON string with all levels of nesting.",
},
"kubelet_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster. It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations. insert a valid JSON string with all levels of nesting.",
},
"cluster_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to define global settings and configurations for the entire cluster. It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations. insert a valid JSON string with all levels of nesting.",
},
"init_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to define settings and actions that should be performed before any other component in the cluster starts. It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting.",
},
"additional_sans": {
Type: schema.TypeList,
Optional: true,
Description: "Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"ha_mode": {
Type: schema.TypeBool,
Optional: true,
Description: "Use Highly Available schema for LB deploy",
},
"lb_sysctl_params": {
Type: schema.TypeString,
Optional: true,
Description: "Custom sysctl values for Load Balancer instance. Applied on boot.",
},
"oidc_cert": {
Type: schema.TypeString,
Optional: true,
Description: "insert ssl certificate in x509 pem format",
},
////
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Description: "Text description of this instance.",
},
"start": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Start k8s cluster.",
},
"detailed_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"interfaces": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"def_gw": {
Type: schema.TypeString,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"natable_vins_ip": {
Type: schema.TypeString,
Computed: true,
},
"natable_vins_network": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"master_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Master group ID.",
},
"master_name": {
Type: schema.TypeString,
Computed: true,
Description: "Master group name.",
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"k8s_acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"rg_acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"bservice_id": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"k8s_ci_name": {
Type: schema.TypeString,
Computed: true,
},
"lb_id": {
Type: schema.TypeInt,
Computed: true,
},
"k8s_id": {
Type: schema.TypeInt,
Computed: true,
},
"lb_ip": {
Type: schema.TypeString,
Computed: true,
Description: "IP address of default load balancer.",
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"kubeconfig": {
Type: schema.TypeString,
Computed: true,
Description: "Kubeconfig for cluster access.",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "ID of default vins for this instace.",
},
},
}
}

@ -199,6 +199,12 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
createReq.ExtNetID = 0 createReq.ExtNetID = 0
} }
if vins, ok := d.GetOk("vins_id"); ok {
createReq.VinsId = uint64(vins.(int))
} else {
createReq.VinsId = 0
}
if desc, ok := d.GetOk("desc"); ok { if desc, ok := d.GetOk("desc"); ok {
createReq.Description = desc.(string) createReq.Description = desc.(string)
} }

@ -158,9 +158,9 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
createReq.JoinConfiguration = joinConfig.(string) createReq.JoinConfiguration = joinConfig.(string)
} }
if cloudInit, ok := d.GetOk("cloud_init"); ok { // if cloudInit, ok := d.GetOk("cloud_init"); ok {
createReq.UserData = cloudInit.(string) // createReq.UserData = cloudInit.(string)
} // }
if initConfig, ok := d.GetOk("init_config"); ok { if initConfig, ok := d.GetOk("init_config"); ok {
createReq.InitConfiguration = initConfig.(string) createReq.InitConfiguration = initConfig.(string)
@ -185,6 +185,12 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
createReq.ExtNetID = 0 createReq.ExtNetID = 0
} }
if vins, ok := d.GetOk("vins_id"); ok {
createReq.VinsId = uint64(vins.(int))
} else {
createReq.VinsId = 0
}
if desc, ok := d.GetOk("desc"); ok { if desc, ok := d.GetOk("desc"); ok {
createReq.Description = desc.(string) createReq.Description = desc.(string)
} }
@ -625,12 +631,6 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
Default: false, Default: false,
Description: "Use only selected ExtNet for infrastructure connections", Description: "Use only selected ExtNet for infrastructure connections",
}, },
///4.4.0
"cloud_init": {
Type: schema.TypeString,
Optional: true,
Description: "Meta data for working group computes, format YAML 'user_data': 1111",
},
"join_config": { "join_config": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -794,6 +794,7 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
}, },
"vins_id": { "vins_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true,
Computed: true, Computed: true,
Description: "ID of default vins for this instace.", Description: "ID of default vins for this instace.",
}, },
@ -802,7 +803,7 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
func ResourceK8sCP() *schema.Resource { func ResourceK8sCP() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
SchemaVersion: 1, SchemaVersion: 2,
CreateContext: resourceK8sCPCreate, CreateContext: resourceK8sCPCreate,
ReadContext: resourceK8sCPRead, ReadContext: resourceK8sCPRead,
@ -822,5 +823,12 @@ func ResourceK8sCP() *schema.Resource {
}, },
Schema: resourceK8sCPSchemaMake(), Schema: resourceK8sCPSchemaMake(),
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceK8sCPSchemaV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceK8sCPStateUpgradeV1,
Version: 1,
},
},
} }
} }

@ -0,0 +1,15 @@
package k8s
import (
"context"
log "github.com/sirupsen/logrus"
)
func resourceK8sCPStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceK8sCPStateUpgradeV1: upgrading state")
delete(rawState, "cloud_init")
return rawState, nil
}

@ -393,7 +393,7 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
} }
func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rg, err := utilityDataResgroupCheckPresence(ctx, d, m) rg, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") // ensure ID is empty in this case d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err) return diag.FromErr(err)

@ -82,8 +82,17 @@ func dataSourceRgAffinityGroupsListSchemaMake() map[string]*schema.Schema {
"ids": { "ids": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Elem: &schema.Schema{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"node_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true,
},
},
}, },
}, },
}, },

@ -461,7 +461,7 @@ func flattenRgListLb(listLb *rg.ListLB) []map[string]interface{} {
} }
func flattenRgListPfw(listPfw *rg.ListPortForwards) []map[string]interface{} { func flattenRgListPfw(listPfw *rg.ListPortForwards) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len (listPfw.Data)) res := make([]map[string]interface{}, 0, len(listPfw.Data))
for _, pfw := range listPfw.Data { for _, pfw := range listPfw.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"public_port_end": pfw.PublicPortEnd, "public_port_end": pfw.PublicPortEnd,
@ -538,10 +538,25 @@ func flattenRgAffinityGroupComputes(list rg.ListAffinityGroupsComputes) []map[st
func flattenRgListGroups(list *rg.ListAffinityGroups) []map[string]interface{} { func flattenRgListGroups(list *rg.ListAffinityGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list.Data)) res := make([]map[string]interface{}, 0, len(list.Data))
for groupKey, groupVal := range list.Data { for _, groupVal := range list.Data {
for label, ag := range groupVal {
temp := map[string]interface{}{ temp := map[string]interface{}{
"label": groupKey, "label": label,
"ids": groupVal, "ids": flattenRgAffinityListGroup(ag),
}
res = append(res, temp)
}
}
return res
}
func flattenRgAffinityListGroup(list rg.ListAffinityGroup) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list))
for _, ag := range list {
temp := map[string]interface{}{
"id": ag.ID,
"node_id": ag.NodeID,
} }
res = append(res, temp) res = append(res, temp)
} }

@ -185,7 +185,6 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
} }
} }
} }
} }
if defNet, ok := d.GetOk("def_net"); ok { if defNet, ok := d.GetOk("def_net"); ok {
@ -380,7 +379,7 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
} }
if hasChanged { if hasChanged {
rgData, err = utilityDataResgroupCheckPresence(ctx, d, m) rgData, err = utilityResgroupCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
@ -789,14 +788,6 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
Schema: aclSchemaMake(), Schema: aclSchemaMake(),
}, },
}, },
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": { "deleted_by": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

@ -63,21 +63,3 @@ func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m
return rgData, nil return rgData, nil
} }
func utilityDataResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.RecordResourceGroup, error) {
c := m.(*controller.ControllerCfg)
req := rg.GetRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
rgData, err := c.CloudAPI().RG().Get(ctx, req)
if err != nil {
return nil, err
}
return rgData, nil
}

@ -1,119 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package account
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceAccountComputeSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"cpus": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"compute_id": {
Type: schema.TypeInt,
Computed: true,
},
"compute_name": {
Type: schema.TypeString,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"registered": {
Type: schema.TypeBool,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"total_disks_size": {
Type: schema.TypeInt,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"user_managed": {
Type: schema.TypeBool,
Computed: true,
},
"vins_connected": {
Type: schema.TypeInt,
Computed: true,
},
}
}

@ -1,262 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package account
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceAccountSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Required: true,
},
"dc_location": {
Type: schema.TypeString,
Computed: true,
},
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"current": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeInt,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeInt,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
// "meta": {
// Type: schema.TypeList,
// Computed: true,
// Elem: &schema.Schema{
// Type: schema.TypeString,
// },
// },
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"company": {
Type: schema.TypeString,
Computed: true,
},
"companyurl": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deactivation_time": {
Type: schema.TypeFloat,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"displayname": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"resource_limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cu_c": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_i": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_m": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_np": {
Type: schema.TypeFloat,
Computed: true,
},
"gpu_units": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
"send_access_emails": {
Type: schema.TypeBool,
Computed: true,
},
// "service_account": {
// Type: schema.TypeBool,
// Computed: true,
// },
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"version": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
return res
}

@ -1,123 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package account
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceAccountFlipGroupSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"client_type": {
Type: schema.TypeString,
Computed: true,
},
"conn_type": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"fg_id": {
Type: schema.TypeInt,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"fg_name": {
Type: schema.TypeString,
Computed: true,
},
"net_id": {
Type: schema.TypeInt,
Computed: true,
},
"net_type": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
}
}

@ -1,189 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package account
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceAccountItemSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"dc_location": {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"company": {
Type: schema.TypeString,
Computed: true,
},
"companyurl": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deactivation_time": {
Type: schema.TypeFloat,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"displayname": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"resource_limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cu_c": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_i": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_m": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_np": {
Type: schema.TypeFloat,
Computed: true,
},
"gpu_units": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
"send_access_emails": {
Type: schema.TypeBool,
Computed: true,
},
"service_account": {
Type: schema.TypeBool,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"version": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
}

@ -56,6 +56,14 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Default: true, Default: true,
Description: "if true send emails when a user is granted access to resources", Description: "if true send emails when a user is granted access to resources",
}, },
"uniq_pools": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"users": { "users": {
Type: schema.TypeList, Type: schema.TypeList,
Optional: true, Optional: true,
@ -77,6 +85,18 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
}, },
}, },
}, },
"cpu_allocation_parameter": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "set cpu allocation parameter",
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
Description: "set cpu allocation ratio",
},
"restore": { "restore": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
@ -91,6 +111,7 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
"enable": { "enable": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: true,
Description: "enable/disable account", Description: "enable/disable account",
}, },
"resource_limits": { "resource_limits": {
@ -106,6 +127,10 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Computed: true, Computed: true,
}, },
"cu_d": { "cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_dm": {
Type: schema.TypeFloat, Type: schema.TypeFloat,
Optional: true, Optional: true,
Computed: true, Computed: true,
@ -142,78 +167,6 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"current": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeInt,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeInt,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
"ckey": { "ckey": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@ -293,10 +246,13 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
// "service_account": { "resource_types": {
// Type: schema.TypeBool, Type: schema.TypeList,
// Computed: true, Computed: true,
// }, Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"status": { "status": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

@ -1,107 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package account
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceAccountVinsSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"computes": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"external_ip": {
Type: schema.TypeString,
Computed: true,
},
"vin_id": {
Type: schema.TypeInt,
Computed: true,
},
"vin_name": {
Type: schema.TypeString,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"pri_vnf_dev_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
}
}

@ -1,56 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package account
const accountAddUserAPI = "/restmachine/cloudbroker/account/addUser"
const accountAuditsAPI = "/restmachine/cloudbroker/account/audits"
const accountCreateAPI = "/restmachine/cloudbroker/account/create"
const accountDeleteAPI = "/restmachine/cloudbroker/account/delete"
const accountDeleteUserAPI = "/restmachine/cloudbroker/account/deleteUser"
const accountDisableAPI = "/restmachine/cloudbroker/account/disable"
const accountEnableAPI = "/restmachine/cloudbroker/account/enable"
const accountGetAPI = "/restmachine/cloudbroker/account/get"
const accountListAPI = "/restmachine/cloudbroker/account/list"
const accountListComputesAPI = "/restmachine/cloudbroker/account/listComputes"
const accountListDeletedAPI = "/restmachine/cloudbroker/account/listDeleted"
const accountListDisksAPI = "/restmachine/cloudbroker/account/listDisks"
const accountListFlipGroupsAPI = "/restmachine/cloudbroker/account/listFlipGroups"
const accountListRGAPI = "/restmachine/cloudbroker/account/listRG"
const accountListVinsAPI = "/restmachine/cloudbroker/account/listVins"
const accountRestoreAPI = "/restmachine/cloudbroker/account/restore"
const accountUpdateAPI = "/restmachine/cloudbroker/account/update"
const accountUpdateUserAPI = "/restmachine/cloudbroker/account/updateUser"
//currently unused
//const accountsEnableAPI = "/restmachine/cloudbroker/account/enableAccounts"
//const accountsDisableAPI = "/restmachine/cloudbroker/account/disableAccounts"
//const accountsDeleteAPI = "/restmachine/cloudbroker/account/deleteAccounts"

@ -1,8 +1,9 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Nikita Sorokin, <nesorokin@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -66,3 +67,174 @@ func DataSourceAccount() *schema.Resource {
Schema: dataSourceAccountSchemaMake(), Schema: dataSourceAccountSchemaMake(),
} }
} }
func dataSourceAccountSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Required: true,
},
"dc_location": {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"company": {
Type: schema.TypeString,
Computed: true,
},
"companyurl": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_parameter": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deactivation_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"displayname": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"resource_limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cu_c": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_dm": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_i": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_m": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_np": {
Type: schema.TypeFloat,
Computed: true,
},
"gpu_units": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
"resource_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"send_access_emails": {
Type: schema.TypeBool,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"uniq_pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"version": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
}

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -65,7 +65,28 @@ func dataSourceAccountAuditsListSchemaMake() map[string]*schema.Schema {
Computed: true, Computed: true,
Description: "Search Result", Description: "Search Result",
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: dataSourceAccountAuditSchemaMake(), Schema: map[string]*schema.Schema{
"call": {
Type: schema.TypeString,
Computed: true,
},
"responsetime": {
Type: schema.TypeFloat,
Computed: true,
},
"statuscode": {
Type: schema.TypeInt,
Computed: true,
},
"timestamp": {
Type: schema.TypeFloat,
Computed: true,
},
"user": {
Type: schema.TypeString,
Computed: true,
},
},
}, },
}, },
} }

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -49,6 +49,7 @@ func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceDa
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenAccountComputesList(accountComputesList)) d.Set("items", flattenAccountComputesList(accountComputesList))
d.Set("entry_count", accountComputesList.EntryCount)
return nil return nil
} }
@ -60,18 +61,154 @@ func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema {
Required: true, Required: true,
Description: "ID of the account", Description: "ID of the account",
}, },
"compute_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by compute ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by compute name",
},
"rg_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by RG name",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by tech. status",
},
"ip_address": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by IP address",
},
"extnet_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by extnet name",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by extnet ID",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": { "items": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Description: "Search Result", Description: "Search Result",
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: dataSourceAccountComputeSchemaMake(), Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
}, },
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"cpus": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"compute_id": {
Type: schema.TypeInt,
Computed: true,
},
"compute_name": {
Type: schema.TypeString,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"registered": {
Type: schema.TypeBool,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"total_disks_size": {
Type: schema.TypeInt,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"user_managed": {
Type: schema.TypeBool,
Computed: true,
},
"vins_connected": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
}, },
} }
return res return res
} }
func DataSourceAccountComputesList() *schema.Resource { func DataSourceAccountComputesList() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
SchemaVersion: 1, SchemaVersion: 1,

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -40,6 +40,21 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func DataSourceAccountDeletedList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceAccountDeletedListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountListDeletedSchemaMake(),
}
}
func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountDeletedList, err := utilityAccountDeletedListCheckPresence(ctx, d, m) accountDeletedList, err := utilityAccountDeletedListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
@ -49,21 +64,221 @@ func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceDat
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenListDeleted(accountDeletedList)) d.Set("items", flattenListDeleted(accountDeletedList))
d.Set("entry_count", accountDeletedList.EntryCount)
return nil return nil
} }
func DataSourceAccountDeletedList() *schema.Resource { func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema {
return &schema.Resource{ return map[string]*schema.Schema{
SchemaVersion: 1, "by_id": {
Type: schema.TypeInt,
ReadContext: dataSourceAccountDeletedListRead, Optional: true,
Description: "Filter by ID",
Timeouts: &schema.ResourceTimeout{ },
Read: &constants.Timeout30s, "name": {
Default: &constants.Timeout60s, Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"acl": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by ACL",
},
"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: map[string]*schema.Schema{
"dc_location": {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"company": {
Type: schema.TypeString,
Computed: true,
},
"companyurl": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_parameter": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deactivation_time": {
Type: schema.TypeFloat,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"displayname": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"resource_limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cu_c": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_dm": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_i": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_m": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_np": {
Type: schema.TypeFloat,
Computed: true,
},
"gpu_units": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
"resource_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"send_access_emails": {
Type: schema.TypeBool,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"uniq_pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"version": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
}, },
Schema: dataSourceAccountListSchemaMake(),
} }
} }

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -48,6 +48,7 @@ func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenAccountDisksList(accountDisksList)) d.Set("items", flattenAccountDisksList(accountDisksList))
d.Set("entry_count", accountDisksList.EntryCount)
return nil return nil
} }
@ -59,13 +60,76 @@ func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema {
Required: true, Required: true,
Description: "ID of the account", Description: "ID of the account",
}, },
"disk_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by disk ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by disk name",
},
"disk_max_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by disk max size",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by disk type",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": { "items": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Description: "Search Result", Description: "Search Result",
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: dataSourceAccountDiskSchemaMake(), Schema: map[string]*schema.Schema{
"disk_id": {
Type: schema.TypeInt,
Computed: true,
},
"disk_name": {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
}, },
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
}, },
} }
return res return res

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -49,6 +49,7 @@ func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.Resource
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList)) d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList))
d.Set("entry_count", accountFlipGroupsList.EntryCount)
return nil return nil
} }
@ -60,13 +61,142 @@ func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema {
Required: true, Required: true,
Description: "ID of the account", Description: "ID of the account",
}, },
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ViNS ID",
},
"vins_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by ViNS name",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by extnet ID",
},
"by_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by IP",
},
"flipgroup_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by flipgroup ID",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": { "items": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Description: "Search Result", Description: "Search Result",
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: dataSourceAccountFlipGroupSchemaMake(), Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"client_type": {
Type: schema.TypeString,
Computed: true,
},
"conn_type": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"fg_id": {
Type: schema.TypeInt,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"fg_name": {
Type: schema.TypeString,
Computed: true,
},
"net_id": {
Type: schema.TypeInt,
Computed: true,
}, },
"net_type": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
}, },
} }
return res return res

@ -0,0 +1,236 @@
/*
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 account
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 dataSourceAccountResourceConsumptionGetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountResourceConsumptionRec, err := utilityAccountResourceConsumptionGetCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
flattenResourceConsumption(d, accountResourceConsumptionRec)
return nil
}
func dataSourceAccountResourceConsumptionGetSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Required: true,
},
"consumed": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeFloat,
Computed: true,
},
"disksizemax": {
Type: schema.TypeFloat,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeFloat,
Computed: true,
},
"disksizemax": {
Type: schema.TypeFloat,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"resource_limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cu_c": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_dm": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_i": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_m": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_np": {
Type: schema.TypeFloat,
Computed: true,
},
"gpu_units": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
}
return res
}
func DataSourceAccountResourceConsumptionGet() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceAccountResourceConsumptionGetRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountResourceConsumptionGetSchemaMake(),
}
}

@ -3,6 +3,7 @@ Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Nikita Sorokin, <nesorokin@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -40,6 +41,21 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func DataSourceAccountList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceAccountListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountListSchemaMake(),
}
}
func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountList, err := utilityAccountListCheckPresence(ctx, d, m) accountList, err := utilityAccountListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
@ -49,12 +65,33 @@ func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m in
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenAccountList(accountList)) d.Set("items", flattenAccountList(accountList))
d.Set("entry_count", accountList.EntryCount)
return nil return nil
} }
func dataSourceAccountListSchemaMake() map[string]*schema.Schema { func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{ res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"acl": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by ACL",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"page": { "page": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
@ -69,24 +106,187 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: dataSourceAccountItemSchemaMake(), Schema: map[string]*schema.Schema{
"dc_location": {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
}, },
}, },
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"company": {
Type: schema.TypeString,
Computed: true,
},
"companyurl": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_parameter": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deactivation_time": {
Type: schema.TypeFloat,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"displayname": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"resource_limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cu_c": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_dm": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_i": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_m": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_np": {
Type: schema.TypeFloat,
Computed: true,
},
"gpu_units": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
"resource_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"send_access_emails": {
Type: schema.TypeBool,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"uniq_pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"version": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
} }
return res return res
} }
func DataSourceAccountList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceAccountListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountListSchemaMake(),
}
}

@ -1,8 +1,9 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -31,31 +32,39 @@ Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/w
package account package account
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" import (
"context"
func dataSourceAccountRGSchemaMake() map[string]*schema.Schema { "github.com/google/uuid"
return map[string]*schema.Schema{ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"computes": { "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceAccountResourceConsumptionListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountResourceConsumptionList, err := utilityAccountResourceConsumptionListCheckPresence(ctx, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccResourceConsumption(accountResourceConsumptionList))
d.Set("entry_count", accountResourceConsumptionList.EntryCount)
return nil
}
func dataSourceAccountResourceConsumptionListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"items": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"started": { "account_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"stopped": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"consumed": { "consumed": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
@ -66,7 +75,11 @@ func dataSourceAccountRGSchemaMake() map[string]*schema.Schema {
Computed: true, Computed: true,
}, },
"disksize": { "disksize": {
Type: schema.TypeInt, Type: schema.TypeFloat,
Computed: true,
},
"disksizemax": {
Type: schema.TypeFloat,
Computed: true, Computed: true,
}, },
"extips": { "extips": {
@ -85,38 +98,29 @@ func dataSourceAccountRGSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
}, "seps": {
},
},
"limits": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"cpu": { "sep_id": {
Type: schema.TypeInt, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"disksize": { "data_name": {
Type: schema.TypeInt, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"extips": { "disk_size": {
Type: schema.TypeInt, Type: schema.TypeFloat,
Computed: true, Computed: true,
}, },
"exttraffic": { "disk_size_max": {
Type: schema.TypeInt, Type: schema.TypeFloat,
Computed: true, Computed: true,
}, },
"gpu": {
Type: schema.TypeInt,
Computed: true,
}, },
"ram": { },
Type: schema.TypeInt,
Computed: true,
}, },
}, },
}, },
@ -131,7 +135,11 @@ func dataSourceAccountRGSchemaMake() map[string]*schema.Schema {
Computed: true, Computed: true,
}, },
"disksize": { "disksize": {
Type: schema.TypeInt, Type: schema.TypeFloat,
Computed: true,
},
"disksizemax": {
Type: schema.TypeFloat,
Computed: true, Computed: true,
}, },
"extips": { "extips": {
@ -150,56 +158,55 @@ func dataSourceAccountRGSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
}, "seps": {
}, Type: schema.TypeList,
},
},
},
},
"created_by": {
Type: schema.TypeString,
Computed: true, Computed: true,
}, Elem: &schema.Resource{
"created_time": { Schema: map[string]*schema.Schema{
Type: schema.TypeInt, "sep_id": {
Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"deleted_by": { "data_name": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"deleted_time": { "disk_size": {
Type: schema.TypeInt, Type: schema.TypeFloat,
Computed: true, Computed: true,
}, },
"rg_id": { "disk_size_max": {
Type: schema.TypeInt, Type: schema.TypeFloat,
Computed: true, Computed: true,
}, },
"milestones": {
Type: schema.TypeInt,
Computed: true,
}, },
"rg_name": {
Type: schema.TypeString,
Computed: true,
}, },
"status": {
Type: schema.TypeString,
Computed: true,
}, },
"updated_by": {
Type: schema.TypeString,
Computed: true,
}, },
"updated_time": {
Type: schema.TypeInt,
Computed: true,
}, },
"vinses": { },
},
},
},
"entry_count": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
} }
return res
}
func DataSourceAccountResourceConsumptionList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceAccountResourceConsumptionListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountResourceConsumptionListSchemaMake(),
}
} }

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -40,6 +40,21 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func DataSourceAccountRGList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceAccountRGListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountRGListSchemaMake(),
}
}
func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountRGList, err := utilityAccountRGListCheckPresence(ctx, d, m) accountRGList, err := utilityAccountRGListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
@ -49,6 +64,7 @@ func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenAccountRGList(accountRGList)) d.Set("items", flattenAccountRGList(accountRGList))
d.Set("entry_count", accountRGList.EntryCount)
return nil return nil
} }
@ -60,6 +76,42 @@ func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema {
Required: true, Required: true,
Description: "ID of the account", Description: "ID of the account",
}, },
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ViNS ID",
},
"vm_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by VM ID",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"items": { "items": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
@ -68,21 +120,243 @@ func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema {
Schema: dataSourceAccountRGSchemaMake(), Schema: dataSourceAccountRGSchemaMake(),
}, },
}, },
"entry_count": {
Type: schema.TypeInt,
Optional: true,
},
} }
return res return res
} }
func DataSourceAccountRGList() *schema.Resource { func dataSourceAccountRGSchemaMake() map[string]*schema.Schema {
return &schema.Resource{ return map[string]*schema.Schema{
SchemaVersion: 1, "computes": {
Type: schema.TypeList,
ReadContext: dataSourceAccountRGListRead, Computed: true,
Elem: &schema.Resource{
Timeouts: &schema.ResourceTimeout{ Schema: map[string]*schema.Schema{
Read: &constants.Timeout30s, "started": {
Default: &constants.Timeout60s, Type: schema.TypeInt,
Computed: true,
},
"stopped": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"consumed": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeFloat,
Computed: true,
},
"disksizemax": {
Type: schema.TypeInt,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeInt,
Computed: true,
},
"disksizemax": {
Type: schema.TypeInt,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disksize": {
Type: schema.TypeInt,
Computed: true,
},
"disksizemax": {
Type: schema.TypeInt,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
},
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"vinses": {
Type: schema.TypeInt,
Computed: true,
}, },
Schema: dataSourceAccountRGListSchemaMake(),
} }
} }

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -49,6 +49,7 @@ func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenAccountVinsList(accountVinsList)) d.Set("items", flattenAccountVinsList(accountVinsList))
d.Set("entry_count", accountVinsList.EntryCount)
return nil return nil
} }
@ -60,13 +61,116 @@ func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema {
Required: true, Required: true,
Description: "ID of the account", Description: "ID of the account",
}, },
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ViNS ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"ext_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by external IP",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": { "items": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Description: "Search Result", Description: "Search Result",
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: dataSourceAccountVinsSchema(), Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
}, },
"computes": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"external_ip": {
Type: schema.TypeString,
Computed: true,
},
"vin_id": {
Type: schema.TypeInt,
Computed: true,
},
"vin_name": {
Type: schema.TypeString,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"pri_vnf_dev_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
}, },
} }
return res return res

@ -8,11 +8,12 @@ import (
func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount) { func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount) {
d.Set("dc_location", acc.DCLocation) d.Set("dc_location", acc.DCLocation)
// d.Set("resources", flattenAccResources(acc.Resources))
d.Set("ckey", acc.CKey) d.Set("ckey", acc.CKey)
d.Set("acl", flattenAccAcl(acc.ACL)) d.Set("acl", flattenAccAcl(acc.ACL))
d.Set("company", acc.Company) d.Set("company", acc.Company)
d.Set("companyurl", acc.CompanyURL) d.Set("companyurl", acc.CompanyURL)
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
d.Set("created_by", acc.CreatedBy) d.Set("created_by", acc.CreatedBy)
d.Set("created_time", acc.CreatedTime) d.Set("created_time", acc.CreatedTime)
d.Set("deactivation_time", acc.DeactivationTime) d.Set("deactivation_time", acc.DeactivationTime)
@ -23,8 +24,10 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
d.Set("account_id", acc.ID) d.Set("account_id", acc.ID)
d.Set("account_name", acc.Name) d.Set("account_name", acc.Name)
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits)) d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
d.Set("resource_types", acc.ResTypes)
d.Set("send_access_emails", acc.SendAccessEmails) d.Set("send_access_emails", acc.SendAccessEmails)
d.Set("status", acc.Status) d.Set("status", acc.Status)
d.Set("uniq_pools", acc.UniqPools)
d.Set("updated_time", acc.UpdatedTime) d.Set("updated_time", acc.UpdatedTime)
d.Set("version", acc.Version) d.Set("version", acc.Version)
d.Set("vins", acc.VINS) d.Set("vins", acc.VINS)
@ -32,12 +35,12 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) { func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
d.Set("dc_location", acc.DCLocation) d.Set("dc_location", acc.DCLocation)
// d.Set("resources", flattenAccResources(acc.Resources))
d.Set("ckey", acc.CKey) d.Set("ckey", acc.CKey)
// d.Set("meta", flattens.FlattenMeta(acc.))
d.Set("acl", flattenAccAcl(acc.ACL)) d.Set("acl", flattenAccAcl(acc.ACL))
d.Set("company", acc.Company) d.Set("company", acc.Company)
d.Set("companyurl", acc.CompanyURL) d.Set("companyurl", acc.CompanyURL)
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
d.Set("created_by", acc.CreatedBy) d.Set("created_by", acc.CreatedBy)
d.Set("created_time", acc.CreatedTime) d.Set("created_time", acc.CreatedTime)
d.Set("deactivation_time", acc.DeactivationTime) d.Set("deactivation_time", acc.DeactivationTime)
@ -48,9 +51,10 @@ func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
d.Set("account_id", acc.ID) d.Set("account_id", acc.ID)
d.Set("account_name", acc.Name) d.Set("account_name", acc.Name)
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits)) d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
d.Set("resource_types", acc.ResTypes)
d.Set("send_access_emails", acc.SendAccessEmails) d.Set("send_access_emails", acc.SendAccessEmails)
// d.Set("service_account", acc.ServiceAccount)
d.Set("status", acc.Status) d.Set("status", acc.Status)
d.Set("uniq_pools", acc.UniqPools)
d.Set("updated_time", acc.UpdatedTime) d.Set("updated_time", acc.UpdatedTime)
d.Set("version", acc.Version) d.Set("version", acc.Version)
d.Set("vins", acc.VINS) d.Set("vins", acc.VINS)
@ -94,7 +98,7 @@ func flattenAccRGComputes(argc account.Computes) []map[string]interface{} {
func flattenAccRGResources(argr account.RGResuorces) []map[string]interface{} { func flattenAccRGResources(argr account.RGResuorces) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
"consumed": flattenAccConsumed(argr.Consumed), "consumed": flattenAccResource(argr.Consumed),
"limits": flattenAccLimits(argr.Limits), "limits": flattenAccLimits(argr.Limits),
"reserved": flattenAccResource(argr.Reserved), "reserved": flattenAccResource(argr.Reserved),
} }
@ -102,39 +106,17 @@ func flattenAccRGResources(argr account.RGResuorces) []map[string]interface{} {
return res return res
} }
func flattenAccResources(r account.RecordResourceConsumption) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"current": flattenAccResource(r.Current),
"reserved": flattenAccResource(r.Reserved),
}
res = append(res, temp)
return res
}
func flattenAccConsumed(c account.Consumed) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cpu": c.CPU,
"disksize": c.DiskSize,
"extips": c.ExtIPs,
"exttraffic": c.ExtTraffic,
"gpu": c.GPU,
"ram": c.RAM,
}
res = append(res, temp)
return res
}
func flattenAccLimits(l account.Limits) []map[string]interface{} { func flattenAccLimits(l account.Limits) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
"cpu": l.CPU, "cpu": l.CPU,
"disksize": l.DiskSize, "disksize": l.DiskSize,
"disksizemax": l.DiskSizeMax,
"extips": l.ExtIPs, "extips": l.ExtIPs,
"exttraffic": l.ExtTraffic, "exttraffic": l.ExtTraffic,
"gpu": l.GPU, "gpu": l.GPU,
"ram": l.RAM, "ram": l.RAM,
"seps": l.SEPs,
} }
res = append(res, temp) res = append(res, temp)
return res return res
@ -145,10 +127,12 @@ func flattenAccResource(r account.Resource) []map[string]interface{} {
temp := map[string]interface{}{ temp := map[string]interface{}{
"cpu": r.CPU, "cpu": r.CPU,
"disksize": r.DiskSize, "disksize": r.DiskSize,
"disksizemax": r.DiskSizeMax,
"extips": r.ExtIPs, "extips": r.ExtIPs,
"exttraffic": r.ExtTraffic, "exttraffic": r.ExtTraffic,
"gpu": r.GPU, "gpu": r.GPU,
"ram": r.RAM, "ram": r.RAM,
"seps": flattenAccountSeps(r.SEPs),
} }
res = append(res, temp) res = append(res, temp)
return res return res
@ -175,6 +159,7 @@ func flattenRgResourceLimits(rl account.ResourceLimits) []map[string]interface{}
temp := map[string]interface{}{ temp := map[string]interface{}{
"cu_c": rl.CuC, "cu_c": rl.CuC,
"cu_d": rl.CuD, "cu_d": rl.CuD,
"cu_dm": rl.CuDM,
"cu_i": rl.CuI, "cu_i": rl.CuI,
"cu_m": rl.CuM, "cu_m": rl.CuM,
"cu_np": rl.CuNP, "cu_np": rl.CuNP,
@ -186,7 +171,7 @@ func flattenRgResourceLimits(rl account.ResourceLimits) []map[string]interface{}
} }
func flattenRgAcl(rgAcls []account.ACL) []map[string]interface{} { func flattenRgAcl(rgAcls []account.ACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, len(rgAcls))
for _, rgAcl := range rgAcls { for _, rgAcl := range rgAcls {
temp := map[string]interface{}{ temp := map[string]interface{}{
"explicit": rgAcl.Explicit, "explicit": rgAcl.Explicit,
@ -208,33 +193,26 @@ func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} {
"dc_location": acc.DCLocation, "dc_location": acc.DCLocation,
"ckey": acc.CKey, "ckey": acc.CKey,
"meta": flattens.FlattenMeta(acc.Meta), "meta": flattens.FlattenMeta(acc.Meta),
"acl": flattenRgAcl(acc.ACL), "acl": flattenRgAcl(acc.ACL),
"company": acc.Company, "company": acc.Company,
"companyurl": acc.CompanyURL, "companyurl": acc.CompanyURL,
"cpu_allocation_parameter": acc.CPUAllocationParameter,
"cpu_allocation_ratio": acc.CPUAllocationRatio,
"created_by": acc.CreatedBy, "created_by": acc.CreatedBy,
"created_time": acc.CreatedTime, "created_time": acc.CreatedTime,
"deactivation_time": acc.DeactivationTime, "deactivation_time": acc.DeactivationTime,
"deleted_by": acc.DeletedBy, "deleted_by": acc.DeletedBy,
"deleted_time": acc.DeletedTime, "deleted_time": acc.DeletedTime,
"displayname": acc.DisplayName, "displayname": acc.DisplayName,
"guid": acc.GUID, "guid": acc.GUID,
"account_id": acc.ID, "account_id": acc.ID,
"account_name": acc.Name, "account_name": acc.Name,
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits), "resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
"resource_types": acc.ResTypes,
"send_access_emails": acc.SendAccessEmails, "send_access_emails": acc.SendAccessEmails,
// "service_account": acc.ServiceAccount,
"status": acc.Status, "status": acc.Status,
"uniq_pools": acc.UniqPools,
"updated_time": acc.UpdatedTime, "updated_time": acc.UpdatedTime,
"version": acc.Version, "version": acc.Version,
"vins": acc.VINS, "vins": acc.VINS,
} }
@ -250,33 +228,26 @@ func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
"dc_location": acc.DCLocation, "dc_location": acc.DCLocation,
"ckey": acc.CKey, "ckey": acc.CKey,
"meta": flattens.FlattenMeta(acc.Meta), "meta": flattens.FlattenMeta(acc.Meta),
"acl": flattenRgAcl(acc.ACL), "acl": flattenRgAcl(acc.ACL),
"company": acc.Company, "company": acc.Company,
"companyurl": acc.CompanyURL, "companyurl": acc.CompanyURL,
"cpu_allocation_parameter": acc.CPUAllocationParameter,
"cpu_allocation_ratio": acc.CPUAllocationRatio,
"created_by": acc.CreatedBy, "created_by": acc.CreatedBy,
"created_time": acc.CreatedTime, "created_time": acc.CreatedTime,
"deactivation_time": acc.DeactivationTime, "deactivation_time": acc.DeactivationTime,
"deleted_by": acc.DeletedBy, "deleted_by": acc.DeletedBy,
"deleted_time": acc.DeletedTime, "deleted_time": acc.DeletedTime,
"displayname": acc.DisplayName, "displayname": acc.DisplayName,
"guid": acc.GUID, "guid": acc.GUID,
"account_id": acc.ID, "account_id": acc.ID,
"account_name": acc.Name, "account_name": acc.Name,
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits), "resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
"resource_types": acc.ResTypes,
"send_access_emails": acc.SendAccessEmails, "send_access_emails": acc.SendAccessEmails,
// "service_account": acc.ServiceAccount,
"status": acc.Status, "status": acc.Status,
"uniq_pools": acc.UniqPools,
"updated_time": acc.UpdatedTime, "updated_time": acc.UpdatedTime,
"version": acc.Version, "version": acc.Version,
"vins": acc.VINS, "vins": acc.VINS,
} }
@ -338,6 +309,7 @@ func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} {
"disk_name": ad.Name, "disk_name": ad.Name,
"pool_name": ad.Pool, "pool_name": ad.Pool,
"sep_id": ad.SepID, "sep_id": ad.SepID,
"shareable": ad.Shareable,
"size_max": ad.SizeMax, "size_max": ad.SizeMax,
"type": ad.Type, "type": ad.Type,
} }
@ -403,3 +375,39 @@ func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} {
} }
return res return res
} }
func flattenResourceConsumption(d *schema.ResourceData, acc *account.RecordResourceConsumption) {
d.Set("account_id", acc.AccountID)
d.Set("consumed", flattenAccResource(acc.Consumed))
d.Set("reserved", flattenAccResource(acc.Reserved))
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
}
func flattenAccountSeps(seps map[string]map[string]account.DiskUsage) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for sepKey, sepVal := range seps {
for dataKey, dataVal := range sepVal {
temp := map[string]interface{}{
"sep_id": sepKey,
"data_name": dataKey,
"disk_size": dataVal.DiskSize,
"disk_size_max": dataVal.DiskSizeMax,
}
res = append(res, temp)
}
}
return res
}
func flattenAccResourceConsumption(lrc *account.ListResources) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(lrc.Data))
for _, rc := range lrc.Data {
temp := map[string]interface{}{
"consumed": flattenAccResource(rc.Consumed),
"reserved": flattenAccResource(rc.Reserved),
"account_id": rc.AccountID,
}
res = append(res, temp)
}
return res
}

@ -1,219 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package account
type AccountAclRecord struct {
IsExplicit bool `json:"explicit"`
Guid string `json:"guid"`
Rights string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
UgroupID string `json:"userGroupId"`
}
type ResourceLimits struct {
CUC float64 `json:"CU_C"`
CUD float64 `json:"CU_D"`
CUI float64 `json:"CU_I"`
CUM float64 `json:"CU_M"`
CUNP float64 `json:"CU_NP"`
GpuUnits float64 `json:"gpu_units"`
}
type Account struct {
DCLocation string `json:"DCLocation"`
CKey string `jspn:"_ckey"`
Meta []interface{} `json:"_meta"`
Acl []AccountAclRecord `json:"acl"`
Company string `json:"company"`
CompanyUrl string `json:"companyurl"`
CreatedBy string `jspn:"createdBy"`
CreatedTime int `json:"createdTime"`
DeactiovationTime float64 `json:"deactivationTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
DisplayName string `json:"displayname"`
GUID int `json:"guid"`
ID int `json:"id"`
Name string `json:"name"`
ResourceLimits ResourceLimits `json:"resourceLimits"`
SendAccessEmails bool `json:"sendAccessEmails"`
ServiceAccount bool `json:"serviceAccount"`
Status string `json:"status"`
UpdatedTime int `json:"updatedTime"`
Version int `json:"version"`
Vins []int `json:"vins"`
}
type AccountList []Account
type Resource struct {
CPU int `json:"cpu"`
Disksize int `json:"disksize"`
Extips int `json:"extips"`
Exttraffic int `json:"exttraffic"`
GPU int `json:"gpu"`
RAM int `json:"ram"`
}
type Resources struct {
Current Resource `json:"Current"`
Reserved Resource `json:"Reserved"`
}
type AccountWithResources struct {
Account
Resources Resources `json:"Resources"`
}
type AccountCompute struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
CPUs int `json:"cpus"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
ComputeId int `json:"id"`
ComputeName string `json:"name"`
RAM int `json:"ram"`
Registered bool `json:"registered"`
RgId int `json:"rgId"`
RgName string `json:"rgName"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
TotalDisksSize int `json:"totalDisksSize"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
UserManaged bool `json:"userManaged"`
VinsConnected int `json:"vinsConnected"`
}
type AccountComputesList []AccountCompute
type AccountDisk struct {
ID int `json:"id"`
Name string `json:"name"`
Pool string `json:"pool"`
SepId int `json:"sepId"`
SizeMax int `json:"sizeMax"`
Type string `json:"type"`
}
type AccountDisksList []AccountDisk
type AccountVin struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
Computes int `json:"computes"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID int `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
PriVnfDevId int `json:"priVnfDevId"`
RgId int `json:"rgId"`
RgName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
}
type AccountVinsList []AccountVin
type AccountAudit struct {
Call string `json:"call"`
ResponseTime float64 `json:"responsetime"`
StatusCode int `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
}
type AccountAuditsList []AccountAudit
type AccountRGComputes struct {
Started int `json:"Started"`
Stopped int `json:"Stopped"`
}
type AccountRGResources struct {
Consumed Resource `json:"Consumed"`
Limits Resource `json:"Limits"`
Reserved Resource `json:"Reserved"`
}
type AccountRG struct {
Computes AccountRGComputes `json:"Computes"`
Resources AccountRGResources `json:"Resources"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
RGID int `json:"id"`
Milestones int `json:"milestones"`
RGName string `json:"name"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
Vinses int `json:"vinses"`
}
type AccountRGList []AccountRG
type AccountFlipGroup struct {
AccountId int `json:"accountId"`
ClientType string `json:"clientType"`
ConnType string `json:"connType"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DefaultGW string `json:"defaultGW"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
Desc string `json:"desc"`
GID int `json:"gid"`
GUID int `json:"guid"`
ID int `json:"id"`
IP string `json:"ip"`
Milestones int `json:"milestones"`
Name string `json:"name"`
NetID int `json:"netId"`
NetType string `json:"netType"`
NetMask int `json:"netmask"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
}
type AccountFlipGroupsList []AccountFlipGroup

@ -42,12 +42,15 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "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/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
) )
func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceAccountCreate") log.Debugf("resourseAccountCreate")
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := account.CreateRequest{} req := account.CreateRequest{}
req.Name = d.Get("account_name").(string) req.Name = d.Get("account_name").(string)
@ -56,57 +59,63 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
if emailaddress, ok := d.GetOk("emailaddress"); ok { if emailaddress, ok := d.GetOk("emailaddress"); ok {
req.EmailAddress = emailaddress.(string) req.EmailAddress = emailaddress.(string)
} }
if sendAccessEmails, ok := d.GetOk("send_access_emails"); ok { if sendAccessEmails, ok := d.GetOk("send_access_emails"); ok {
req.SendAccessEmails = sendAccessEmails.(bool) req.SendAccessEmails = sendAccessEmails.(bool)
} }
if uniqPools, ok := d.GetOk("uniq_pools"); ok {
uniqPools := uniqPools.([]interface{})
for _, pool := range uniqPools {
req.UniqPools = append(req.UniqPools, pool.(string))
}
}
if resLimits, ok := d.GetOk("resource_limits"); ok { if resLimits, ok := d.GetOk("resource_limits"); ok {
resLimit := resLimits.([]interface{})[0] resLimits := resLimits.([]interface{})[0]
resLimitConv := resLimit.(map[string]interface{}) resLimitsConv := resLimits.(map[string]interface{})
if resLimitConv["cu_m"] != nil { if resLimitsConv["cu_m"] != nil {
maxMemCap := int64(resLimitConv["cu_m"].(float64)) maxMemCap := int64(resLimitsConv["cu_m"].(float64))
if maxMemCap == 0 { if maxMemCap == 0 {
req.MaxMemoryCapacity = -1 req.MaxMemoryCapacity = -1
} else { } else {
req.MaxMemoryCapacity = maxMemCap req.MaxMemoryCapacity = maxMemCap
} }
} }
if resLimitConv["cu_d"] != nil { if resLimitsConv["cu_dm"] != nil {
maxDiskCap := int64(resLimitConv["cu_d"].(float64)) maxDiskCap := int64(resLimitsConv["cu_dm"].(float64))
if maxDiskCap == 0 { if maxDiskCap == 0 {
req.MaxVDiskCapacity = -1 req.MaxVDiskCapacity = -1
} else { } else {
req.MaxVDiskCapacity = maxDiskCap req.MaxVDiskCapacity = maxDiskCap
} }
} }
if resLimitConv["cu_c"] != nil { if resLimitsConv["cu_c"] != nil {
maxCPUCap := int64(resLimitConv["cu_c"].(float64)) maxCPUCap := int64(resLimitsConv["cu_c"].(float64))
if maxCPUCap == 0 { if maxCPUCap == 0 {
req.MaxCPUCapacity = -1 req.MaxCPUCapacity = -1
} else { } else {
req.MaxCPUCapacity = maxCPUCap req.MaxCPUCapacity = maxCPUCap
} }
} }
if resLimitConv["cu_i"] != nil { if resLimitsConv["cu_i"] != nil {
maxNumPublicIP := int64(resLimitConv["cu_i"].(float64)) maxNumPublicIP := int64(resLimitsConv["cu_i"].(float64))
if maxNumPublicIP == 0 { if maxNumPublicIP == 0 {
req.MaxNumPublicIP = -1 req.MaxNumPublicIP = -1
} else { } else {
req.MaxNumPublicIP = maxNumPublicIP req.MaxNumPublicIP = maxNumPublicIP
} }
} }
if resLimitConv["cu_np"] != nil { if resLimitsConv["cu_np"] != nil {
maxNP := int64(resLimitConv["cu_np"].(float64)) maxNP := int64(resLimitsConv["cu_np"].(float64))
if maxNP == 0 { if maxNP == 0 {
req.MaxNetworkPeerTransfer = -1 req.MaxNetworkPeerTransfer = -1
} else { } else {
req.MaxNetworkPeerTransfer = maxNP req.MaxNetworkPeerTransfer = maxNP
} }
} }
if resLimitConv["gpu_units"] != nil { if resLimitsConv["gpu_units"] != nil {
gpuUnits := int64(resLimitConv["gpu_units"].(float64)) gpuUnits := int64(resLimitsConv["gpu_units"].(float64))
if gpuUnits == 0 { if gpuUnits == 0 {
req.GPUUnits = -1 req.GPUUnits = -1
} else { } else {
@ -121,55 +130,72 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
} }
d.SetId(strconv.FormatUint(accountId, 10)) d.SetId(strconv.FormatUint(accountId, 10))
d.Set("account_id", accountId)
diagnostics := resourceAccountRead(ctx, d, m) var w dc.Warnings
if diagnostics != nil {
return diagnostics if users, ok := d.GetOk("users"); ok {
} addedUsers := users.([]interface{})
for _, user := range addedUsers {
userConv := user.(map[string]interface{})
if enable, ok := d.GetOk("enable"); ok { req := account.AddUserRequest{
enable := enable.(bool)
if enable {
req := account.EnableRequest{
AccountID: accountId, AccountID: accountId,
Username: userConv["user_id"].(string),
AccessType: userConv["access_type"].(string),
} }
_, err := c.CloudBroker().Account().Enable(ctx, req)
_, err := c.CloudBroker().Account().AddUser(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) w.Add(err)
} }
} else { }
req := account.DisableRequest{ }
if cpuAllocationParameter, ok := d.GetOk("cpu_allocation_parameter"); ok {
cpuAllocationParameter := cpuAllocationParameter.(string)
req := account.SetCPUAllocationParameterRequest{
AccountID: accountId, AccountID: accountId,
StrictLoose: cpuAllocationParameter,
} }
_, err := c.CloudBroker().Account().Disable(ctx, req)
log.Debugf("setting account cpu allocation parameter")
_, err := c.CloudBroker().Account().SetCPUAllocationParameter(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) w.Add(err)
}
} }
} }
if users, ok := d.GetOk("users"); ok { if cpuAllocationRatio, ok := d.GetOk("cpu_allocation_ratio"); ok {
addedUsers := users.([]interface{}) cpuAllocationRatio := cpuAllocationRatio.(float64)
if len(addedUsers) > 0 { req := account.SetCPUAllocationRatioRequest{
for _, user := range addedUsers {
userConv := user.(map[string]interface{})
req := account.AddUserRequest{
AccountID: accountId, AccountID: accountId,
Username: userConv["user_id"].(string), Ratio: cpuAllocationRatio,
AccessType: userConv["access_type"].(string),
} }
_, err := c.CloudBroker().Account().AddUser(ctx, req) log.Debugf("setting account cpu allocation ratio")
_, err := c.CloudBroker().Account().SetCPUAllocationRatio(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) w.Add(err)
} }
} }
if !d.Get("enable").(bool) {
_, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{
AccountID: accountId,
})
if err != nil {
w.Add(err)
} }
} }
return nil diags := resourceAccountRead(ctx, d, m)
diags = append(diags, w.Get()...)
return diags
} }
func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@ -220,35 +246,88 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err) return diag.FromErr(err)
} }
if d.HasChange("enable") { accountId, _ := strconv.ParseUint(d.Id(), 10, 64)
enable := d.Get("enable").(bool)
if enable { hasChanged := false
req := account.EnableRequest{
AccountID: acc.ID, switch acc.Status {
case status.Destroyed:
d.SetId("")
// return resourceAccountCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
case status.Destroying:
return diag.Errorf("The account is in progress with status: %s", acc.Status)
case status.Deleted:
_, err := c.CloudBroker().Account().Restore(ctx, account.RestoreRequest{
AccountID: accountId,
})
if err != nil {
return diag.FromErr(err)
}
hasChanged = true
case status.Disabled:
log.Debugf("The account is in status: %s, troubles may occur with update. Please, enable account first.", acc.Status)
case status.Confirmed:
} }
_, err := c.CloudBroker().Account().Enable(ctx, req)
if hasChanged {
acc, err = utilityAccountCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
} else {
req := account.DisableRequest{
AccountID: acc.ID,
} }
_, err := c.CloudBroker().Account().Disable(ctx, req)
if d.HasChange("enable") {
enable := d.Get("enable").(bool)
if enable && acc.Status == status.Disabled {
_, err := c.CloudBroker().Account().Enable(ctx, account.EnableRequest{
AccountID: accountId,
})
if err != nil {
return diag.FromErr(err)
}
} else if !enable && acc.Status == status.Enabled {
_, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{
AccountID: accountId,
})
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
} }
updateReq := account.UpdateRequest{AccountID: acc.ID} req := account.UpdateRequest{
hasChange := false AccountID: accountId,
}
updated := false
if d.HasChange("account_name") { if d.HasChange("account_name") {
updateReq.Name = d.Get("account_name").(string) req.Name = d.Get("account_name").(string)
updated = true
}
if d.HasChange("send_access_emails") {
req.SendAccessEmails = d.Get("send_access_emails").(bool)
updated = true
}
if d.HasChange("uniq_pools") {
uniq_pools := d.Get("uniq_pools").([]interface{})
for _, pool := range uniq_pools {
req.UniqPools = append(req.UniqPools, pool.(string))
}
hasChange = true updated = true
} }
if d.HasChange("resource_limits") { if d.HasChange("resource_limits") {
resLimit := d.Get("resource_limits").([]interface{})[0] resLimit := d.Get("resource_limits").([]interface{})[0]
resLimitConv := resLimit.(map[string]interface{}) resLimitConv := resLimit.(map[string]interface{})
@ -256,82 +335,85 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
if resLimitConv["cu_m"] != nil { if resLimitConv["cu_m"] != nil {
maxMemCap := int(resLimitConv["cu_m"].(float64)) maxMemCap := int(resLimitConv["cu_m"].(float64))
if maxMemCap == 0 { if maxMemCap == 0 {
updateReq.MaxMemoryCapacity = -1 req.MaxMemoryCapacity = -1
} else { } else {
updateReq.MaxMemoryCapacity = int64(maxMemCap) req.MaxMemoryCapacity = int64(maxMemCap)
} }
} }
if resLimitConv["cu_d"] != nil { if resLimitConv["cu_dm"] != nil {
maxDiskCap := int(resLimitConv["cu_d"].(float64)) maxDiskCap := int(resLimitConv["cu_dm"].(float64))
if maxDiskCap == 0 { if maxDiskCap == 0 {
updateReq.MaxVDiskCapacity = -1 req.MaxVDiskCapacity = -1
} else { } else {
updateReq.MaxVDiskCapacity = int64(maxDiskCap) req.MaxVDiskCapacity = int64(maxDiskCap)
} }
} }
if resLimitConv["cu_c"] != nil { if resLimitConv["cu_c"] != nil {
maxCPUCap := int(resLimitConv["cu_c"].(float64)) maxCPUCap := int(resLimitConv["cu_c"].(float64))
if maxCPUCap == 0 { if maxCPUCap == 0 {
updateReq.MaxCPUCapacity = -1 req.MaxCPUCapacity = -1
} else { } else {
updateReq.MaxCPUCapacity = int64(maxCPUCap) req.MaxCPUCapacity = int64(maxCPUCap)
} }
} }
if resLimitConv["cu_i"] != nil { if resLimitConv["cu_i"] != nil {
maxNumPublicIP := int(resLimitConv["cu_i"].(float64)) maxNumPublicIP := int(resLimitConv["cu_i"].(float64))
if maxNumPublicIP == 0 { if maxNumPublicIP == 0 {
updateReq.MaxNumPublicIP = -1 req.MaxNumPublicIP = -1
} else { } else {
updateReq.MaxNumPublicIP = int64(maxNumPublicIP) req.MaxNumPublicIP = int64(maxNumPublicIP)
} }
} }
if resLimitConv["cu_np"] != nil { if resLimitConv["cu_np"] != nil {
maxNP := int(resLimitConv["cu_np"].(float64)) maxNP := int(resLimitConv["cu_np"].(float64))
if maxNP == 0 { if maxNP == 0 {
updateReq.MaxNetworkPeerTransfer = -1 req.MaxNetworkPeerTransfer = -1
} else { } else {
updateReq.MaxNetworkPeerTransfer = int64(maxNP) req.MaxNetworkPeerTransfer = int64(maxNP)
} }
} }
if resLimitConv["gpu_units"] != nil { if resLimitConv["gpu_units"] != nil {
gpuUnits := int(resLimitConv["gpu_units"].(float64)) gpuUnits := int(resLimitConv["gpu_units"].(float64))
if gpuUnits == 0 { if gpuUnits == 0 {
updateReq.GPUUnits = -1 req.GPUUnits = -1
} else { } else {
updateReq.GPUUnits = int64(gpuUnits) req.GPUUnits = int64(gpuUnits)
} }
} }
hasChange = true updated = true
} }
if d.HasChange("send_access_emails") { if updated {
updateReq.SendAccessEmails = d.Get("send_access_emails").(bool) _, err := c.CloudBroker().Account().Update(ctx, req)
hasChange = true
}
if hasChange {
_, err := c.CloudBroker().Account().Update(ctx, updateReq)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
if d.HasChange("restore") { if d.HasChange("cpu_allocation_parameter") {
restore := d.Get("restore").(bool) cpuAllocationParameter := d.Get("cpu_allocation_parameter").(string)
if restore {
req := account.RestoreRequest{ _, err := c.CloudBroker().Account().SetCPUAllocationParameter(ctx, account.SetCPUAllocationParameterRequest{
AccountID: acc.ID, AccountID: acc.ID,
} StrictLoose: cpuAllocationParameter,
})
_, err := c.CloudBroker().Account().Restore(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
if d.HasChange("cpu_allocation_ratio") {
cpuAllocacationRatio := d.Get("cpu_allocation_ratio").(float64)
_, err := c.CloudBroker().Account().SetCPUAllocationRatio(ctx, account.SetCPUAllocationRatioRequest{
AccountID: acc.ID,
Ratio: cpuAllocacationRatio,
})
if err != nil {
return diag.FromErr(err)
}
} }
if d.HasChange("users") { if d.HasChange("users") {
@ -347,67 +429,66 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
deletedUsers = append(deletedUsers, el) deletedUsers = append(deletedUsers, el)
} }
} }
for _, el := range newConv { for _, el := range newConv {
if !isContainsUser(oldConv, el) { if !isContainsUser(oldConv, el) {
duplicate := false
for _, user := range acc.ACL {
if user.UserGroupID == el.(map[string]interface{})["user_id"].(string) {
duplicate = true
}
}
if !duplicate {
addedUsers = append(addedUsers, el) addedUsers = append(addedUsers, el)
} else { } else if isChangedUser(oldConv, el) {
if isChangedUser(oldConv, el) {
updatedUsers = append(updatedUsers, el) updatedUsers = append(updatedUsers, el)
} }
} }
} }
if len(deletedUsers) > 0 {
for _, user := range deletedUsers { for _, user := range deletedUsers {
userConv := user.(map[string]interface{}) userConv := user.(map[string]interface{})
req := account.DeleteUserRequest{
AccountID: acc.ID, _, err := c.CloudBroker().Account().DeleteUser(ctx, account.DeleteUserRequest{
AccountID: accountId,
UserName: userConv["user_id"].(string), UserName: userConv["user_id"].(string),
RecursiveDelete: userConv["recursive_delete"].(bool), RecursiveDelete: userConv["recursive_delete"].(bool),
} })
_, err := c.CloudBroker().Account().DeleteUser(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
}
if len(addedUsers) > 0 {
for _, user := range addedUsers { for _, user := range addedUsers {
userConv := user.(map[string]interface{}) userConv := user.(map[string]interface{})
req := account.AddUserRequest{
AccountID: acc.ID, _, err := c.CloudBroker().Account().AddUser(ctx, account.AddUserRequest{
AccountID: accountId,
Username: userConv["user_id"].(string), Username: userConv["user_id"].(string),
AccessType: strings.ToUpper(userConv["access_type"].(string)), AccessType: strings.ToUpper(userConv["access_type"].(string)),
} })
_, err := c.CloudBroker().Account().AddUser(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
}
if len(updatedUsers) > 0 {
for _, user := range updatedUsers { for _, user := range updatedUsers {
userConv := user.(map[string]interface{}) userConv := user.(map[string]interface{})
req := account.UpdateUserRequest{
AccountID: acc.ID, _, err := c.CloudBroker().Account().UpdateUser(ctx, account.UpdateUserRequest{
AccountID: accountId,
UserID: userConv["user_id"].(string), UserID: userConv["user_id"].(string),
AccessType: strings.ToUpper(userConv["access_type"].(string)), AccessType: strings.ToUpper(userConv["access_type"].(string)),
} })
_, err := c.CloudBroker().Account().UpdateUser(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
} }
} return resourceAccountRead(ctx, d, m)
return nil
} }
func isContainsUser(els []interface{}, el interface{}) bool { func isContainsUser(els []interface{}, el interface{}) bool {

@ -44,13 +44,15 @@ import (
func utilityAccountCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.RecordAccount, error) { func utilityAccountCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.RecordAccount, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
accountID := d.Get("account_id").(int)
req := account.GetRequest{} req := account.GetRequest{}
if (strconv.Itoa(d.Get("account_id").(int))) != "0" { if d.Id() == "" {
req.AccountID = uint64(d.Get("account_id").(int)) req.AccountID = uint64(accountID)
} else { } else {
id, _ := strconv.ParseUint(d.Id(), 10, 64) req.AccountID, _ = strconv.ParseUint(d.Id(), 10, 64)
req.AccountID = id
} }
log.Debugf("utilityAccountCheckPresence: load account") log.Debugf("utilityAccountCheckPresence: load account")

@ -47,6 +47,46 @@ func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.Reso
AccountID: uint64(d.Get("account_id").(int)), AccountID: uint64(d.Get("account_id").(int)),
} }
if compute_id, ok := d.GetOk("compute_id"); ok {
req.ComputeID = uint64(compute_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if rg_name, ok := d.GetOk("rg_name"); ok {
req.RGName = rg_name.(string)
}
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 ip_address, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ip_address.(string)
}
if extnet_name, ok := d.GetOk("extnet_name"); ok {
req.ExtNetName = extnet_name.(string)
}
if extnet_id, ok := d.GetOk("extnet_id"); ok {
req.ExtNetID = uint64(extnet_id.(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("utilityAccountComputesListCheckPresence: load account list") log.Debugf("utilityAccountComputesListCheckPresence: load account list")
accountComputesList, err := c.CloudBroker().Account().ListComputes(ctx, req) accountComputesList, err := c.CloudBroker().Account().ListComputes(ctx, req)
if err != nil { if err != nil {

@ -48,10 +48,23 @@ func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.Resou
if page, ok := d.GetOk("page"); ok { if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int)) req.Page = uint64(page.(int))
} }
if size, ok := d.GetOk("size"); ok { if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int)) req.Size = uint64(size.(int))
} }
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if acl, ok := d.GetOk("acl"); ok {
req.ACL = acl.(string)
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
log.Debugf("utilityAccountDeletedListCheckPresence: load") log.Debugf("utilityAccountDeletedListCheckPresence: load")
accountDeletedList, err := c.CloudBroker().Account().ListDeleted(ctx, req) accountDeletedList, err := c.CloudBroker().Account().ListDeleted(ctx, req)
if err != nil { if err != nil {

@ -47,6 +47,30 @@ func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.Resourc
AccountID: uint64(d.Get("account_id").(int)), AccountID: uint64(d.Get("account_id").(int)),
} }
if disk_id, ok := d.GetOk("disk_id"); ok {
req.DiskID = uint64(disk_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
req.DiskMaxSize = uint64(disk_max_size.(int))
}
if typeVal, ok := d.GetOk("type"); ok {
req.Type = typeVal.(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("utilityAccountDisksListCheckPresence: load account list") log.Debugf("utilityAccountDisksListCheckPresence: load account list")
accountDisksList, err := c.CloudBroker().Account().ListDisks(ctx, req) accountDisksList, err := c.CloudBroker().Account().ListDisks(ctx, req)
if err != nil { if err != nil {

@ -47,6 +47,38 @@ func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.Re
AccountID: uint64(d.Get("account_id").(int)), AccountID: uint64(d.Get("account_id").(int)),
} }
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if vins_id, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vins_id.(int))
}
if vins_name, ok := d.GetOk("vins_name"); ok {
req.VINSName = vins_name.(string)
}
if extnet_id, ok := d.GetOk("extnet_id"); ok {
req.ExtNetID = uint64(extnet_id.(int))
}
if by_ip, ok := d.GetOk("by_ip"); ok {
req.ByIP = by_ip.(string)
}
if flipgroup_id, ok := d.GetOk("flipgroup_id"); ok {
req.FLIPGroupID = uint64(flipgroup_id.(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("utilityAccountFlipGroupsListCheckPresence") log.Debugf("utilityAccountFlipGroupsListCheckPresence")
accountFlipGroupsList, err := c.CloudBroker().Account().ListFLIPGroups(ctx, req) accountFlipGroupsList, err := c.CloudBroker().Account().ListFLIPGroups(ctx, req)
if err != nil { if err != nil {

@ -0,0 +1,61 @@
/*
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 account
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountResourceConsumptionGetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.RecordResourceConsumption, error) {
c := m.(*controller.ControllerCfg)
id := uint64(d.Get("account_id").(int))
req:= account.GetResourceConsumptionRequest {
AccountID: id,
}
log.Debugf("utilityAccountResourceConsumptionGetCheckPresence: load")
accountResourceConsumptionRec, err := c.CloudBroker().Account().GetResourceConsumption(ctx, req)
if err != nil {
return nil, err
}
return accountResourceConsumptionRec, nil
}

@ -52,6 +52,22 @@ func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData
req.Size = uint64(size.(int)) req.Size = uint64(size.(int))
} }
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if acl, ok := d.GetOk("acl"); ok {
req.ACL = acl.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
log.Debugf("utilityAccountListCheckPresence: load account list") log.Debugf("utilityAccountListCheckPresence: load account list")
accountList, err := c.CloudBroker().Account().List(ctx, req) accountList, err := c.CloudBroker().Account().List(ctx, req)
if err != nil { if err != nil {

@ -1,8 +1,9 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -29,11 +30,24 @@ builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package rg package account
const ResgroupCreateAPI = "/restmachine/cloudbroker/rg/create" import (
const ResgroupUpdateAPI = "/restmachine/cloudbroker/rg/update" "context"
const ResgroupListAPI = "/restmachine/cloudbroker/rg/list"
const ResgroupGetAPI = "/restmachine/cloudbroker/rg/get" log "github.com/sirupsen/logrus"
const ResgroupDeleteAPI = "/restmachine/cloudbroker/rg/delete" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
const RgListComputesAPI = "/restmachine/cloudbroker/rg/listComputes" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityAccountResourceConsumptionListCheckPresence(ctx context.Context, m interface{}) (*account.ListResources, error) {
c := m.(*controller.ControllerCfg)
log.Debugf("utilityAccountResourceConsumptionListCheckPresence: load")
accountResourceConsumptionList, err := c.CloudBroker().Account().ListResourceConsumption(ctx)
if err != nil {
return nil, err
}
return accountResourceConsumptionList, nil
}

@ -47,6 +47,34 @@ func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceDa
AccountID: uint64(d.Get("account_id").(int)), AccountID: uint64(d.Get("account_id").(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))
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if vins_id, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vins_id.(int))
}
if vm_id, ok := d.GetOk("vm_id"); ok {
req.VMID = uint64(vm_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
log.Debugf("utilityAccountRGListCheckPresence: load account list") log.Debugf("utilityAccountRGListCheckPresence: load account list")
accountRGList, err := c.CloudBroker().Account().ListRG(ctx, req) accountRGList, err := c.CloudBroker().Account().ListRG(ctx, req)
if err != nil { if err != nil {

@ -47,6 +47,30 @@ func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.Resource
AccountID: uint64(d.Get("account_id").(int)), AccountID: uint64(d.Get("account_id").(int)),
} }
if vins_id, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vins_id.(int))
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(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))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if ext_ip, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = ext_ip.(string)
}
log.Debugf("utilityAccountVinsListCheckPresence: load account list") log.Debugf("utilityAccountVinsListCheckPresence: load account list")
accountVinsList, err := c.CloudBroker().Account().ListVINS(ctx, req) accountVinsList, err := c.CloudBroker().Account().ListVINS(ctx, req)
if err != nil { if err != nil {

@ -79,6 +79,22 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"computes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"compute_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"created_time": { "created_time": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -222,6 +238,13 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"purge_attempts": { "purge_attempts": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -258,6 +281,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"shareable": {
Type: schema.TypeString,
Computed: true,
},
"size_max": { "size_max": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -279,6 +306,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"res_id": { "res_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

@ -49,12 +49,43 @@ func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m inter
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenDiskList(diskList)) d.Set("items", flattenDiskList(diskList))
d.Set("entry_count", diskList.EntryCount)
return nil return nil
} }
func dataSourceDiskListSchemaMake() map[string]*schema.Schema { func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{ res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by name",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by account name",
},
"disk_max_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by max disk size",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"shared": {
Type: schema.TypeBool,
Optional: true,
Description: "Find by shared field",
},
"account_id": { "account_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
@ -65,6 +96,16 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Optional: true, Optional: true,
Description: "type of the disks", Description: "type of the disks",
}, },
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by sep id",
},
"pool": {
Type: schema.TypeString,
Optional: true,
Description: "Find by pool name",
},
"page": { "page": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
@ -96,6 +137,22 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"computes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"compute_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"created_time": { "created_time": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -251,6 +308,13 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"purge_attempts": { "purge_attempts": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -287,6 +351,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"shareable": {
Type: schema.TypeBool,
Computed: true,
},
"size_max": { "size_max": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -308,6 +376,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"res_id": { "res_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@ -346,6 +418,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
}, },
}, },
}, },
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
} }
return res return res
} }

@ -0,0 +1,56 @@
package disks
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 dataSourceDiskListTypesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listTypes, err := utilityDiskListTypesCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", listTypes.Data)
d.Set("entry_count", listTypes.EntryCount)
return nil
}
func dataSourceDiskListTypesSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The types of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
func DataSourceDiskListTypes() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceDiskListTypesRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceDiskListTypesSchemaMake(),
}
}

@ -0,0 +1,84 @@
package disks
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 dataSourceDiskListTypesDetailedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listTypesDetailed, err := utilityDiskListTypesDetailedCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenDiskListTypesDetailed(listTypesDetailed))
d.Set("entry_count", listTypesDetailed.EntryCount)
return nil
}
func DataSourceDiskListTypesDetailed() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceDiskListTypesDetailedRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: map[string]*schema.Schema{
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Pool name",
},
"system": {
Type: schema.TypeString,
Computed: true,
},
"types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The types of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
},
},
},
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Storage endpoint provider ID to create disk",
},
"sep_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}

@ -0,0 +1,470 @@
/*
Copyright (c) 2019-2022 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>
Nikita Sorokin, <nesorokin@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 disks
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 dataSourceDiskListUnattachedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diskListUnattached, err := utilityDiskListUnattachedCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenDiskListUnattached(diskListUnattached))
d.Set("entry_count", diskListUnattached.EntryCount)
return nil
}
func DataSourceDiskListUnattached() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceDiskListUnattachedRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceDiskListUnattachedSchemaMake(),
}
}
func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by account name",
},
"disk_max_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by max disk size",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "type of the disks",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "ID of the account the disks belong to",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Description: "ID of SEP",
},
"pool": {
Type: schema.TypeString,
Optional: true,
},
"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: map[string]*schema.Schema{
"_ckey": {
Type: schema.TypeString,
Computed: true,
Description: "CKey",
},
"_meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Meta parameters",
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the account the disks belong to",
},
"account_name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the subscriber '(account') to whom this disk belongs",
},
"acl": {
Type: schema.TypeString,
Computed: true,
},
"boot_partition": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of disk partitions",
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Created time",
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Deleted time",
},
"desc": {
Type: schema.TypeString,
Computed: true,
Description: "Description of disk",
},
"destruction_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Time of final deletion",
},
"disk_path": {
Type: schema.TypeString,
Computed: true,
Description: "Disk path",
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the grid (platform)",
},
"guid": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk ID on the storage side",
},
"disk_id": {
Type: schema.TypeInt,
Computed: true,
Description: "The unique ID of the subscriber-owner of the disk",
},
"image_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Image ID",
},
"images": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "IDs of images using the disk",
},
"iotune": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"read_bytes_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of bytes to read per second",
},
"read_bytes_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of bytes to read",
},
"read_iops_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of io read operations per second",
},
"read_iops_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of io read operations",
},
"size_iops_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Size of io operations",
},
"total_bytes_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Total size bytes per second",
},
"total_bytes_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum total size of bytes per second",
},
"total_iops_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Total number of io operations per second",
},
"total_iops_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum total number of io operations per second",
},
"write_bytes_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of bytes to write per second",
},
"write_bytes_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of bytes to write per second",
},
"write_iops_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of write operations per second",
},
"write_iops_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of write operations per second",
},
},
},
},
"iqn": {
Type: schema.TypeString,
Computed: true,
Description: "Disk IQN",
},
"login": {
Type: schema.TypeString,
Computed: true,
Description: "Login to access the disk",
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
Description: "Milestones",
},
"disk_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of disk",
},
"order": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk order",
},
"params": {
Type: schema.TypeString,
Computed: true,
Description: "Disk params",
},
"parent_id": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the parent disk",
},
"passwd": {
Type: schema.TypeString,
Computed: true,
Description: "Password to access the disk",
},
"pci_slot": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the pci slot to which the disk is connected",
},
"pool": {
Type: schema.TypeString,
Computed: true,
Description: "Pool for disk location",
},
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of deletion attempts",
},
"purge_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Time of the last deletion attempt",
},
"reality_device_number": {
Type: schema.TypeInt,
Computed: true,
Description: "Reality device number",
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the reference to the disk",
},
"res_id": {
Type: schema.TypeString,
Computed: true,
Description: "Resource ID",
},
"res_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the resource",
},
"role": {
Type: schema.TypeString,
Computed: true,
Description: "Disk role",
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Storage endpoint provider ID to create disk",
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Size in GB",
},
"size_used": {
Type: schema.TypeFloat,
Computed: true,
Description: "Number of used space, in GB",
},
"snapshots": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the snapshot",
},
"label": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the snapshot",
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,
Description: "Reference to the snapshot",
},
"snap_set_guid": {
Type: schema.TypeString,
Computed: true,
Description: "The set snapshot ID",
},
"snap_set_time": {
Type: schema.TypeInt,
Computed: true,
Description: "The set time of the snapshot",
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
Description: "Snapshot time",
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Disk status",
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
Description: "Technical status of the disk",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
},
"vmid": {
Type: schema.TypeInt,
Computed: true,
Description: "Virtual Machine ID (Deprecated)",
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

@ -0,0 +1,129 @@
/*
Copyright (c) 2019-2022 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 disks
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/decort-golang-sdk/pkg/cloudbroker/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceDiskSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
var snapshot disks.ItemSnapshot
label := d.Get("label").(string)
for _, sn := range disk.Snapshots {
if label == sn.Label {
snapshot = sn
break
}
}
if label != snapshot.Label {
return diag.Errorf("Snapshot with label \"%v\" not found", label)
}
id := uuid.New()
d.SetId(id.String())
flattenDiskSnapshot(d, snapshot)
return nil
}
func DataSourceDiskSnapshot() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceDiskSnapshotRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceDiskSnapshotSchemaMake(),
}
}
func dataSourceDiskSnapshotSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"disk_id": {
Type: schema.TypeInt,
Required: true,
Description: "The unique ID of the subscriber-owner of the disk",
},
"label": {
Type: schema.TypeString,
Required: true,
Description: "Name of the snapshot",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the snapshot",
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
Description: "Snapshot time",
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,
Description: "Reference to the snapshot",
},
"snap_set_guid": {
Type: schema.TypeString,
Computed: true,
Description: "The set snapshot ID",
},
"snap_set_time": {
Type: schema.TypeInt,
Computed: true,
Description: "The set time of the snapshot",
},
}
return rets
}

@ -0,0 +1,122 @@
/*
Copyright (c) 2019-2022 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 disks
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 dataSourceDiskSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenDiskSnapshotList(disk.Snapshots))
return nil
}
func DataSourceDiskSnapshotList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceDiskSnapshotListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceDiskSnapshotListSchemaMake(),
}
}
func dataSourceDiskSnapshotListSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"disk_id": {
Type: schema.TypeInt,
Required: true,
Description: "The unique ID of the subscriber-owner of the disk",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"label": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the snapshot",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the snapshot",
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
Description: "Snapshot time",
},
"res_id": {
Type: schema.TypeString,
Computed: true,
Description: "Reference to the snapshot",
},
"snap_set_guid": {
Type: schema.TypeString,
Computed: true,
Description: "The set snapshot ID",
},
"snap_set_time": {
Type: schema.TypeInt,
Computed: true,
Description: "The set time of the snapshot",
},
},
},
},
}
return rets
}

@ -5,6 +5,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
) )
func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) { func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
@ -14,6 +15,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("account_name", disk.AccountName) d.Set("account_name", disk.AccountName)
d.Set("acl", string(diskAcl)) d.Set("acl", string(diskAcl))
d.Set("boot_partition", disk.BootPartition) d.Set("boot_partition", disk.BootPartition)
d.Set("computes", flattenDiskComputes(disk.Computes))
d.Set("created_time", disk.CreatedTime) d.Set("created_time", disk.CreatedTime)
d.Set("deleted_time", disk.DeletedTime) d.Set("deleted_time", disk.DeletedTime)
d.Set("desc", disk.Description) d.Set("desc", disk.Description)
@ -37,6 +39,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("pci_slot", disk.PCISlot) d.Set("pci_slot", disk.PCISlot)
d.Set("pool", disk.Pool) d.Set("pool", disk.Pool)
d.Set("purge_attempts", disk.PurgeAttempts) d.Set("purge_attempts", disk.PurgeAttempts)
d.Set("present_to", disk.PresentTo)
d.Set("purge_time", disk.PurgeTime) d.Set("purge_time", disk.PurgeTime)
d.Set("reality_device_number", disk.RealityDeviceNumber) d.Set("reality_device_number", disk.RealityDeviceNumber)
d.Set("reference_id", disk.ReferenceID) d.Set("reference_id", disk.ReferenceID)
@ -45,6 +48,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("role", disk.Role) d.Set("role", disk.Role)
d.Set("sep_id", disk.SEPID) d.Set("sep_id", disk.SEPID)
d.Set("sep_type", disk.SEPType) d.Set("sep_type", disk.SEPType)
d.Set("shareable", disk.Shareable)
d.Set("size_max", disk.SizeMax) d.Set("size_max", disk.SizeMax)
d.Set("size_used", disk.SizeUsed) d.Set("size_used", disk.SizeUsed)
d.Set("snapshots", flattendDiskSnapshotList(disk.Snapshots)) d.Set("snapshots", flattendDiskSnapshotList(disk.Snapshots))
@ -54,6 +58,27 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("vmid", disk.VMID) d.Set("vmid", disk.VMID)
} }
func flattenDiskSnapshot(d *schema.ResourceData, snapshot disks.ItemSnapshot) {
d.Set("timestamp", snapshot.Timestamp)
d.Set("guid", snapshot.GUID)
d.Set("reference_id", snapshot.ReferenceID)
d.Set("res_id", snapshot.ResID)
d.Set("snap_set_guid", snapshot.SnapSetGUID)
d.Set("snap_set_time", snapshot.SnapSetTime)
}
func flattenDiskComputes(computes map[string]string) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(computes))
for key, val := range computes {
tmp := map[string]interface{}{
"compute_id": key,
"compute_name": val,
}
res = append(res, tmp)
}
return res
}
func flattenIOTune(iot disks.IOTune) []map[string]interface{} { func flattenIOTune(iot disks.IOTune) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
@ -140,6 +165,7 @@ func flattendDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
temp := map[string]interface{}{ temp := map[string]interface{}{
"guid": snapshot.GUID, "guid": snapshot.GUID,
"label": snapshot.Label, "label": snapshot.Label,
"reference_id": snapshot.ReferenceID,
"res_id": snapshot.ResID, "res_id": snapshot.ResID,
"snap_set_guid": snapshot.SnapSetGUID, "snap_set_guid": snapshot.SnapSetGUID,
"snap_set_time": snapshot.SnapSetTime, "snap_set_time": snapshot.SnapSetTime,
@ -151,3 +177,105 @@ func flattendDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
return res return res
} }
func flattenDiskListTypesDetailed(tld *disks.ListTypes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, typeListDetailed := range tld.Data {
toMap := typeListDetailed.(map[string]interface{})
temp := map[string]interface{}{
"pools": flattenListTypesDetailedPools(toMap["pools"].([]interface{})),
"sep_id": toMap["sepId"].(float64),
"sep_name": toMap["sepName"].(string),
}
res = append(res, temp)
}
return res
}
func flattenListTypesDetailedPools(pools []interface{}) []interface{} {
res := make([]interface{}, 0)
for _, pool := range pools {
toMap := pool.(map[string]interface{})
temp := map[string]interface{}{
"name": toMap["name"].(string),
"system": toMap["system"].(string),
"types": toMap["types"].([]interface{}),
}
res = append(res, temp)
}
return res
}
func flattenDiskListUnattached(ul *disks.ListUnattachedDisks) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, unattachedDisk := range ul.Data {
unattachedDiskAcl, _ := json.Marshal(unattachedDisk.ACL)
tmp := map[string]interface{}{
"_ckey": unattachedDisk.CKey,
"_meta": flattens.FlattenMeta(unattachedDisk.Meta),
"account_id": unattachedDisk.AccountID,
"account_name": unattachedDisk.AccountName,
"acl": string(unattachedDiskAcl),
"boot_partition": unattachedDisk.BootPartition,
"created_time": unattachedDisk.CreatedTime,
"deleted_time": unattachedDisk.DeletedTime,
"desc": unattachedDisk.Description,
"destruction_time": unattachedDisk.DestructionTime,
"disk_path": unattachedDisk.DiskPath,
"gid": unattachedDisk.GID,
"guid": unattachedDisk.GUID,
"disk_id": unattachedDisk.ID,
"image_id": unattachedDisk.ImageID,
"images": unattachedDisk.Images,
"iotune": flattenIOTune(unattachedDisk.IOTune),
"iqn": unattachedDisk.IQN,
"login": unattachedDisk.Login,
"milestones": unattachedDisk.Milestones,
"disk_name": unattachedDisk.Name,
"order": unattachedDisk.Order,
"params": unattachedDisk.Params,
"parent_id": unattachedDisk.ParentID,
"passwd": unattachedDisk.Password,
"pci_slot": unattachedDisk.PCISlot,
"pool": unattachedDisk.Pool,
"present_to": unattachedDisk.PresentTo,
"purge_attempts": unattachedDisk.PurgeAttempts,
"purge_time": unattachedDisk.PurgeTime,
"reality_device_number": unattachedDisk.RealityDeviceNumber,
"reference_id": unattachedDisk.ReferenceID,
"res_id": unattachedDisk.ResID,
"res_name": unattachedDisk.ResName,
"role": unattachedDisk.Role,
"sep_id": unattachedDisk.SEPID,
"shareable": unattachedDisk.Shareable,
"size_max": unattachedDisk.SizeMax,
"size_used": unattachedDisk.SizeUsed,
"snapshots": flattenDiskSnapshotList(unattachedDisk.Snapshots),
"status": unattachedDisk.Status,
"tech_status": unattachedDisk.TechStatus,
"type": unattachedDisk.Type,
"vmid": unattachedDisk.VMID,
}
res = append(res, tmp)
}
return res
}
func flattenDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
res := make([]interface{}, 0)
for _, snapshot := range sl {
temp := map[string]interface{}{
"guid": snapshot.GUID,
"label": snapshot.Label,
"reference_id": snapshot.ReferenceID,
"res_id": snapshot.ResID,
"snap_set_guid": snapshot.SnapSetGUID,
"snap_set_time": snapshot.SnapSetTime,
"timestamp": snapshot.Timestamp,
}
res = append(res, temp)
}
return res
}

@ -0,0 +1,55 @@
package disks
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
accountID := uint64(d.Get("account_id").(int))
accountList, err := c.CloudBroker().Account().List(ctx, account.ListRequest{})
if err != nil {
return err
}
if len(accountList.FilterByID(accountID).Data) == 0 {
return fmt.Errorf("resourceDiskCreate: can't create/update Disk because AccountID %d is not allowed or does not exist", accountID)
}
return nil
}
func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
gid := uint64(d.Get("gid").(int))
gidList, err := c.CloudBroker().Grid().List(ctx, grid.ListRequest{})
if err != nil {
return err
}
for _, elem := range gidList.Data {
if elem.GID == gid {
return nil
}
}
return fmt.Errorf("resourceDiskCreate: can't create/update Disk because GID %d is not allowed or does not exist", gid)
}
func checkParamsExists(ctx context.Context, d *schema.ResourceData, m interface{}) error {
err := existAccountID(ctx, d, m)
if err != nil {
return err
}
return existGID(ctx, d, m)
}

@ -35,129 +35,233 @@ import (
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
"strings"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "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/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
log "github.com/sirupsen/logrus"
) )
func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := disks.CreateRequest{}
req.AccountID = uint64(d.Get("account_id").(int)) err := checkParamsExists(ctx, d, m)
req.GID = uint64(d.Get("gid").(int)) if err != nil {
req.Name = d.Get("disk_name").(string) return diag.FromErr(err)
req.Size = uint64(d.Get("size_max").(int)) }
if typeRaw, ok := d.GetOk("type"); ok { req := disks.CreateRequest{
req.Type = strings.ToUpper(typeRaw.(string)) AccountID: uint64(d.Get("account_id").(int)),
} else { GID: uint64(d.Get("gid").(int)),
req.Type = "D" Name: d.Get("disk_name").(string),
Size: uint64(d.Get("size_max").(int)),
Type: d.Get("type").(string),
} }
if sepId, ok := d.GetOk("sep_id"); ok { if desc, ok := d.GetOk("desc"); ok {
req.SEPID = uint64(sepId.(int)) req.Description = desc.(string)
} }
if poolName, ok := d.GetOk("pool"); ok { if ssdSize, ok := d.GetOk("ssd_size"); ok {
req.Pool = poolName.(string) req.SSDSize = uint64(ssdSize.(int))
} }
argVal, argSet := d.GetOk("desc") if sepID, ok := d.GetOk("sep_id"); ok {
if argSet { req.SEPID = uint64(sepID.(int))
req.Description = argVal.(string)
} }
diskId, err := c.CloudBroker().Disks().Create(ctx, req) if pool, ok := d.GetOk("pool"); ok {
req.Pool = pool.(string)
}
diskID, err := c.CloudBroker().Disks().Create(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId(strconv.FormatUint(diskId, 10)) d.SetId(strconv.FormatUint(diskID, 10))
w := dc.Warnings{}
if iotuneRaw, ok := d.GetOk("iotune"); ok { if iotuneRaw, ok := d.GetOk("iotune"); ok {
iot := iotuneRaw.([]interface{})[0] iot := iotuneRaw.([]interface{})[0]
iotune := iot.(map[string]interface{}) iotune := iot.(map[string]interface{})
req := disks.LimitIORequest{ req := disks.LimitIORequest{
DiskID: diskId, DiskID: diskID,
IOPS: uint64(iotune["total_iops_sec"].(int)), IOPS: uint64(iotune["total_iops_sec"].(int)),
TotalBytesSec: uint64(iotune["total_bytes_sec"].(int)),
ReadBytesSec: uint64(iotune["read_bytes_sec"].(int)), ReadBytesSec: uint64(iotune["read_bytes_sec"].(int)),
WriteBytesSec: uint64(iotune["write_bytes_sec"].(int)), ReadBytesSecMax: uint64(iotune["read_bytes_sec_max"].(int)),
TotalIOPSSec: uint64(iotune["total_iops_sec"].(int)),
ReadIOPSSec: uint64(iotune["read_iops_sec"].(int)), ReadIOPSSec: uint64(iotune["read_iops_sec"].(int)),
WriteIOPSSec: uint64(iotune["write_iops_sec"].(int)), ReadIOPSSecMax: uint64(iotune["read_iops_sec_max"].(int)),
SizeIOPSSec: uint64(iotune["size_iops_sec"].(int)),
TotalBytesSec: uint64(iotune["total_bytes_sec"].(int)),
TotalBytesSecMax: uint64(iotune["total_bytes_sec_max"].(int)), TotalBytesSecMax: uint64(iotune["total_bytes_sec_max"].(int)),
ReadBytesSecMax: uint64(iotune["read_bytes_sec_max"].(int)),
WriteBytesSecMax: uint64(iotune["write_bytes_sec_max"].(int)),
TotalIOPSSecMax: uint64(iotune["total_iops_sec_max"].(int)), TotalIOPSSecMax: uint64(iotune["total_iops_sec_max"].(int)),
ReadIOPSSecMax: uint64(iotune["read_iops_sec_max"].(int)), TotalIOPSSec: uint64(iotune["total_iops_sec"].(int)),
WriteBytesSec: uint64(iotune["write_bytes_sec"].(int)),
WriteBytesSecMax: uint64(iotune["write_bytes_sec_max"].(int)),
WriteIOPSSec: uint64(iotune["write_iops_sec"].(int)),
WriteIOPSSecMax: uint64(iotune["write_iops_sec_max"].(int)), WriteIOPSSecMax: uint64(iotune["write_iops_sec_max"].(int)),
SizeIOPSSec: uint64(iotune["size_iops_sec"].(int)),
} }
_, err := c.CloudBroker().Disks().LimitIO(ctx, req) _, err := c.CloudBroker().Disks().LimitIO(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) w.Add(err)
}
}
if shareable := d.Get("shareable"); shareable.(bool) {
_, err := c.CloudBroker().Disks().Share(ctx, disks.ShareRequest{
DiskID: diskID,
})
if err != nil {
w.Add(err)
} }
} }
return resourceDiskRead(ctx, d, m) return append(w.Get(), resourceDiskRead(ctx, d, m)...)
} }
func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
w := dc.Warnings{}
disk, err := utilityDiskCheckPresence(ctx, d, m) disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
hasChangeState := false
switch disk.Status {
case status.Destroyed, status.Purged:
d.Set("disk_id", 0)
d.SetId("")
return resourceDiskCreate(ctx, d, m)
case status.Deleted:
hasChangeState = true
req := disks.RestoreRequest{
DiskID: disk.ID,
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
} else {
req.Reason = "Terraform automatic restore"
}
_, err := c.CloudBroker().Disks().Restore(ctx, req)
if err != nil {
w.Add(err)
}
case status.Assigned:
case status.Modeled:
return diag.Errorf("The disk is in status: %s, please, contact support for more information", disk.Status)
case status.Creating:
case status.Created:
case status.Allocated:
case status.Unallocated:
}
if hasChangeState {
disk, err = utilityDiskCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
flattenDisk(d, disk) flattenDisk(d, disk)
return nil return w.Get()
} }
func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
diskID, _ := strconv.ParseUint(d.Id(), 10, 64) w := dc.Warnings{}
err := checkParamsExists(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
hasChangeState := false
switch disk.Status {
case status.Destroyed, status.Purged:
d.Set("disk_id", 0)
d.SetId("")
return resourceDiskCreate(ctx, d, m)
case status.Deleted:
hasChangeState = true
req := disks.RestoreRequest{
DiskID: disk.ID,
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
} else {
req.Reason = "Terraform automatic restore"
}
_, err := c.CloudBroker().Disks().Restore(ctx, req)
if err != nil {
return diag.FromErr(err)
}
case status.Assigned:
case status.Modeled:
return diag.Errorf("The disk is in status: %s, please, contact support for more information", disk.Status)
case status.Creating:
case status.Created:
case status.Allocated:
case status.Unallocated:
}
if hasChangeState {
disk, err = utilityDiskCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
if d.HasChange("size_max") { if d.HasChange("size_max") {
oldSize, newSize := d.GetChange("size_max") oldSize, newSize := d.GetChange("size_max")
if oldSize.(int) < newSize.(int) { if oldSize.(int) < newSize.(int) {
log.Debugf("resourceDiskUpdate: resizing disk ID %s - %d GB -> %d GB", log.Debugf("resourceDiskUpdate: resizing disk ID %s - %d GB -> %d GB",
d.Id(), oldSize.(int), newSize.(int)) d.Id(), oldSize.(int), newSize.(int))
req := disks.ResizeRequest{
DiskID: diskID,
Size: uint64(newSize.(int)),
}
_, err := c.CloudBroker().Disks().Resize(ctx, req) _, err := c.CloudBroker().Disks().Resize(ctx, disks.ResizeRequest{
DiskID: disk.ID,
Size: uint64(newSize.(int)),
})
if err != nil { if err != nil {
return diag.FromErr(err) w.Add(err)
} }
d.Set("size_max", newSize)
} else if oldSize.(int) > newSize.(int) { } else if oldSize.(int) > newSize.(int) {
return diag.FromErr(fmt.Errorf("resourceDiskUpdate: Disk ID %s - reducing disk size is not allowed", d.Id())) return diag.FromErr(fmt.Errorf("resourceDiskUpdate: Disk ID %s - reducing disk size is not allowed", d.Id()))
} }
} }
if d.HasChange("disk_name") { if d.HasChange("disk_name") {
req := disks.RenameRequest{ _, err := c.CloudBroker().Disks().Rename(ctx, disks.RenameRequest{
DiskID: diskID, DiskID: disk.ID,
Name: d.Get("disk_name").(string), Name: d.Get("disk_name").(string),
} })
_, err := c.CloudBroker().Disks().Rename(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) w.Add(err)
} }
} }
@ -165,44 +269,49 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
iot := d.Get("iotune").([]interface{})[0] iot := d.Get("iotune").([]interface{})[0]
iotune := iot.(map[string]interface{}) iotune := iot.(map[string]interface{})
req := disks.LimitIORequest{ req := disks.LimitIORequest{
DiskID: diskID,
IOPS: uint64(iotune["total_iops_sec"].(int)), IOPS: uint64(iotune["total_iops_sec"].(int)),
TotalBytesSec: uint64(iotune["total_bytes_sec"].(int)),
ReadBytesSec: uint64(iotune["read_bytes_sec"].(int)), ReadBytesSec: uint64(iotune["read_bytes_sec"].(int)),
WriteBytesSec: uint64(iotune["write_bytes_sec"].(int)), ReadBytesSecMax: uint64(iotune["read_bytes_sec_max"].(int)),
TotalIOPSSec: uint64(iotune["total_iops_sec"].(int)),
ReadIOPSSec: uint64(iotune["read_iops_sec"].(int)), ReadIOPSSec: uint64(iotune["read_iops_sec"].(int)),
WriteIOPSSec: uint64(iotune["write_iops_sec"].(int)), ReadIOPSSecMax: uint64(iotune["read_iops_sec_max"].(int)),
SizeIOPSSec: uint64(iotune["size_iops_sec"].(int)),
TotalBytesSec: uint64(iotune["total_bytes_sec"].(int)),
TotalBytesSecMax: uint64(iotune["total_bytes_sec_max"].(int)), TotalBytesSecMax: uint64(iotune["total_bytes_sec_max"].(int)),
ReadBytesSecMax: uint64(iotune["read_bytes_sec_max"].(int)),
WriteBytesSecMax: uint64(iotune["write_bytes_sec_max"].(int)),
TotalIOPSSecMax: uint64(iotune["total_iops_sec_max"].(int)), TotalIOPSSecMax: uint64(iotune["total_iops_sec_max"].(int)),
ReadIOPSSecMax: uint64(iotune["read_iops_sec_max"].(int)), TotalIOPSSec: uint64(iotune["total_iops_sec"].(int)),
WriteBytesSec: uint64(iotune["write_bytes_sec"].(int)),
WriteBytesSecMax: uint64(iotune["write_bytes_sec_max"].(int)),
WriteIOPSSec: uint64(iotune["write_iops_sec"].(int)),
WriteIOPSSecMax: uint64(iotune["write_iops_sec_max"].(int)), WriteIOPSSecMax: uint64(iotune["write_iops_sec_max"].(int)),
SizeIOPSSec: uint64(iotune["size_iops_sec"].(int)),
} }
_, err := c.CloudBroker().Disks().LimitIO(ctx, req) _, err := c.CloudBroker().Disks().LimitIO(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) w.Add(err)
} }
} }
if d.HasChange("restore") { if d.HasChange("shareable") {
if d.Get("restore").(bool) { old, new := d.GetChange("shareable")
req := disks.RestoreRequest{ if !old.(bool) && new.(bool) && !disk.Shareable {
DiskID: diskID, _, err := c.CloudBroker().Disks().Share(ctx, disks.ShareRequest{
Reason: d.Get("reason").(string), DiskID: disk.ID,
})
if err != nil {
w.Add(err)
} }
}
_, err := c.CloudBroker().Disks().Restore(ctx, req) if old.(bool) && !new.(bool) && disk.Shareable {
_, err := c.CloudBroker().Disks().Unshare(ctx, disks.UnshareRequest{
DiskID: disk.ID,
})
if err != nil { if err != nil {
return diag.FromErr(err) w.Add(err)
} }
} }
} }
return resourceDiskRead(ctx, d, m) return append(w.Get(), resourceDiskRead(ctx, d, m)...)
} }
func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@ -210,6 +319,7 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
disk, err := utilityDiskCheckPresence(ctx, d, m) disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@ -225,6 +335,8 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId("")
return nil return nil
} }
@ -233,41 +345,46 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
"account_id": { "account_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
ForceNew: true,
}, },
"disk_name": { "gid": {
Type: schema.TypeString, Type: schema.TypeInt,
Required: true, Required: true,
ForceNew: true,
}, },
"size_max": { "disk_name": {
Type: schema.TypeInt, Type: schema.TypeString,
Required: true, Required: true,
}, },
"gid": { "type": {
Type: schema.TypeInt, Type: schema.TypeString,
Required: true, Required: true,
ValidateFunc: validation.StringInSlice([]string{"D", "B", "T"}, false),
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
}, },
"pool": { "desc": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"sep_id": { "size_max": {
Type: schema.TypeInt,
Required: true,
},
"ssd_size": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true,
}, },
"desc": { "sep_id": {
Type: schema.TypeString, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"type": { "pool": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
ValidateFunc: validation.StringInSlice([]string{"D", "B", "T"}, false),
}, },
"detach": { "detach": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
@ -286,17 +403,17 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Default: "", Default: "",
Description: "reason for an action", Description: "reason for an action",
}, },
"shareable": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"restore": { "restore": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: false, Default: false,
Description: "restore deleting disk", Description: "restore deleting disk",
}, },
"disk_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": { "account_name": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@ -309,6 +426,22 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"computes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"compute_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"created_time": { "created_time": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -333,6 +466,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"disk_id": {
Type: schema.TypeInt,
Computed: true,
},
"image_id": { "image_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -452,7 +589,13 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"purge_attempts": { "purge_attempts": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -481,7 +624,6 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"sep_type": { "sep_type": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@ -503,6 +645,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"res_id": { "res_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

@ -0,0 +1,215 @@
package disks
import (
"context"
"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/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceDiskSnapshotCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
snapshots := disk.Snapshots
snapshot := disks.ItemSnapshot{}
label := d.Get("label").(string)
for _, sn := range snapshots {
if label == sn.Label {
snapshot = sn
break
}
}
if label != snapshot.Label {
return diag.Errorf("Snapshot with label \"%v\" not found", label)
}
if rollback := d.Get("rollback").(bool); rollback {
req := disks.SnapshotRollbackRequest{
DiskID: disk.ID,
Label: label,
TimeStamp: uint64(d.Get("timestamp").(int)),
}
log.Debugf("resourceDiskCreate: Snapshot rollback with label", label)
_, err := c.CloudBroker().Disks().SnapshotRollback(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
return resourceDiskSnapshotRead(ctx, d, m)
}
func resourceDiskSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
snapshots := disk.Snapshots
snapshot := disks.ItemSnapshot{}
label := d.Get("label").(string)
for _, sn := range snapshots {
if label == sn.Label {
snapshot = sn
break
}
}
if label != snapshot.Label {
return diag.Errorf("Snapshot with label \"%v\" not found", label)
}
flattenDiskSnapshot(d, snapshot)
return nil
}
func resourceDiskSnapshotUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
snapshots := disk.Snapshots
snapshot := disks.ItemSnapshot{}
label := d.Get("label").(string)
for _, sn := range snapshots {
if label == sn.Label {
snapshot = sn
break
}
}
if label != snapshot.Label {
return diag.Errorf("Snapshot with label \"%v\" not found", label)
}
if d.HasChange("rollback") && d.Get("rollback").(bool) == true {
req := disks.SnapshotRollbackRequest{
DiskID: disk.ID,
Label: label,
TimeStamp: uint64(d.Get("timestamp").(int)),
}
log.Debugf("resourceDiskUpdtae: Snapshot rollback with label", label)
_, err := c.CloudBroker().Disks().SnapshotRollback(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
return resourceDiskSnapshotRead(ctx, d, m)
}
func resourceDiskSnapshotDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
req := disks.SnapshotDeleteRequest{
DiskID: disk.ID,
Label: d.Get("label").(string),
}
_, err = c.CloudBroker().Disks().SnapshotDelete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceDiskSnapshot() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceDiskSnapshotCreate,
ReadContext: resourceDiskSnapshotRead,
UpdateContext: resourceDiskSnapshotUpdate,
DeleteContext: resourceDiskSnapshotDelete,
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: resourceDiskSnapshotSchemaMake(),
}
}
func resourceDiskSnapshotSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"disk_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "The unique ID of the subscriber-owner of the disk",
},
"label": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Name of the snapshot",
},
"rollback": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Needed in order to make a snapshot rollback",
},
"timestamp": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Snapshot time",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the snapshot",
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,
Description: "Reference to the snapshot",
},
"snap_set_guid": {
Type: schema.TypeString,
Computed: true,
Description: "The set snapshot ID",
},
"snap_set_time": {
Type: schema.TypeInt,
Computed: true,
Description: "The set time of the snapshot",
},
}
}

@ -46,9 +46,9 @@ func utilityDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m int
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := disks.GetRequest{} req := disks.GetRequest{}
if d.Get("disk_id").(int) == 0 { if d.Id() != "" {
id, _ := strconv.ParseUint(d.Id(), 10, 64) diskID, _ := strconv.ParseUint(d.Id(), 10, 64)
req.DiskID = id req.DiskID = diskID
} else { } else {
req.DiskID = uint64(d.Get("disk_id").(int)) req.DiskID = uint64(d.Get("disk_id").(int))
} }

@ -46,17 +46,41 @@ func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := disks.ListRequest{} req := disks.ListRequest{}
if page, ok := d.GetOk("page"); ok { if by_id, ok := d.GetOk("by_id"); ok {
req.Page = uint64(page.(int)) req.ByID = uint64(by_id.(int))
} }
if size, ok := d.GetOk("size"); ok { if name, ok := d.GetOk("name"); ok {
req.Size = uint64(size.(int)) req.Name = name.(string)
}
if account_name, ok := d.GetOk("account_name"); ok {
req.AccountName = account_name.(string)
}
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
req.DiskMaxSize = int64(disk_max_size.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if shared, ok := d.GetOk("shared"); ok {
req.Shared = shared.(bool)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
} }
if diskType, ok := d.GetOk("type"); ok { if diskType, ok := d.GetOk("type"); ok {
req.Type = strings.ToUpper(diskType.(string)) req.Type = strings.ToUpper(diskType.(string))
} }
if accountId, ok := d.GetOk("accountId"); ok { if pool, ok := d.GetOk("pool"); ok {
req.AccountID = uint64(accountId.(int)) req.Pool = pool.(string)
}
if sepID, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sepID.(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("utilityDiskListCheckPresence: load disk list") log.Debugf("utilityDiskListCheckPresence: load disk list")

@ -0,0 +1,85 @@
/*
Copyright (c) 2019-2022 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>
Nikita Sorokin, <nesorokin@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 disks
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/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) {
c := m.(*controller.ControllerCfg)
req := disks.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_name, ok := d.GetOk("account_name"); ok {
req.AccountName = account_name.(string)
}
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
req.DiskMaxSize = int64(disk_max_size.(int))
}
if shared, ok := d.GetOk("shared"); ok {
req.Shared = shared.(bool)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if typev, ok := d.GetOk("type"); ok {
req.Type = typev.(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("utilityDiskListDeletedCheckPresence: load disk list")
diskList, err := c.CloudBroker().Disks().ListDeleted(ctx, req)
if err != nil {
return nil, err
}
return diskList, nil
}

@ -0,0 +1,25 @@
package disks
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/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListTypesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListTypesRequest{
Detailed: false,
}
log.Debugf("utilityDiskListTypesCheckPresence: load disk list Types Detailed")
typesList, err := c.CloudBroker().Disks().ListTypes(ctx, req)
if err != nil {
return nil, err
}
return typesList, nil
}

@ -0,0 +1,27 @@
package disks
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/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListTypesDetailedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
c := m.(*controller.ControllerCfg)
log.Debugf("utilityDiskListTypesDetailedCheckPresence: load disk list Types Detailed")
listTypesDetailed, err := c.CloudBroker().Disks().ListTypes(ctx, disks.ListTypesRequest{
Detailed: true,
})
log.Debugf("%+v", listTypesDetailed.Data[0].(map[string]interface{}))
if err != nil {
return nil, err
}
return listTypesDetailed, nil
}

@ -0,0 +1,54 @@
package disks
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/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListUnattachedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListUnattachedDisks, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListUnattachedRequest{}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if account_name, ok := d.GetOk("account_name"); ok {
req.AccountName = account_name.(string)
}
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
req.DiskMaxSize = int64(disk_max_size.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if diskType, ok := d.GetOk("type"); ok {
req.Type = diskType.(string)
}
if accountId, ok := d.GetOk("accountId"); ok {
req.AccountID = uint64(accountId.(int))
}
if sepId, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sepId.(int))
}
if pool, ok := d.GetOk("pool"); ok {
req.Pool = pool.(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("utilityDiskListUnattachedCheckPresence: load disk Unattached list")
unattachedList, err := c.CloudBroker().Disks().ListUnattached(ctx, req)
if err != nil {
return nil, err
}
return unattachedList, nil
}

@ -56,7 +56,7 @@ func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interfa
func dataSourceExtnetSchemaMake() map[string]*schema.Schema { func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{ return map[string]*schema.Schema{
"net_id": { "extnet_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
}, },
@ -116,10 +116,6 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"extnet_id": {
Type: schema.TypeInt,
Computed: true,
},
"ipcidr": { "ipcidr": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@ -198,6 +194,10 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"desc": {
Type: schema.TypeString,
Computed: true,
},
"domain_name": { "domain_name": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

@ -50,14 +50,14 @@ func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("net_id", extnetId) d.Set("extnet_id", extnetId)
return nil return nil
} }
func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema { func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{ return map[string]*schema.Schema{
"net_id": { "extnet_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },

@ -0,0 +1,107 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
staticRoute, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(staticRoute.ID, 10))
flattenStaticRouteData(d, staticRoute)
return nil
}
func dataSourceStaticRouteSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"extnet_id": {
Type: schema.TypeInt,
Required: true,
Description: "Unique ID of the ExtNet",
},
"route_id": {
Type: schema.TypeInt,
Required: true,
Description: "Unique ID of the static route",
},
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
}
return rets
}
func DataSourceStaticRoute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceStaticRouteRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceStaticRouteSchemaMake(),
}
}

@ -0,0 +1,121 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceStaticRouteListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
staticRouteList, err := utilityStaticRouteListCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenStaticRouteList(staticRouteList))
d.Set("entry_count", staticRouteList.EntryCount)
return nil
}
func dataSourceStaticRouteListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"extnet_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of ExtNet",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
func DataSourceStaticRouteList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceStaticRouteListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceStaticRouteListSchemaMake(),
}
}

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -46,6 +46,7 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
"ckey": item.CKey, "ckey": item.CKey,
"meta": flattens.FlattenMeta(item.Meta), "meta": flattens.FlattenMeta(item.Meta),
"default": item.Default, "default": item.Default,
"default_qos": flattenExtnetDefaultQos(item.DefaultQOS),
"desc": item.Description, "desc": item.Description,
"free_ips": item.FreeIPs, "free_ips": item.FreeIPs,
"gid": item.GID, "gid": item.GID,
@ -62,6 +63,7 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
"status": item.Status, "status": item.Status,
"vlan_id": item.VLANID, "vlan_id": item.VLANID,
"check_ips": item.CheckIPs, "check_ips": item.CheckIPs,
"vnfs": flattenExtnetVNFS(item.VNFs),
} }
res = append(res, temp) res = append(res, temp)
@ -73,7 +75,6 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) { func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) {
d.Set("ckey", recNet.CKey) d.Set("ckey", recNet.CKey)
d.Set("meta", flattens.FlattenMeta(recNet.Meta)) d.Set("meta", flattens.FlattenMeta(recNet.Meta))
d.Set("default", recNet.Default) d.Set("default", recNet.Default)
d.Set("desc", recNet.Description) d.Set("desc", recNet.Description)
d.Set("free_ips", recNet.FreeIPs) d.Set("free_ips", recNet.FreeIPs)
@ -96,17 +97,49 @@ func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) {
d.Set("gateway", recNet.Gateway) d.Set("gateway", recNet.Gateway)
d.Set("network", recNet.Network) d.Set("network", recNet.Network)
d.Set("prefix", recNet.Prefix) d.Set("prefix", recNet.Prefix)
d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS))
d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs))
d.Set("reservations", flattenExtnetReservations(recNet.Reservations))
}
func flattenRecordExtnetResource(d *schema.ResourceData, recNet *extnet.RecordExtNet, staticRouteList *extnet.ListStaticRoutes) {
d.Set("ckey", recNet.CKey)
d.Set("meta", flattens.FlattenMeta(recNet.Meta))
d.Set("default", recNet.Default)
d.Set("desc", recNet.Description)
d.Set("free_ips", recNet.FreeIPs)
d.Set("gid", recNet.GID)
d.Set("guid", recNet.GUID)
d.Set("extnet_id", recNet.ID)
d.Set("ipcidr", recNet.IPCIDR)
d.Set("milestones", recNet.Milestones)
d.Set("name", recNet.Name)
d.Set("network_id", recNet.NetworkID)
d.Set("ovs_bridge", recNet.OVSBridge)
d.Set("pre_reservations_num", recNet.PreReservationsNum)
d.Set("pri_vnfdev_id", recNet.PriVNFDevID)
d.Set("shared_with", recNet.SharedWith)
d.Set("status", recNet.Status)
d.Set("vlan_id", recNet.VLANID)
d.Set("check_ips", recNet.CheckIPs)
d.Set("dns", recNet.DNS)
d.Set("excluded", flattenExtnetExcluded(recNet.Excluded))
d.Set("gateway", recNet.Gateway)
d.Set("network", recNet.Network)
d.Set("prefix", recNet.Prefix)
d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS)) d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS))
d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs)) d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs))
d.Set("reservations", flattenExtnetReservations(recNet.Reservations)) d.Set("reservations", flattenExtnetReservations(recNet.Reservations))
d.Set("routes", flattenStaticRouteList(staticRouteList))
} }
func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} { func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, er := range ers { for _, er := range ers {
temp := map[string]interface{}{ temp := map[string]interface{}{
"client_type": er.ClientType, "client_type": er.ClientType,
"desc": er.Description,
"domain_name": er.DomainName, "domain_name": er.DomainName,
"hostname": er.Hostname, "hostname": er.Hostname,
"ip": er.IP, "ip": er.IP,
@ -159,3 +192,29 @@ func flattenExtnetDefaultQos(edqos extnet.QOS) []map[string]interface{} {
res = append(res, temp) res = append(res, temp)
return res return res
} }
func flattenStaticRouteList(sr *extnet.ListStaticRoutes) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(sr.Data))
for _, staticRoute := range sr.Data {
temp := map[string]interface{}{
"route_id": staticRoute.ID,
"destination": staticRoute.Destination,
"gateway": staticRoute.Gateway,
"guid": staticRoute.GUID,
"netmask": staticRoute.Netmask,
"compute_ids": staticRoute.ComputeIds,
}
res = append(res, temp)
}
return res
}
func flattenStaticRouteData(d *schema.ResourceData, route *extnet.ItemRoutes) {
d.Set("destination", route.Destination)
d.Set("gateway", route.Gateway)
d.Set("guid", route.GUID)
d.Set("netmask", route.Netmask)
d.Set("compute_ids", route.ComputeIds)
d.Set("route_id", route.ID)
}

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -43,12 +43,17 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "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/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
) )
func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("cloudbroker: resourceExtnetCreate called with name '%s'", d.Get("name").(string)) log.Debugf("cloudbroker: resourceExtnetCreate called with name '%s'", d.Get("name").(string))
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
if err := ic.ExistGID(ctx, uint64(d.Get("gid").(int)), c); err != nil {
return diag.FromErr(err)
}
req := extnet.CreateRequest{ req := extnet.CreateRequest{
Name: d.Get("name").(string), Name: d.Get("name").(string),
GID: uint64(d.Get("gid").(int)), GID: uint64(d.Get("gid").(int)),
@ -122,6 +127,7 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
} }
d.SetId(strconv.FormatUint(netID, 10)) d.SetId(strconv.FormatUint(netID, 10))
d.Set("extnet_id", netID)
log.Debugf("cloudbroker: Extnet with id %d successfully created on platform", netID) log.Debugf("cloudbroker: Extnet with id %d successfully created on platform", netID)
if d.Get("excluded_ips").(*schema.Set).Len() > 0 { if d.Get("excluded_ips").(*schema.Set).Len() > 0 {
@ -163,8 +169,12 @@ func resourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
staticRouteList, err := utilityStaticRouteListInResourceCheckPresence(ctx, m, recNet.ID)
if err != nil {
return diag.FromErr(err)
}
flattenRecordExtnet(d, recNet) flattenRecordExtnetResource(d, recNet, staticRouteList)
return nil return nil
} }
@ -219,6 +229,35 @@ func resourceExtnetUpdate(ctx context.Context, d *schema.ResourceData, m interfa
} }
} }
if d.HasChange("excluded_ips_range") {
if err := handleExcludedIPsRangeUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("shared_with") {
if err := handleSharedWithUpdate(ctx, d, c); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("virtual") {
if err := handleVirtualUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("restart") {
if err := handleRestartUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("migrate") {
if err := handleMigrateUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
return resourceExtnetRead(ctx, d, m) return resourceExtnetRead(ctx, d, m)
} }
@ -253,13 +292,13 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
"ipcidr": { "ipcidr": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, // ForceNew: true,
Description: "IP network CIDR", Description: "IP network CIDR",
}, },
"vlan_id": { "vlan_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
ForceNew: true, // ForceNew: true,
Description: "VLAN ID", Description: "VLAN ID",
}, },
"gateway": { "gateway": {
@ -352,6 +391,23 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
}, },
Description: "IPs to exclude in current extnet pool", Description: "IPs to exclude in current extnet pool",
}, },
"excluded_ips_range": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_start": {
Type: schema.TypeString,
Required: true,
},
"ip_end": {
Type: schema.TypeString,
Required: true,
},
},
},
Description: "Range of IPs to exclude in current extnet pool",
},
"default_qos": { "default_qos": {
Type: schema.TypeList, Type: schema.TypeList,
MaxItems: 1, MaxItems: 1,
@ -381,6 +437,15 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
}, },
}, },
}, },
"restart":{
Type: schema.TypeBool,
Optional: true,
Description: "restart extnet vnf device",
},
"migrate":{
Type: schema.TypeInt,
Optional: true,
},
"ckey": { "ckey": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@ -488,6 +553,41 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"routes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"reservations": { "reservations": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
@ -540,6 +640,10 @@ func ResourceExtnetCB() *schema.Resource {
UpdateContext: resourceExtnetUpdate, UpdateContext: resourceExtnetUpdate,
DeleteContext: resourceExtnetDelete, DeleteContext: resourceExtnetDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{ Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout300s, Read: &constants.Timeout300s,
Create: &constants.Timeout300s, Create: &constants.Timeout300s,

@ -0,0 +1,259 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"context"
"fmt"
"strconv"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceStaticRouteCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
if err := ic.ExistExtNet(ctx, uint64(d.Get("extnet_id").(int)), c); err != nil {
return diag.FromErr(err)
}
req := extnet.StaticRouteAddRequest{
ExtNetId: uint64(d.Get("extnet_id").(int)),
Destination: d.Get("destination").(string),
Netmask: d.Get("netmask").(string),
Gateway: d.Get("gateway").(string),
}
if computesIDS, ok := d.GetOk("compute_ids"); ok {
ids := computesIDS.([]interface{})
res := make([]uint64, 0, len (ids))
for _, id := range ids {
computeId := uint64(id.(int))
res = append(res, computeId)
}
req.ComputeIds = res
}
_, err := c.CloudBroker().ExtNet().StaticRouteAdd(ctx, req)
if err != nil {
return diag.FromErr(err)
}
staticRouteData, err := getStaticRouteData(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
d.SetId(fmt.Sprintf("%d#%d", req.ExtNetId, staticRouteData.ID))
return resourceStaticRouteRead(ctx, d, m)
}
func resourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
warnings := dc.Warnings{}
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenStaticRouteData(d, staticRouteData)
return warnings.Get()
}
func resourceStaticRouteUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
warnings := dc.Warnings{}
if err := ic.ExistExtNet(ctx, uint64(d.Get("extnet_id").(int)), c); err != nil {
return diag.FromErr(err)
}
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if d.HasChange("compute_ids") {
deletedIds := make([]uint64, 0)
addedIds := make([]uint64, 0)
oldComputeIds, newComputeIds := d.GetChange("compute_ids")
oldComputeIdsSlice := oldComputeIds.([]interface{})
newComputeIdsSlice := newComputeIds.([]interface{})
for _, el := range oldComputeIdsSlice {
if !isContainsIds(newComputeIdsSlice, el) {
convertedEl := uint64(el.(int))
deletedIds = append(deletedIds, convertedEl)
}
}
for _, el := range newComputeIdsSlice {
if !isContainsIds(oldComputeIdsSlice, el) {
convertedEl := uint64(el.(int))
addedIds = append(addedIds, convertedEl)
}
}
if len(deletedIds) > 0 {
req := extnet.StaticRouteAccessRevokeRequest{
ExtNetID: uint64(d.Get("extnet_id").(int)),
RouteId: staticRouteData.ID,
ComputeIds: deletedIds,
}
_, err := c.CloudBroker().ExtNet().StaticRouteAccessRevoke(ctx, req)
if err != nil {
warnings.Add(err)
}
}
if len(addedIds) > 0 {
req := extnet.StaticRouteAccessGrantRequest{
ExtNetID: uint64(d.Get("extnet_id").(int)),
RouteId: staticRouteData.ID,
ComputeIds: addedIds,
}
_, err := c.CloudBroker().ExtNet().StaticRouteAccessGrant(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
return append(warnings.Get(), resourceStaticRouteRead(ctx, d, m)...)
}
func resourceStaticRouteDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
req := extnet.StaticRouteDelRequest{}
arr := strings.Split(d.Id(), "#")
if len(arr) != 2 {
return diag.Errorf("broken state id - %s", d.Id())
}
req.ExtNetID, _ = strconv.ParseUint(arr[0], 10, 64)
req.RouteId, _ = strconv.ParseUint(arr[1], 10, 64)
_, err := c.CloudBroker().ExtNet().StaticRouteDel(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceStaticRouteSchemaMake() map[string]*schema.Schema {
rets := dataSourceStaticRouteSchemaMake()
rets["route_id"] = &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Optional: true,
}
rets["compute_ids"] = &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
}
rets["destination"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
rets["gateway"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
rets["netmask"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
return rets
}
func isContainsIds(els []interface{}, el interface{}) bool {
convEl := el.(int)
for _, elOld := range els {
if convEl == elOld.(int) {
return true
}
}
return false
}
func ResourceStaticRoute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceStaticRouteCreate,
ReadContext: resourceStaticRouteRead,
UpdateContext: resourceStaticRouteUpdate,
DeleteContext: resourceStaticRouteDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout20m,
Read: &constants.Timeout600s,
Update: &constants.Timeout20m,
Delete: &constants.Timeout600s,
Default: &constants.Timeout600s,
},
Schema: resourceStaticRouteSchemaMake(),
}
}

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -38,245 +38,20 @@ import (
"strconv" "strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
) )
func handleExcludedIPsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
old_set, new_set := d.GetChange("excluded_ips")
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
if detach_set.Len() > 0 {
ips := make([]string, 0)
for _, detach_ip := range detach_set.List() {
ips = append(ips, detach_ip.(string))
}
log.Debugf("cloudbroker: removing %d IP address(es) from excluded list", detach_set.Len())
req := extnet.IPsIncludeRequest{
NetID: recNet.ID,
IPs: ips,
}
_, err := c.CloudBroker().ExtNet().IPsInclude(ctx, req)
if err != nil {
return err
}
}
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
if attach_set.Len() > 0 {
ips := make([]string, 0)
for _, attach_ip := range attach_set.List() {
ips = append(ips, attach_ip.(string))
}
log.Debugf("cloudbroker: excluding %d IP address(es) from extnet with id %d", attach_set.Len(), recNet.ID)
req := extnet.IPsExcludeRequest{
NetID: recNet.ID,
IPs: ips,
}
_, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleSetDefault(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
set_default := d.Get("set_default").(bool)
if set_default && recNet.Default == false {
req := extnet.SetDefaultRequest{
NetID: recNet.ID,
}
_, err := c.CloudBroker().ExtNet().SetDefault(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
doBasicUpdate := false
basiUpdateReq := extnet.UpdateRequest{NetID: recNet.ID}
if d.HasChange("name") {
basiUpdateReq.Name = d.Get("name").(string)
doBasicUpdate = true
}
if d.HasChange("desc") {
basiUpdateReq.Description = d.Get("desc").(string)
doBasicUpdate = true
}
if doBasicUpdate {
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
if err != nil {
return err
}
}
return nil
}
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
enable := d.Get("enable").(bool)
if enable {
if recNet.Status == status.Disabled {
req := extnet.EnableRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().Enable(ctx, req)
if err != nil {
return err
}
}
} else {
if recNet.Status == status.Enabled {
req := extnet.DisableRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().Disable(ctx, req)
if err != nil {
return err
}
}
}
return nil
}
func handleDefaultQOSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
qos := d.Get("default_qos").([]interface{})[0].(map[string]interface{})
req := extnet.DefaultQOSUpdateRequest{
NetID: recNet.ID,
IngressRate: uint64(qos["in_rate"].(int)),
IngressBurst: uint64(qos["in_burst"].(int)),
EgressRate: uint64(qos["e_rate"].(int)),
}
_, err := c.CloudBroker().ExtNet().DefaultQOSUpdate(ctx, req)
if err != nil {
return err
}
return nil
}
func handleNTPUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
changed_list := d.Get("ntp").([]interface{})
ntp_list := make([]string, 0)
for _, ntp_address := range changed_list {
ntp_list = append(ntp_list, ntp_address.(string))
}
req := extnet.NTPApplyRequest{
NetID: recNet.ID,
NTPList: ntp_list,
}
_, err := c.CloudBroker().ExtNet().NTPApply(ctx, req)
if err != nil {
return err
}
return nil
}
func handleDNSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
changed_list := d.Get("dns").([]interface{})
dns_list := make([]string, 0)
for _, dns_address := range changed_list {
dns_list = append(dns_list, dns_address.(string))
}
req := extnet.DNSApplyRequest{
NetID: recNet.ID,
DNSList: dns_list,
}
_, err := c.CloudBroker().ExtNet().DNSApply(ctx, req)
if err != nil {
return err
}
return nil
}
func utilityExtnetDefaultCheckPresence(ctx context.Context, m interface{}) (uint64, error) {
c := m.(*controller.ControllerCfg)
return c.CloudBroker().ExtNet().GetDefault(ctx)
}
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNet, error) {
c := m.(*controller.ControllerCfg)
req := extnet.ListRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if network, ok := d.GetOk("network"); ok {
req.Network = network.(string)
}
if vlan_id, ok := d.GetOk("vlan_id"); ok {
req.VLANID = uint64(vlan_id.(int))
}
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
req.VNFDevID = uint64(vnfdev_id.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
res, err := c.CloudBroker().ExtNet().List(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}
func utilityExtnetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.RecordExtNet, error) { func utilityExtnetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.RecordExtNet, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
var netId uint64
if id, ok := d.GetOk("net_id"); ok { req := extnet.GetRequest{}
netId = uint64(id.(int))
} else {
parsed, _ := strconv.ParseUint(d.Id(), 10, 64)
netId = parsed
}
req := extnet.GetRequest{ if d.Id() != "" {
NetID: netId, netId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.NetID = netId
} else {
req.NetID = uint64(d.Get("extnet_id").(int))
} }
res, err := c.CloudBroker().ExtNet().Get(ctx, req) res, err := c.CloudBroker().ExtNet().Get(ctx, req)

@ -1,8 +1,18 @@
/* /*
<<<<<<<< HEAD:internal/dc/utils.go
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
========
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
>>>>>>>> dev:internal/service/cloudbroker/extnet/utility_extnet_default.go
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
<<<<<<<< HEAD:internal/dc/utils.go
Nikita Sorokin, <nesorokin@basistech.ru>
========
Tim Tkachev, <tvtkachev@basistech.ru>
>>>>>>>> dev:internal/service/cloudbroker/extnet/utility_extnet_default.go
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -29,35 +39,16 @@ builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package extnet
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" import (
"context"
func dataSourceAccountDiskSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{ "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"disk_id": { )
Type: schema.TypeInt,
Computed: true, func utilityExtnetDefaultCheckPresence(ctx context.Context, m interface{}) (uint64, error) {
}, c := m.(*controller.ControllerCfg)
"disk_name": {
Type: schema.TypeString, return c.CloudBroker().ExtNet().GetDefault(ctx)
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
}
} }

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

@ -0,0 +1,360 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
)
func handleExcludedIPsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
old_set, new_set := d.GetChange("excluded_ips")
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
if detach_set.Len() > 0 {
ips := make([]string, 0)
for _, detach_ip := range detach_set.List() {
ips = append(ips, detach_ip.(string))
}
log.Debugf("cloudbroker: removing %d IP address(es) from excluded list", detach_set.Len())
req := extnet.IPsIncludeRequest{
NetID: recNet.ID,
IPs: ips,
}
_, err := c.CloudBroker().ExtNet().IPsInclude(ctx, req)
if err != nil {
return err
}
}
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
if attach_set.Len() > 0 {
ips := make([]string, 0)
for _, attach_ip := range attach_set.List() {
ips = append(ips, attach_ip.(string))
}
log.Debugf("cloudbroker: excluding %d IP address(es) from extnet with id %d", attach_set.Len(), recNet.ID)
req := extnet.IPsExcludeRequest{
NetID: recNet.ID,
IPs: ips,
}
_, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleSetDefault(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
set_default := d.Get("set_default").(bool)
if set_default && !recNet.Default {
req := extnet.SetDefaultRequest{
NetID: recNet.ID,
}
_, err := c.CloudBroker().ExtNet().SetDefault(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
doBasicUpdate := false
basiUpdateReq := extnet.UpdateRequest{NetID: recNet.ID}
if d.HasChange("name") {
basiUpdateReq.Name = d.Get("name").(string)
doBasicUpdate = true
}
if d.HasChange("desc") {
basiUpdateReq.Description = d.Get("desc").(string)
doBasicUpdate = true
}
if doBasicUpdate {
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
if err != nil {
return err
}
}
return nil
}
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
enable := d.Get("enable").(bool)
if enable {
if recNet.Status == status.Disabled {
req := extnet.EnableRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().Enable(ctx, req)
if err != nil {
return err
}
}
} else {
if recNet.Status == status.Enabled {
req := extnet.DisableRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().Disable(ctx, req)
if err != nil {
return err
}
}
}
return nil
}
func handleDefaultQOSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
qos := d.Get("default_qos").([]interface{})[0].(map[string]interface{})
req := extnet.DefaultQOSUpdateRequest{
NetID: recNet.ID,
IngressRate: uint64(qos["in_rate"].(int)),
IngressBurst: uint64(qos["in_burst"].(int)),
EgressRate: uint64(qos["e_rate"].(int)),
}
_, err := c.CloudBroker().ExtNet().DefaultQOSUpdate(ctx, req)
if err != nil {
return err
}
return nil
}
func handleNTPUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
changed_list := d.Get("ntp").([]interface{})
ntp_list := make([]string, 0)
for _, ntp_address := range changed_list {
ntp_list = append(ntp_list, ntp_address.(string))
}
req := extnet.NTPApplyRequest{
NetID: recNet.ID,
NTPList: ntp_list,
}
_, err := c.CloudBroker().ExtNet().NTPApply(ctx, req)
if err != nil {
return err
}
return nil
}
func handleDNSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
changed_list := d.Get("dns").([]interface{})
dns_list := make([]string, 0)
for _, dns_address := range changed_list {
dns_list = append(dns_list, dns_address.(string))
}
req := extnet.DNSApplyRequest{
NetID: recNet.ID,
DNSList: dns_list,
}
_, err := c.CloudBroker().ExtNet().DNSApply(ctx, req)
if err != nil {
return err
}
return nil
}
func handleExcludedIPsRangeUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
old_set, new_set := d.GetChange("excluded_ips_range")
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
if detach_set.Len() > 0 {
for _, detach_ip_range := range detach_set.List() {
log.Debugf("cloudbroker: removing range of IP addreses from excluded range list")
req := extnet.IPsIncludeRangeRequest{
NetID: recNet.ID,
IPStart: detach_ip_range.(map[string]interface{})["ip_start"].(string),
IPEnd: detach_ip_range.(map[string]interface{})["ip_end"].(string),
}
_, err := c.CloudBroker().ExtNet().IPsIncludeRange(ctx, req)
if err != nil {
return err
}
}
}
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
if attach_set.Len() > 0 {
for _, attach_ip_range := range attach_set.List() {
log.Debugf("cloudbroker: excluding range of IP addreses from excluded range list")
req := extnet.IPsExcludeRangeRequest{
NetID: recNet.ID,
IPStart: attach_ip_range.(map[string]interface{})["ip_start"].(string),
IPEnd: attach_ip_range.(map[string]interface{})["ip_end"].(string),
}
_, err := c.CloudBroker().ExtNet().IPsExcludeRange(ctx, req)
if err != nil {
return err
}
}
}
return nil
}
func handleSharedWithUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) error {
deletedIds := make([]uint64, 0)
addedIds := make([]uint64, 0)
oldAccountIds, newAccountIds := d.GetChange("shared_with")
oldAccountIdsSlice := oldAccountIds.([]interface{})
newAccountIdsSlice := newAccountIds.([]interface{})
for _, el := range oldAccountIdsSlice {
if !isContainsIds(newAccountIdsSlice, el) {
convertedEl := uint64(el.(int))
deletedIds = append(deletedIds, convertedEl)
}
}
for _, el := range newAccountIdsSlice {
if !isContainsIds(oldAccountIdsSlice, el) {
convertedEl := uint64(el.(int))
addedIds = append(addedIds, convertedEl)
}
}
if len(deletedIds) > 0 {
for _, accountId := range deletedIds {
req := extnet.AccessRemoveRequest{
NetID: uint64(d.Get("extnet_id").(int)),
AccountID: accountId,
}
_, err := c.CloudBroker().ExtNet().AccessRemove(ctx, req)
if err != nil {
return err
}
}
}
if len(addedIds) > 0 {
for _, accountId := range addedIds {
req := extnet.AccessAddRequest{
NetID: uint64(d.Get("extnet_id").(int)),
AccountID: accountId,
}
_, err := c.CloudBroker().ExtNet().AccessAdd(ctx, req)
if err != nil {
return err
}
}
}
return nil
}
func handleVirtualUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
virtualOld, virtualNew := d.GetChange("virtual")
if virtualOld == false && virtualNew == true {
req := extnet.DeviceRemoveRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().DeviceRemove(ctx, req)
if err != nil {
return err
}
} else if virtualOld == true && virtualNew == false {
req := extnet.DeviceDeployRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().DeviceDeploy(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleRestartUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
restartOld, restartNew := d.GetChange("restart")
if restartOld == false && restartNew == true {
req := extnet.DeviceRestartRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().DeviceRestart(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleMigrateUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
stackId := uint64(d.Get("migrate").(int))
if err := ic.ExistStack(ctx, stackId, c); err != nil {
return err
}
req := extnet.DeviceMigrateRequest{
NetID: recNet.ID,
StackID: stackId,
}
_, err := c.CloudBroker().ExtNet().DeviceMigrate(ctx, req)
if err != nil {
return err
}
return nil
}

@ -0,0 +1,108 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"context"
"fmt"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityDataStaticRouteCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ItemRoutes, error) {
c := m.(*controller.ControllerCfg)
req := extnet.StaticRouteListRequest{}
var routeId uint64
if d.Id() != "" {
arr := strings.Split(d.Id(), "#")
if len(arr) != 2 {
return nil, fmt.Errorf("broken state id")
}
req.ExtNetID, _ = strconv.ParseUint(arr[0], 10, 64)
routeId, _ = strconv.ParseUint(arr[1], 10, 64)
} else {
req.ExtNetID = uint64(d.Get("extnet_id").(int))
routeId = uint64(d.Get("route_id").(int))
}
log.Debugf("utilityStaticRouteCheckPresence, extnet id: %v", req.ExtNetID)
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
if err != nil {
return nil, err
}
log.Debugf("utilityStaticRouteCheckPresence: ROUTE ID %v", routeId)
staticRoute := extnet.ItemRoutes{}
for _, route := range staticRouteList.Data {
if routeId == route.ID {
staticRoute = route
return &staticRoute, nil
}
}
return nil, fmt.Errorf("static route not found")
}
func getStaticRouteData(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ItemRoutes, error) {
c := m.(*controller.ControllerCfg)
req := extnet.StaticRouteListRequest{}
req.ExtNetID = uint64(d.Get("extnet_id").(int))
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
if err != nil {
return nil, err
}
destination := d.Get("destination").(string)
gateway := d.Get("gateway").(string)
staticRoute := extnet.ItemRoutes{}
for _, route := range staticRouteList.Data {
if destination == route.Destination && gateway == route.Gateway {
staticRoute = route
return &staticRoute, nil
}
}
return nil, fmt.Errorf("static route not found")
}

@ -0,0 +1,73 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityStaticRouteListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListStaticRoutes, error) {
c := m.(*controller.ControllerCfg)
req := extnet.StaticRouteListRequest{}
req.ExtNetID = uint64(d.Get("extnet_id").(int))
log.Debugf("utilityStaticRouteListCheckPresence")
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
if err != nil {
return nil, err
}
return staticRouteList, nil
}
func utilityStaticRouteListInResourceCheckPresence(ctx context.Context, m interface{}, extnetId uint64) (*extnet.ListStaticRoutes, error) {
c := m.(*controller.ControllerCfg)
req := extnet.StaticRouteListRequest{
ExtNetID: extnetId,
}
log.Debugf("utilityStaticRouteListInResourceCheckPresence")
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
if err != nil {
return nil, err
}
return staticRouteList, nil
}

@ -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(),
}
}

@ -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(),
}
}

@ -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
}

@ -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
}

@ -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(),
}
}

@ -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
}

@ -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
}

@ -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
}

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>

@ -0,0 +1,117 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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 grid
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/constants"
)
func dataSourceGridGetDiagnosisRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diagnosis, err := utilityGridGetDiagnosisCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
d.SetId(d.Id())
d.Set("diagnosis", diagnosis)
return nil
}
func dataSourceGridGetDiagnosisSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"gid": {
Type: schema.TypeInt,
Required: true,
},
"diagnosis": {
Type: schema.TypeString,
Computed: true,
},
}
}
func DataSourceGridGetDiagnosis() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceGridGetDiagnosisRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceGridGetDiagnosisSchemaMake(),
}
}
func dataSourceGridPostDiagnosisRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diagnosis, err := utilityGridPostDiagnosisCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
d.SetId(d.Id())
d.Set("diagnosis", diagnosis)
return nil
}
func dataSourceGridPostDiagnosisSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"gid": {
Type: schema.TypeInt,
Required: true,
},
"diagnosis": {
Type: schema.TypeString,
Computed: true,
},
}
}
func DataSourceGridPostDiagnosis() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceGridPostDiagnosisRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceGridPostDiagnosisSchemaMake(),
}
}

@ -0,0 +1,112 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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 grid
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 dataSourceGridGetStatusRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
grid, err := utilityGridGetStatusCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("status", grid)
return nil
}
func dataSourceGridGetStatusSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"status": {
Type: schema.TypeBool,
Computed: true,
},
}
}
func DataSourceGridGetStatus() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceGridGetStatusRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceGridGetStatusSchemaMake(),
}
}
func dataSourceGridPostStatusRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
grid, err := utilityGridPostStatusCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("status", grid)
return nil
}
func dataSourceGridPostStatusSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"status": {
Type: schema.TypeBool,
Computed: true,
},
}
}
func DataSourceGridPostStatus() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceGridPostStatusRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceGridPostStatusSchemaMake(),
}
}

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -48,12 +48,22 @@ func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m inter
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenGridList(gridList)) d.Set("items", flattenGridList(gridList))
d.Set("entry_count", gridList.EntryCount)
return nil return nil
} }
func dataSourceGridListSchemaMake() map[string]*schema.Schema { func dataSourceGridListSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{ rets := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "by id",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "name",
},
"page": { "page": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
@ -72,6 +82,11 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
Schema: dataSourceGridSchemaMake(), Schema: dataSourceGridSchemaMake(),
}, },
}, },
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry count",
},
} }
return rets return rets
@ -79,6 +94,134 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
func dataSourceGridSchemaMake() map[string]*schema.Schema { func dataSourceGridSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{ return map[string]*schema.Schema{
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"current": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Computed: true,
},
"ext_ips": {
Type: schema.TypeInt,
Computed: true,
},
"ext_traffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Computed: true,
},
"ext_ips": {
Type: schema.TypeInt,
Computed: true,
},
"ext_traffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
},
},
},
"flag": { "flag": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

@ -0,0 +1,99 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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 grid
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 dataSourceGridListEmailsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
gridListEmails, err := utilityGridListEmailsCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", gridListEmails.Data)
d.Set("entry_count", gridListEmails.EntryCount)
return nil
}
func dataSourceGridListEmailsSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Description: "grid list emails",
Elem: &schema.Schema {
Type: schema.TypeString,
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry count",
},
}
return rets
}
func DataSourceGridListEmails() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceGridListEmailsRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceGridListEmailsSchemaMake(),
}
}

@ -0,0 +1,197 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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 grid
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 dataSourceGridGetConsumptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
gridGetConsumption, err := utilityGridGetConsumptionCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(gridGetConsumption.GID, 10))
d.Set("consumed", flattenGridRecordResource(gridGetConsumption.Consumed))
d.Set("reserved", flattenGridRecordResource(gridGetConsumption.Reserved))
return nil
}
func dataSourceGridGetConsumptionSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"grid_id": {
Type: schema.TypeInt,
Required: true,
},
"consumed": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Computed: true,
},
"ext_ips": {
Type: schema.TypeInt,
Computed: true,
},
"ext_traffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Computed: true,
},
"ext_ips": {
Type: schema.TypeInt,
Computed: true,
},
"ext_traffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
}
}
func DataSourceGridGetConsumption() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceGridGetConsumptionRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceGridGetConsumptionSchemaMake(),
}
}

@ -0,0 +1,217 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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 grid
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 dataSourceGridListConsumptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
gridListConsumption, err := utilityGridListConsumptionCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenGridListConsumption(gridListConsumption))
d.Set("entry_count", gridListConsumption.EntryCount)
return nil
}
func dataSourceGridListConsumptionSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"items": {
Type: schema.TypeList,
Computed: true,
Description: "grid list consumption",
Elem: &schema.Resource{
Schema: dataSourceGridConsumptionSchemaMake(),
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry count",
},
}
return rets
}
func dataSourceGridConsumptionSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"consumed": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Computed: true,
},
"ext_ips": {
Type: schema.TypeInt,
Computed: true,
},
"ext_traffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Computed: true,
},
"ext_ips": {
Type: schema.TypeInt,
Computed: true,
},
"ext_traffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func DataSourceGridListConsumption() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceGridListConsumptionRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceGridListConsumptionSchemaMake(),
}
}

@ -15,9 +15,10 @@ func flattenGrid(d *schema.ResourceData, grid *grid.RecordGrid) {
} }
func flattenGridList(gl *grid.ListGrids) []map[string]interface{} { func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0, len(gl.Data))
for _, item := range gl.Data { for _, item := range gl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"resources": flattenGridResources(item.Resources),
"name": item.Name, "name": item.Name,
"flag": item.Flag, "flag": item.Flag,
"gid": item.GID, "gid": item.GID,
@ -25,8 +26,62 @@ func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
"location_code": item.LocationCode, "location_code": item.LocationCode,
"id": item.ID, "id": item.ID,
} }
res = append(res, temp)
}
return res
}
func flattenGridListConsumption(gl *grid.ListResourceConsumption) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(gl.Data))
for _, item := range gl.Data {
temp := map[string]interface{}{
"consumed": flattenGridRecordResource(item.Consumed),
"reserved": flattenGridRecordResource(item.Reserved),
"id": item.GID,
}
res = append(res, temp)
}
return res
}
func flattenGridResources(r grid.Resources) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"current": flattenGridRecordResource(r.Current),
"reserved": flattenGridRecordResource(r.Reserved),
}
res = append(res, temp) res = append(res, temp)
return res
}
func flattenGridRecordResource(rr grid.RecordResource) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cpu": rr.CPU,
"disk_size": rr.DiskSize,
"disk_size_max": rr.DiskSizeMax,
"ext_ips": rr.ExtIPs,
"ext_traffic": rr.ExtTraffic,
"gpu": rr.GPU,
"ram": rr.RAM,
"seps": flattenGridSeps(rr.SEPs),
}
res = append(res, temp)
return res
}
func flattenGridSeps(seps map[string]map[string]grid.DiskUsage) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for sepKey, sepVal := range seps {
for dataKey, dataVal := range sepVal {
temp := map[string]interface{}{
"sep_id": sepKey,
"data_name": dataKey,
"disk_size": dataVal.DiskSize,
"disk_size_max": dataVal.DiskSizeMax,
}
res = append(res, temp)
}
} }
return res return res
} }

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@ -33,7 +33,7 @@ package grid
import ( import (
"context" "context"
"errors" "strconv"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
@ -46,10 +46,11 @@ func utilityGridCheckPresence(ctx context.Context, d *schema.ResourceData, m int
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := grid.GetRequest{} req := grid.GetRequest{}
if gridId, ok := d.GetOk("grid_id"); ok { if d.Id() != "" {
req.GID = uint64(gridId.(int)) id, _ := strconv.ParseUint(d.Id(), 10, 64)
req.GID = id
} else { } else {
return nil, errors.New("grid_id is required") req.GID = uint64(d.Get("grid_id").(int))
} }
log.Debugf("utilityGridCheckPresence: load grid") log.Debugf("utilityGridCheckPresence: load grid")

@ -1,8 +1,9 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -29,18 +30,35 @@ builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package kvmvm package grid
const KvmX86CreateAPI = "/restmachine/cloudbroker/kvmx86/create" import (
const KvmPPCCreateAPI = "/restmachine/cloudbroker/kvmppc/create" "context"
const ComputeGetAPI = "/restmachine/cloudbroker/compute/get" "strconv"
const RgListComputesAPI = "/restmachine/cloudbroker/rg/listComputes"
const ComputeNetAttachAPI = "/restmachine/cloudbroker/compute/netAttach" log "github.com/sirupsen/logrus"
const ComputeNetDetachAPI = "/restmachine/cloudbroker/compute/netDetach" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
const ComputeDiskAttachAPI = "/restmachine/cloudbroker/compute/diskAttach" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
const ComputeDiskDetachAPI = "/restmachine/cloudbroker/compute/diskDetach"
const ComputeStartAPI = "/restmachine/cloudbroker/compute/start" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
const ComputeStopAPI = "/restmachine/cloudbroker/compute/stop" )
const ComputeResizeAPI = "/restmachine/cloudbroker/compute/resize"
const DisksResizeAPI = "/restmachine/cloudbroker/disks/resize2" func utilityGridGetConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*grid.RecordResourcesConsumption, error) {
const ComputeDeleteAPI = "/restmachine/cloudbroker/compute/delete" c := m.(*controller.ControllerCfg)
req := grid.GetResourceConsumptionRequest{}
if d.Id() != "" {
id, _ := strconv.ParseUint(d.Id(), 10, 64)
req.GridID = id
} else {
req.GridID = uint64(d.Get("grid_id").(int))
}
log.Debugf("utilityGridGetConsumptionCheckPresence: load specific grid")
gridGetConsumption, err := c.CloudBroker().Grid().GetResourceConsumption(ctx,req)
if err != nil {
return nil, err
}
return gridGetConsumption, nil
}

@ -0,0 +1,84 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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 grid
import (
"context"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityGridGetDiagnosisCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
c := m.(*controller.ControllerCfg)
req := grid.GetDiagnosisRequest{}
if d.Id() != "" {
id, _ := strconv.ParseUint(d.Id(), 10, 64)
req.GID = id
} else {
req.GID = uint64(d.Get("gid").(int))
}
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
gridGetDiagnosis, err := c.CloudBroker().Grid().GetDiagnosisGET(ctx, req)
if err != nil {
return "", err
}
return gridGetDiagnosis, nil
}
func utilityGridPostDiagnosisCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
c := m.(*controller.ControllerCfg)
req := grid.GetDiagnosisRequest{}
if d.Id() != "" {
id, _ := strconv.ParseUint(d.Id(), 10, 64)
req.GID = id
} else {
req.GID = uint64(d.Get("gid").(int))
}
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
gridPostDiagnosis, err := c.CloudBroker().Grid().GetDiagnosis(ctx, req)
if err != nil {
return "", err
}
return gridPostDiagnosis, nil
}

@ -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>
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 grid
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityGridGetStatusCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
c := m.(*controller.ControllerCfg)
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
gridGetStatus, err := c.CloudBroker().Grid().StatusGET(ctx)
if err != nil {
return false, err
}
return gridGetStatus, nil
}
func utilityGridPostStatusCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
c := m.(*controller.ControllerCfg)
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
gridGetStatus, err := c.CloudBroker().Grid().Status(ctx)
if err != nil {
return false, err
}
return gridGetStatus, nil
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save