From db8d13d40365300c09226e4e89454ceacd45512f Mon Sep 17 00:00:00 2001 From: Alexey Fetisov Date: Mon, 15 Jun 2026 13:37:04 +0300 Subject: [PATCH] 4.11.3 --- CHANGELOG.md | 34 +- Makefile | 2 +- docs/resources/cb_kvmvm.md | 3 +- docs/resources/kvmvm.md | 4 +- go.mod | 2 +- go.sum | 4 +- .../cloudapi/image/resource_image_virtual.go | 278 +++--- internal/service/cloudapi/k8s/resource_k8s.go | 14 +- .../service/cloudapi/k8s/resource_k8s_cp.go | 14 +- .../service/cloudapi/k8s/resource_k8s_wg.go | 14 +- .../cloudapi/kvmvm/resource_compute.go | 94 ++- .../service/cloudapi/kvmvm/utility_compute.go | 13 +- internal/service/cloudapi/lb/flattens.go | 600 ++++++------- .../cloudapi/lb/lb_resource_subresource.go | 238 +++--- internal/service/cloudapi/lb/lb_schema.go | 792 +++++++++--------- internal/service/cloudapi/locations/models.go | 72 +- internal/service/cloudapi/zone/flattens.go | 182 ++-- .../service/cloudapi/zone/utility_zone.go | 124 +-- .../cloudapi/zone/utility_zone_list.go | 170 ++-- .../service/cloudbroker/flipgroup/flattens.go | 28 + .../flipgroup/resource_flipgroup.go | 2 +- internal/service/cloudbroker/k8s/schema.go | 42 +- .../kvmvm/resource_check_input_values.go | 6 +- .../cloudbroker/kvmvm/resource_compute.go | 30 +- internal/service/cloudbroker/kvmvm/schema.go | 40 +- .../cloudbroker/kvmvm/utility_compute.go | 32 +- .../service/cloudbroker/trunk/flattens.go | 8 +- .../cloudbroker/vfpool/resource_vfpool.go | 23 +- .../cloudbroker/vfpool/utility_vfpool.go | 41 +- internal/service/cloudbroker/zone/flattens.go | 182 ++-- .../service/cloudbroker/zone/utility_zone.go | 318 +++---- .../cloudbroker/zone/utility_zone_list.go | 170 ++-- .../data_decort_sdn_access_group_list.go | 1 + .../access_group/utility_access_group_list.go | 1 + ...decort_sdn_default_security_policy_list.go | 1 + .../sdn/default_security_policy/schema.go | 1 + .../utility_default_security_policy_list.go | 1 + .../sdn/segments/utility_segment_list.go | 2 +- samples/cloudapi/kvmvm/resource_kvmvm/main.tf | 12 + .../cloudbroker/kvmvm/resource_kvmvm/main.tf | 8 +- 40 files changed, 1892 insertions(+), 1711 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2fd7c24..98f093a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,38 @@ -## Version 4.11.2 +## Version 4.11.3 ### Добавлено #### kvmvm | Идентификатор
задачи | Описание | | --- | --- | -| BATF-1270 | Опциональное поле `iotune` в блоке `disks` в resource `decort_kvmvm` в cloudapi/kvmvm и в resource `decort_cb_kvmvm` в cloudbroker/kvmvm | \ No newline at end of file +| BATF-1276 | Добавлено опциональное поле `create_blank` в resource `decort_kvmvm` в cloudapi/kvmvm и в resource `decort_cb_kvmvm` в cloudbroker/kvmvm | +| BATF-1276 | Опциональное поле `alt_boot_id` в resource `decort_kvmvm` в cloudapi/kvmvm | + +### Изменено +#### kvmvm +| Идентификатор
задачи | Описание | +| --- | --- | +| BATF-1276 | Тип поля `disk_type` с опционального на вычисляемый в resource `decort_kvmvm` в cloudapi/kvmvm и в resource `decort_cb_kvmvm` в cloudbroker/kvmvm | + +### Исправлено + +#### flipgroup +| Идентификатор
задачи | Описание | +| --- | --- | +| BATF-1283 | Установка поля `desc` с платформы в ресурсе `decort_cb_flipgroup` в cloudbroker/flipgroup | + +#### kvmvm +| Идентификатор
задачи | Описание | +| --- | --- | +| BATF-1276 | Ошибка при старте ВМ с указанием поля `alt_boot_id` в resource `decort_cb_kvmvm` в cloudbroker/kvmvm | + +#### trunk +| Идентификатор
задачи | Описание | +| --- | --- | +| BATF-1285 | Установка полей `account_ids`, `ovs_bridge`, `native_vlan_id`, `trunk_tags` с платформы в ресурсе `decort_cb_trunk ` в cloudbroker/trunk | + +#### vfpool +| Идентификатор
задачи | Описание | +| --- | --- | +| BATF-1289 | Разрешено создавать пул виртуальных функций с блоком `config` при значении поля `enable` равным `false` в resource `decort_cb_vfpool` в cloudbroker/vfpool | +| BATF-1289 | Разрешено обновлять поля `name`, `description`, `account_access` и `rg_access` без блока `config` в resource `decort_cb_vfpool` в cloudbroker/vfpool | diff --git a/Makefile b/Makefile index c87f6772..362ae4b4 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ ZIPDIR = ./zip BINARY=${NAME} WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH} MAINPATH = ./cmd/decort/ -VERSION=4.11.2 +VERSION=4.11.3 OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) FILES = ${BINARY}_${VERSION}_darwin_amd64\ diff --git a/docs/resources/cb_kvmvm.md b/docs/resources/cb_kvmvm.md index a9fba414..e8923667 100644 --- a/docs/resources/cb_kvmvm.md +++ b/docs/resources/cb_kvmvm.md @@ -38,6 +38,7 @@ description: |- - `chipset` (String) Type of the emulated system. - `cloud_init` (String) Optional cloud_init parameters. Applied when creating new compute instance only, ignored in all other cases. - `cpu_pin` (Boolean) Run VM on dedicated CPUs. To use this feature, the system must be pre-configured by allocating CPUs on the physical node. +- `create_blank` (Boolean) If True, the compute is created via kvmx86/createBlank endpoint (without OS image). The image_id field is not required in this case. - `custom_fields` (String) - `description` (String) Optional text description of this compute instance. - `detach_disks` (Boolean) @@ -186,7 +187,6 @@ Optional: - `blk_discard` (Boolean) - `cache` (String) Setting the disk caching mode - `desc` (String) Optional description -- `disk_type` (String) The type of disk in terms of its role in compute: 'B=Boot, D=Data' - `image_id` (Number) Specify image id for create disk from template - `iotune` (Block List, Max: 1) (see [below for nested schema](#nestedblock--disks--iotune)) - `node_ids` (Set of Number) @@ -202,6 +202,7 @@ Read-Only: - `delete_time` (Number) - `devicename` (String) - `disk_id` (Number) Disk ID +- `disk_type` (String) The type of disk in terms of its role in compute: 'B=Boot, D=Data' - `present_to` (Map of Number) - `shareable` (Boolean) - `size_max` (Number) diff --git a/docs/resources/kvmvm.md b/docs/resources/kvmvm.md index 27fc7bb4..d4aa6f72 100644 --- a/docs/resources/kvmvm.md +++ b/docs/resources/kvmvm.md @@ -27,6 +27,7 @@ description: |- - `affinity_label` (String) Set affinity label for compute - `affinity_rules` (Block List) (see [below for nested schema](#nestedblock--affinity_rules)) +- `alt_boot_id` (Number) ID of CD-ROM live image to boot - `anti_affinity_rules` (Block List) (see [below for nested schema](#nestedblock--anti_affinity_rules)) - `auto_start_w_node` (Boolean) Flag for start compute after node exits from MAINTENANCE state - `boot_disk_size` (Number) This compute instance boot disk size in GB. Make sure it is large enough to accomodate selected OS image. @@ -35,6 +36,7 @@ description: |- - `chipset` (String) Type of the emulated system. - `cloud_init` (String) Optional cloud_init parameters. Applied when creating new compute instance only, ignored in all other cases. - `cpu_pin` (Boolean) Run VM on dedicated CPUs. To use this feature, the system must be pre-configured by allocating CPUs on the physical node. +- `create_blank` (Boolean) If True, the compute is created via kvmx86/createBlank endpoint (without OS image). The image_id field is not required in this case. - `custom_fields` (String) - `description` (String) Optional text description of this compute instance. - `detach_disks` (Boolean) @@ -177,7 +179,6 @@ Required: Optional: - `desc` (String) Optional description -- `disk_type` (String) The type of disk in terms of its role in compute: 'B=Boot, D=Data' - `image_id` (Number) Specify image id for create disk from template - `iotune` (Block List, Max: 1) (see [below for nested schema](#nestedblock--disks--iotune)) - `permanently` (Boolean) Disk deletion status @@ -194,6 +195,7 @@ Read-Only: - `deleted_time` (Number) - `devicename` (String) - `disk_id` (Number) Disk ID +- `disk_type` (String) The type of disk in terms of its role in compute: 'B=Boot, D=Data' - `present_to` (Map of Number) - `shareable` (Boolean) - `size_max` (Number) diff --git a/go.mod b/go.mod index 3e3cf695..c28bd0a7 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1 github.com/sirupsen/logrus v1.9.0 golang.org/x/net v0.44.0 - repository.basistech.ru/BASIS/decort-golang-sdk v1.13.9 + repository.basistech.ru/BASIS/decort-golang-sdk v1.13.10 ) require ( diff --git a/go.sum b/go.sum index 0428eae1..986737de 100644 --- a/go.sum +++ b/go.sum @@ -318,5 +318,5 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -repository.basistech.ru/BASIS/decort-golang-sdk v1.13.9 h1:jrfwiJBuHbt3JlVwD6DWF3E/H9pyDOJOvb8F5sQ/mhM= -repository.basistech.ru/BASIS/decort-golang-sdk v1.13.9/go.mod h1:S/f7GxwWcE88eFpORV+I9xqEf8zDW5srQHpG2XQCLZM= +repository.basistech.ru/BASIS/decort-golang-sdk v1.13.10 h1:aRKyTH3/NSrpCLyLuTwCMtzOBoQ+hQ5EC4emQSnya5k= +repository.basistech.ru/BASIS/decort-golang-sdk v1.13.10/go.mod h1:S/f7GxwWcE88eFpORV+I9xqEf8zDW5srQHpG2XQCLZM= diff --git a/internal/service/cloudapi/image/resource_image_virtual.go b/internal/service/cloudapi/image/resource_image_virtual.go index c9291868..1aae5628 100644 --- a/internal/service/cloudapi/image/resource_image_virtual.go +++ b/internal/service/cloudapi/image/resource_image_virtual.go @@ -1,139 +1,139 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 image - -import ( - "context" - "strconv" - - "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/cloudapi/image" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" -) - -func resourceImageVirtualCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceImageVirtualCreate: called for image %s", d.Get("name").(string)) - - c := m.(*controller.ControllerCfg) - req := image.CreateVirtualRequest{ - Name: d.Get("name").(string), - TargetID: uint64(d.Get("link_to").(int)), - AccountID: uint64(d.Get("account_id").(int)), - } - - imageId, err := c.CloudAPI().Image().CreateVirtual(ctx, req) - if err != nil { - return diag.FromErr(err) - } - - d.SetId(strconv.FormatUint(imageId, 10)) - d.Set("image_id", imageId) - - _, err = utilityImageCheckPresence(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - - return resourceImageRead(ctx, d, m) -} - -func resourceImageVirtualUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceImageUpdate: called for %s, id: %s", d.Get("name").(string), d.Id()) - - if d.HasChange("name") { - err := resourceImageRename(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - } - - if d.HasChange("link_to") { - err := resourceImageVirtualLink(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - } - - return resourceImageRead(ctx, d, m) -} - -func resourceImageVirtualLink(ctx context.Context, d *schema.ResourceData, m interface{}) error { - log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id()) - c := m.(*controller.ControllerCfg) - req := image.LinkRequest{ - ImageID: uint64(d.Get("image_id").(int)), - TargetID: uint64(d.Get("link_to").(int)), - } - - _, err := c.CloudAPI().Image().Link(ctx, req) - if err != nil { - return err - } - - return nil -} - -func ResourceImageVirtual() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 2, - - CreateContext: resourceImageVirtualCreate, - ReadContext: resourceImageRead, - UpdateContext: resourceImageVirtualUpdate, - DeleteContext: resourceImageDelete, - - 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: resourceImageVirtualSchemaMake(dataSourceImageExtendSchemaMake()), - StateUpgraders: []schema.StateUpgrader{ - { - Type: resourceImageVirtualSchemaV1().CoreConfigSchema().ImpliedType(), - Upgrade: resourcePresentToUpgradeV1, - Version: 1, - }, - }, - } -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 image + +import ( + "context" + "strconv" + + "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/cloudapi/image" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func resourceImageVirtualCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceImageVirtualCreate: called for image %s", d.Get("name").(string)) + + c := m.(*controller.ControllerCfg) + req := image.CreateVirtualRequest{ + Name: d.Get("name").(string), + TargetID: uint64(d.Get("link_to").(int)), + AccountID: uint64(d.Get("account_id").(int)), + } + + imageId, err := c.CloudAPI().Image().CreateVirtual(ctx, req) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.FormatUint(imageId, 10)) + d.Set("image_id", imageId) + + _, err = utilityImageCheckPresence(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + + return resourceImageRead(ctx, d, m) +} + +func resourceImageVirtualUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceImageUpdate: called for %s, id: %s", d.Get("name").(string), d.Id()) + + if d.HasChange("name") { + err := resourceImageRename(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("link_to") { + err := resourceImageVirtualLink(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + } + + return resourceImageRead(ctx, d, m) +} + +func resourceImageVirtualLink(ctx context.Context, d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id()) + c := m.(*controller.ControllerCfg) + req := image.LinkRequest{ + ImageID: uint64(d.Get("image_id").(int)), + TargetID: uint64(d.Get("link_to").(int)), + } + + _, err := c.CloudAPI().Image().Link(ctx, req) + if err != nil { + return err + } + + return nil +} + +func ResourceImageVirtual() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 2, + + CreateContext: resourceImageVirtualCreate, + ReadContext: resourceImageRead, + UpdateContext: resourceImageVirtualUpdate, + DeleteContext: resourceImageDelete, + + 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: resourceImageVirtualSchemaMake(dataSourceImageExtendSchemaMake()), + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceImageVirtualSchemaV1().CoreConfigSchema().ImpliedType(), + Upgrade: resourcePresentToUpgradeV1, + Version: 1, + }, + }, + } +} diff --git a/internal/service/cloudapi/k8s/resource_k8s.go b/internal/service/cloudapi/k8s/resource_k8s.go index 457bfacc..3582643f 100644 --- a/internal/service/cloudapi/k8s/resource_k8s.go +++ b/internal/service/cloudapi/k8s/resource_k8s.go @@ -805,13 +805,13 @@ func resourceK8sSchemaMake() map[string]*schema.Schema { Description: "insert ssl certificate in x509 pem format", }, - "chipset": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), - Default: "Q35", - Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", - }, + "chipset": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), + Default: "Q35", + Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", + }, "desc": { Type: schema.TypeString, diff --git a/internal/service/cloudapi/k8s/resource_k8s_cp.go b/internal/service/cloudapi/k8s/resource_k8s_cp.go index d2779369..8489fc16 100644 --- a/internal/service/cloudapi/k8s/resource_k8s_cp.go +++ b/internal/service/cloudapi/k8s/resource_k8s_cp.go @@ -715,13 +715,13 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema { ), Description: "Node RAM in MB.", }, - "chipset": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), - Default: "Q35", - Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", - }, + "chipset": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), + Default: "Q35", + Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", + }, "disk": { Type: schema.TypeInt, Optional: true, diff --git a/internal/service/cloudapi/k8s/resource_k8s_wg.go b/internal/service/cloudapi/k8s/resource_k8s_wg.go index 0cde9f4b..e6d6c43d 100644 --- a/internal/service/cloudapi/k8s/resource_k8s_wg.go +++ b/internal/service/cloudapi/k8s/resource_k8s_wg.go @@ -290,13 +290,13 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema { Description: "Number of worker nodes to create.", }, - "chipset": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), - Default: "Q35", - Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", - }, + "chipset": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), + Default: "Q35", + Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", + }, "cpu": { Type: schema.TypeInt, diff --git a/internal/service/cloudapi/kvmvm/resource_compute.go b/internal/service/cloudapi/kvmvm/resource_compute.go index ad432c4d..4c14e632 100644 --- a/internal/service/cloudapi/kvmvm/resource_compute.go +++ b/internal/service/cloudapi/kvmvm/resource_compute.go @@ -71,13 +71,15 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf return diag.Errorf("resourceComputeCreate: can't create Compute because rgID %d is not allowed or does not exist", d.Get("rg_id").(int)) } - hasImage, err := existImageId(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } + if !d.Get("create_blank").(bool) { + hasImage, err := existImageId(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } - if !hasImage { - return diag.Errorf("resourceComputeCreate: can't create Compute because imageID %d is not allowed or does not exist", d.Get("image_id").(int)) + if !hasImage { + return diag.Errorf("resourceComputeCreate: can't create Compute because imageID %d is not allowed or does not exist", d.Get("image_id").(int)) + } } if zoneID, ok := d.GetOk("zone_id"); ok { @@ -294,7 +296,32 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf } log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86") - apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86) + var apiResp uint64 + if d.Get("create_blank").(bool) { + log.Debugf("resourceComputeCreate: using createBlank endpoint") + createBlankReq := kvmx86.CreateBlankRequest{ + RGID: createReqX86.RGID, + Name: createReqX86.Name, + CPU: createReqX86.CPU, + RAM: createReqX86.RAM, + StoragePolicyID: createReqX86.StoragePolicyID, + WithoutBootDisk: createReqX86.WithoutBootDisk, + BootDisk: createReqX86.BootDisk, + SEPID: createReqX86.SepID, + Pool: createReqX86.Pool, + DataDisks: createReqX86.DataDisks, + Interfaces: createReqX86.Interfaces, + Description: createReqX86.Description, + Chipset: createReqX86.Chipset, + PreferredCPU: createReqX86.PreferredCPU, + ZoneID: createReqX86.ZoneID, + OSVersion: createReqX86.OSVersion, + } + apiResp, err = c.CloudAPI().KVMX86().CreateBlank(ctx, createBlankReq) + } else { + apiResp, err = c.CloudAPI().KVMX86().Create(ctx, createReqX86) + } + if err != nil { return diag.FromErr(err) } @@ -458,6 +485,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf if start, ok := d.GetOk("started"); ok { if start.(bool) { req := compute.StartRequest{ComputeID: computeId} + if altBootID, ok := d.Get("alt_boot_id").(int); ok { + req.AltBootID = uint64(altBootID) + } log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId) if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil { warnings.Add(err) @@ -769,13 +799,19 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf return diag.Errorf("resourceComputeUpdate: can't update Compute because rgID %d not allowed or does not exist", d.Get("rg_id").(int)) } - hasImage, err := existImageId(ctx, d, m) - if err != nil { - return diag.FromErr(err) + if !d.Get("create_blank").(bool) { + hasImage, err := existImageId(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + + if !hasImage { + return diag.Errorf("resourceComputeUpdate: can't update Compute because imageID %d not allowed or does not exist", d.Get("image_id").(int)) + } } - if !hasImage { - return diag.Errorf("resourceComputeUpdate: can't update Compute because imageID %d not allowed or does not exist", d.Get("image_id").(int)) + if err != nil { + return diag.FromErr(err) } if d.HasChange("zone_id") { @@ -863,6 +899,9 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf if start, ok := d.GetOk("started"); ok { if start.(bool) { req := compute.StartRequest{ComputeID: computeRec.ID} + if altBootID, ok := d.Get("alt_boot_id").(int); ok { + req.AltBootID = uint64(altBootID) + } if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil { return diag.FromErr(err) @@ -1105,7 +1144,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf // If used to be STARTED, we need to start it after update if isStopRequired { - if _, err := c.CloudAPI().Compute().Start(ctx, compute.StartRequest{ComputeID: computeRec.ID}); err != nil { + req := compute.StartRequest{ComputeID: computeRec.ID} + if altBootID, ok := d.Get("alt_boot_id").(int); ok { + req.AltBootID = uint64(altBootID) + } + if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil { return diag.FromErr(err) } } @@ -1214,9 +1257,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf if diskConv["sep_id"].(int) != 0 { req.SepID = uint64(diskConv["sep_id"].(int)) } - if diskConv["disk_type"].(string) != "" { - req.DiskType = diskConv["disk_type"].(string) - } if diskConv["pool"].(string) != "" { req.Pool = diskConv["pool"].(string) } @@ -1847,6 +1887,9 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf req := compute.StartRequest{ ComputeID: computeRec.ID, } + if altBootID, ok := d.Get("alt_boot_id").(int); ok { + req.AltBootID = uint64(altBootID) + } if !isStopRequired { if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil { return diag.FromErr(err) @@ -2043,11 +2086,9 @@ func disksSubresourceSchemaMake() map[string]*schema.Schema { Description: "Storage endpoint provider ID; by default the same with boot disk", }, "disk_type": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"B", "D"}, false), - Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'", + Type: schema.TypeString, + Computed: true, + Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'", }, "pool": { Type: schema.TypeString, @@ -2353,6 +2394,12 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { Default: false, Description: "If True, the imageId, bootDisk, sepId, pool parameters are ignored and the compute is created without a boot disk in the stopped state.", }, + "create_blank": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "If True, the compute is created via kvmx86/createBlank endpoint (without OS image). The image_id field is not required in this case.", + }, "boot_disk_size": { Type: schema.TypeInt, Optional: true, @@ -2607,6 +2654,11 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { Default: false, Description: "Flag for resize compute", }, + "alt_boot_id": { + Type: schema.TypeInt, + Optional: true, + Description: "ID of CD-ROM live image to boot", + }, "started": { Type: schema.TypeBool, Optional: true, diff --git a/internal/service/cloudapi/kvmvm/utility_compute.go b/internal/service/cloudapi/kvmvm/utility_compute.go index 6440f28d..d5756d0a 100644 --- a/internal/service/cloudapi/kvmvm/utility_compute.go +++ b/internal/service/cloudapi/kvmvm/utility_compute.go @@ -299,7 +299,13 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData if needStart { computeId, _ := strconv.ParseUint(d.Id(), 10, 64) - if numErr, err := utilityComputeStart(ctx, computeId, m); err != nil { + var altBootID uint64 + if altBootIDRaw, ok := d.Get("alt_boot_id").(int); ok { + altBootID = uint64(altBootIDRaw) + } else { + altBootID = 0 + } + if numErr, err := utilityComputeStart(ctx, computeId, altBootID, m); err != nil { apiErrCount += numErr lastSavedError = err } @@ -462,9 +468,12 @@ func utilityComputeStop(ctx context.Context, computeID uint64, m interface{}) er return nil } -func utilityComputeStart(ctx context.Context, computeID uint64, m interface{}) (int, error) { +func utilityComputeStart(ctx context.Context, computeID uint64, altBootID uint64, m interface{}) (int, error) { c := m.(*controller.ControllerCfg) startReq := compute.StartRequest{ComputeID: computeID} + if altBootID > 0 { + startReq.AltBootID = altBootID + } log.Debugf("utilityComputeNetworksConfigure: starting compute %d", computeID) _, err := c.CloudAPI().Compute().Start(ctx, startReq) diff --git a/internal/service/cloudapi/lb/flattens.go b/internal/service/cloudapi/lb/flattens.go index db182770..fc064dd5 100644 --- a/internal/service/cloudapi/lb/flattens.go +++ b/internal/service/cloudapi/lb/flattens.go @@ -1,300 +1,300 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud -Orchestration Technology) with Terraform by Hashicorp. - -Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort - -Please see README.md to learn where to place source code so that it -builds seamlessly. - -Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki -*/ - -package lb - -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb" -) - -func flattenLBFrontendBind(d *schema.ResourceData, b *lb.ItemBinding, lbId int64, frontendName string) { - d.Set("lb_id", lbId) - d.Set("frontend_name", frontendName) - d.Set("name", b.Name) - d.Set("address", b.Address) - d.Set("guid", b.GUID) - d.Set("port", b.Port) -} - -func flattenLBFrontend(d *schema.ResourceData, f *lb.ItemFrontend, lbId int64) { - d.Set("lb_id", lbId) - d.Set("backend_name", f.Backend) - d.Set("name", f.Name) - d.Set("guid", f.GUID) - d.Set("bindings", flattendBindings(f.Bindings)) -} - -func flattenResourceLBBackendServer(d *schema.ResourceData, s *lb.ItemServer, lbId int64, backendName string) { - d.Set("lb_id", lbId) - d.Set("backend_name", backendName) - d.Set("name", s.Name) - d.Set("port", s.Port) - d.Set("address", s.Address) - d.Set("check", s.Check) - d.Set("guid", s.GUID) - d.Set("downinter", s.ServerSettings.DownInter) - d.Set("fall", s.ServerSettings.Fall) - d.Set("inter", s.ServerSettings.Inter) - d.Set("maxconn", s.ServerSettings.MaxConn) - d.Set("maxqueue", s.ServerSettings.MaxQueue) - d.Set("rise", s.ServerSettings.Rise) - d.Set("slowstart", s.ServerSettings.SlowStart) - d.Set("weight", s.ServerSettings.Weight) - -} - -func flattenResourceLBBackend(d *schema.ResourceData, b *lb.ItemBackend, lbId int64) { - d.Set("lb_id", lbId) - d.Set("name", b.Name) - d.Set("algorithm", b.Algorithm) - d.Set("guid", b.GUID) - d.Set("downinter", b.ServerDefaultSettings.DownInter) - d.Set("fall", b.ServerDefaultSettings.Fall) - d.Set("inter", b.ServerDefaultSettings.Inter) - d.Set("maxconn", b.ServerDefaultSettings.MaxConn) - d.Set("maxqueue", b.ServerDefaultSettings.MaxQueue) - d.Set("rise", b.ServerDefaultSettings.Rise) - d.Set("slowstart", b.ServerDefaultSettings.SlowStart) - d.Set("weight", b.ServerDefaultSettings.Weight) - d.Set("servers", flattenServers(b.Servers)) -} - -func flattenResourceLB(d *schema.ResourceData, lb *lb.RecordLB) { - d.Set("ha_mode", lb.HAMode) - d.Set("backend_haip", lb.BackendHAIP) - d.Set("backends", flattenLBBackends(lb.Backends)) - d.Set("created_by", lb.CreatedBy) - d.Set("created_time", lb.CreatedTime) - d.Set("deleted_by", lb.DeletedBy) - d.Set("deleted_time", lb.DeletedTime) - d.Set("desc", lb.Description) - d.Set("dp_api_user", lb.DPAPIUser) - d.Set("extnet_id", lb.ExtNetID) - d.Set("frontend_haip", lb.FrontendHAIP) - d.Set("frontends", flattenFrontends(lb.Frontends)) - d.Set("gid", lb.GID) - d.Set("guid", lb.GUID) - d.Set("manager_id", lb.ManagerId) - d.Set("manager_type", lb.ManagerType) - d.Set("lb_id", lb.ID) - d.Set("image_id", lb.ImageID) - d.Set("milestones", lb.Milestones) - d.Set("name", lb.Name) - d.Set("part_k8s", lb.PartK8s) - d.Set("primary_node", flattenNode(lb.PrimaryNode)) - d.Set("rg_id", lb.RGID) - d.Set("rg_name", lb.RGName) - d.Set("secondary_node", flattenNode(lb.SecondaryNode)) - d.Set("status", lb.Status) - d.Set("tech_status", lb.TechStatus) - d.Set("updated_by", lb.UpdatedBy) - d.Set("updated_time", lb.UpdatedTime) - d.Set("user_managed", lb.UserManaged) - d.Set("vins_id", lb.VINSID) - d.Set("zone_id", lb.ZoneID) - -} - -func flattenLB(d *schema.ResourceData, lb *lb.RecordLB) { - d.Set("account_id", lb.AccountID) - d.Set("ha_mode", lb.HAMode) - d.Set("backend_haip", lb.BackendHAIP) - d.Set("backends", flattenLBBackends(lb.Backends)) - d.Set("created_by", lb.CreatedBy) - d.Set("created_time", lb.CreatedTime) - d.Set("deleted_by", lb.DeletedBy) - d.Set("deleted_time", lb.DeletedTime) - d.Set("desc", lb.Description) - d.Set("dp_api_user", lb.DPAPIUser) - d.Set("extnet_id", lb.ExtNetID) - d.Set("frontend_haip", lb.FrontendHAIP) - d.Set("frontends", flattenFrontends(lb.Frontends)) - d.Set("gid", lb.GID) - d.Set("guid", lb.GUID) - d.Set("manager_id", lb.ManagerId) - d.Set("manager_type", lb.ManagerType) - d.Set("image_id", lb.ImageID) - d.Set("milestones", lb.Milestones) - d.Set("name", lb.Name) - d.Set("part_k8s", lb.PartK8s) - d.Set("primary_node", flattenNode(lb.PrimaryNode)) - d.Set("rg_id", lb.RGID) - d.Set("rg_name", lb.RGName) - d.Set("secondary_node", flattenNode(lb.SecondaryNode)) - d.Set("status", lb.Status) - d.Set("tech_status", lb.TechStatus) - d.Set("updated_by", lb.UpdatedBy) - d.Set("updated_time", lb.UpdatedTime) - d.Set("user_managed", lb.UserManaged) - d.Set("vins_id", lb.VINSID) - d.Set("zone_id", lb.ZoneID) -} - -func flattenNode(node lb.RecordNode) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - n := map[string]interface{}{ - "backend_ip": node.BackendIP, - "compute_id": node.ComputeID, - "frontend_ip": node.FrontendIP, - "guid": node.GUID, - "mgmt_ip": node.MGMTIP, - "network_id": node.NetworkID, - } - - temp = append(temp, n) - - return temp -} - -func flattendBindings(bs []lb.ItemBinding) []map[string]interface{} { - temp := make([]map[string]interface{}, 0, len(bs)) - for _, b := range bs { - t := map[string]interface{}{ - "address": b.Address, - "guid": b.GUID, - "name": b.Name, - "port": b.Port, - } - temp = append(temp, t) - } - return temp -} - -func flattenFrontends(fs []lb.ItemFrontend) []map[string]interface{} { - temp := make([]map[string]interface{}, 0, len(fs)) - for _, f := range fs { - t := map[string]interface{}{ - "backend": f.Backend, - "bindings": flattendBindings(f.Bindings), - "guid": f.GUID, - "name": f.Name, - } - temp = append(temp, t) - } - - return temp -} - -func flattenServers(servers []lb.ItemServer) []map[string]interface{} { - temp := make([]map[string]interface{}, 0, len(servers)) - for _, server := range servers { - t := map[string]interface{}{ - "address": server.Address, - "check": server.Check, - "guid": server.GUID, - "name": server.Name, - "port": server.Port, - "server_settings": flattenServerSettings(server.ServerSettings), - } - - temp = append(temp, t) - } - return temp -} - -func flattenServerSettings(defSet lb.RecordServerSettings) []map[string]interface{} { - temp := map[string]interface{}{ - "downinter": defSet.DownInter, - "fall": defSet.Fall, - "guid": defSet.GUID, - "inter": defSet.Inter, - "maxconn": defSet.MaxConn, - "maxqueue": defSet.MaxQueue, - "rise": defSet.Rise, - "slowstart": defSet.SlowStart, - "weight": defSet.Weight, - } - - res := make([]map[string]interface{}, 0) - res = append(res, temp) - return res -} - -func flattenLBBackends(backends []lb.ItemBackend) []map[string]interface{} { - temp := make([]map[string]interface{}, 0, len(backends)) - for _, item := range backends { - t := map[string]interface{}{ - "algorithm": item.Algorithm, - "guid": item.GUID, - "name": item.Name, - "server_default_settings": flattenServerSettings(item.ServerDefaultSettings), - "servers": flattenServers(item.Servers), - } - - temp = append(temp, t) - } - return temp -} - -func flattenLBList(lbl *lb.ListLB) []map[string]interface{} { - res := make([]map[string]interface{}, 0, len(lbl.Data)) - for _, lb := range lbl.Data { - temp := map[string]interface{}{ - "ha_mode": lb.HAMode, - "backend_haip": lb.BackendHAIP, - "backends": flattenLBBackends(lb.Backends), - "created_by": lb.CreatedBy, - "created_time": lb.CreatedTime, - "deleted_by": lb.DeletedBy, - "deleted_time": lb.DeletedTime, - "desc": lb.Description, - "dp_api_user": lb.DPAPIUser, - "dp_api_password": lb.DPAPIPassword, - "extnet_id": lb.ExtNetID, - "frontend_haip": lb.FrontendHAIP, - "frontends": flattenFrontends(lb.Frontends), - "gid": lb.GID, - "guid": lb.GUID, - "manager_id": lb.ManagerId, - "manager_type": lb.ManagerType, - "image_id": lb.ImageID, - "milestones": lb.Milestones, - "name": lb.Name, - "part_k8s": lb.PartK8s, - "primary_node": flattenNode(lb.PrimaryNode), - "rg_id": lb.RGID, - "rg_name": lb.RGName, - "secondary_node": flattenNode(lb.SecondaryNode), - "status": lb.Status, - "tech_status": lb.TechStatus, - "updated_by": lb.UpdatedBy, - "updated_time": lb.UpdatedTime, - "user_managed": lb.UserManaged, - "vins_id": lb.VINSID, - "lb_id": lb.ID, - "zone_id": lb.ZoneID, - } - res = append(res, temp) - } - return res -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package lb + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb" +) + +func flattenLBFrontendBind(d *schema.ResourceData, b *lb.ItemBinding, lbId int64, frontendName string) { + d.Set("lb_id", lbId) + d.Set("frontend_name", frontendName) + d.Set("name", b.Name) + d.Set("address", b.Address) + d.Set("guid", b.GUID) + d.Set("port", b.Port) +} + +func flattenLBFrontend(d *schema.ResourceData, f *lb.ItemFrontend, lbId int64) { + d.Set("lb_id", lbId) + d.Set("backend_name", f.Backend) + d.Set("name", f.Name) + d.Set("guid", f.GUID) + d.Set("bindings", flattendBindings(f.Bindings)) +} + +func flattenResourceLBBackendServer(d *schema.ResourceData, s *lb.ItemServer, lbId int64, backendName string) { + d.Set("lb_id", lbId) + d.Set("backend_name", backendName) + d.Set("name", s.Name) + d.Set("port", s.Port) + d.Set("address", s.Address) + d.Set("check", s.Check) + d.Set("guid", s.GUID) + d.Set("downinter", s.ServerSettings.DownInter) + d.Set("fall", s.ServerSettings.Fall) + d.Set("inter", s.ServerSettings.Inter) + d.Set("maxconn", s.ServerSettings.MaxConn) + d.Set("maxqueue", s.ServerSettings.MaxQueue) + d.Set("rise", s.ServerSettings.Rise) + d.Set("slowstart", s.ServerSettings.SlowStart) + d.Set("weight", s.ServerSettings.Weight) + +} + +func flattenResourceLBBackend(d *schema.ResourceData, b *lb.ItemBackend, lbId int64) { + d.Set("lb_id", lbId) + d.Set("name", b.Name) + d.Set("algorithm", b.Algorithm) + d.Set("guid", b.GUID) + d.Set("downinter", b.ServerDefaultSettings.DownInter) + d.Set("fall", b.ServerDefaultSettings.Fall) + d.Set("inter", b.ServerDefaultSettings.Inter) + d.Set("maxconn", b.ServerDefaultSettings.MaxConn) + d.Set("maxqueue", b.ServerDefaultSettings.MaxQueue) + d.Set("rise", b.ServerDefaultSettings.Rise) + d.Set("slowstart", b.ServerDefaultSettings.SlowStart) + d.Set("weight", b.ServerDefaultSettings.Weight) + d.Set("servers", flattenServers(b.Servers)) +} + +func flattenResourceLB(d *schema.ResourceData, lb *lb.RecordLB) { + d.Set("ha_mode", lb.HAMode) + d.Set("backend_haip", lb.BackendHAIP) + d.Set("backends", flattenLBBackends(lb.Backends)) + d.Set("created_by", lb.CreatedBy) + d.Set("created_time", lb.CreatedTime) + d.Set("deleted_by", lb.DeletedBy) + d.Set("deleted_time", lb.DeletedTime) + d.Set("desc", lb.Description) + d.Set("dp_api_user", lb.DPAPIUser) + d.Set("extnet_id", lb.ExtNetID) + d.Set("frontend_haip", lb.FrontendHAIP) + d.Set("frontends", flattenFrontends(lb.Frontends)) + d.Set("gid", lb.GID) + d.Set("guid", lb.GUID) + d.Set("manager_id", lb.ManagerId) + d.Set("manager_type", lb.ManagerType) + d.Set("lb_id", lb.ID) + d.Set("image_id", lb.ImageID) + d.Set("milestones", lb.Milestones) + d.Set("name", lb.Name) + d.Set("part_k8s", lb.PartK8s) + d.Set("primary_node", flattenNode(lb.PrimaryNode)) + d.Set("rg_id", lb.RGID) + d.Set("rg_name", lb.RGName) + d.Set("secondary_node", flattenNode(lb.SecondaryNode)) + d.Set("status", lb.Status) + d.Set("tech_status", lb.TechStatus) + d.Set("updated_by", lb.UpdatedBy) + d.Set("updated_time", lb.UpdatedTime) + d.Set("user_managed", lb.UserManaged) + d.Set("vins_id", lb.VINSID) + d.Set("zone_id", lb.ZoneID) + +} + +func flattenLB(d *schema.ResourceData, lb *lb.RecordLB) { + d.Set("account_id", lb.AccountID) + d.Set("ha_mode", lb.HAMode) + d.Set("backend_haip", lb.BackendHAIP) + d.Set("backends", flattenLBBackends(lb.Backends)) + d.Set("created_by", lb.CreatedBy) + d.Set("created_time", lb.CreatedTime) + d.Set("deleted_by", lb.DeletedBy) + d.Set("deleted_time", lb.DeletedTime) + d.Set("desc", lb.Description) + d.Set("dp_api_user", lb.DPAPIUser) + d.Set("extnet_id", lb.ExtNetID) + d.Set("frontend_haip", lb.FrontendHAIP) + d.Set("frontends", flattenFrontends(lb.Frontends)) + d.Set("gid", lb.GID) + d.Set("guid", lb.GUID) + d.Set("manager_id", lb.ManagerId) + d.Set("manager_type", lb.ManagerType) + d.Set("image_id", lb.ImageID) + d.Set("milestones", lb.Milestones) + d.Set("name", lb.Name) + d.Set("part_k8s", lb.PartK8s) + d.Set("primary_node", flattenNode(lb.PrimaryNode)) + d.Set("rg_id", lb.RGID) + d.Set("rg_name", lb.RGName) + d.Set("secondary_node", flattenNode(lb.SecondaryNode)) + d.Set("status", lb.Status) + d.Set("tech_status", lb.TechStatus) + d.Set("updated_by", lb.UpdatedBy) + d.Set("updated_time", lb.UpdatedTime) + d.Set("user_managed", lb.UserManaged) + d.Set("vins_id", lb.VINSID) + d.Set("zone_id", lb.ZoneID) +} + +func flattenNode(node lb.RecordNode) []map[string]interface{} { + temp := make([]map[string]interface{}, 0) + n := map[string]interface{}{ + "backend_ip": node.BackendIP, + "compute_id": node.ComputeID, + "frontend_ip": node.FrontendIP, + "guid": node.GUID, + "mgmt_ip": node.MGMTIP, + "network_id": node.NetworkID, + } + + temp = append(temp, n) + + return temp +} + +func flattendBindings(bs []lb.ItemBinding) []map[string]interface{} { + temp := make([]map[string]interface{}, 0, len(bs)) + for _, b := range bs { + t := map[string]interface{}{ + "address": b.Address, + "guid": b.GUID, + "name": b.Name, + "port": b.Port, + } + temp = append(temp, t) + } + return temp +} + +func flattenFrontends(fs []lb.ItemFrontend) []map[string]interface{} { + temp := make([]map[string]interface{}, 0, len(fs)) + for _, f := range fs { + t := map[string]interface{}{ + "backend": f.Backend, + "bindings": flattendBindings(f.Bindings), + "guid": f.GUID, + "name": f.Name, + } + temp = append(temp, t) + } + + return temp +} + +func flattenServers(servers []lb.ItemServer) []map[string]interface{} { + temp := make([]map[string]interface{}, 0, len(servers)) + for _, server := range servers { + t := map[string]interface{}{ + "address": server.Address, + "check": server.Check, + "guid": server.GUID, + "name": server.Name, + "port": server.Port, + "server_settings": flattenServerSettings(server.ServerSettings), + } + + temp = append(temp, t) + } + return temp +} + +func flattenServerSettings(defSet lb.RecordServerSettings) []map[string]interface{} { + temp := map[string]interface{}{ + "downinter": defSet.DownInter, + "fall": defSet.Fall, + "guid": defSet.GUID, + "inter": defSet.Inter, + "maxconn": defSet.MaxConn, + "maxqueue": defSet.MaxQueue, + "rise": defSet.Rise, + "slowstart": defSet.SlowStart, + "weight": defSet.Weight, + } + + res := make([]map[string]interface{}, 0) + res = append(res, temp) + return res +} + +func flattenLBBackends(backends []lb.ItemBackend) []map[string]interface{} { + temp := make([]map[string]interface{}, 0, len(backends)) + for _, item := range backends { + t := map[string]interface{}{ + "algorithm": item.Algorithm, + "guid": item.GUID, + "name": item.Name, + "server_default_settings": flattenServerSettings(item.ServerDefaultSettings), + "servers": flattenServers(item.Servers), + } + + temp = append(temp, t) + } + return temp +} + +func flattenLBList(lbl *lb.ListLB) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(lbl.Data)) + for _, lb := range lbl.Data { + temp := map[string]interface{}{ + "ha_mode": lb.HAMode, + "backend_haip": lb.BackendHAIP, + "backends": flattenLBBackends(lb.Backends), + "created_by": lb.CreatedBy, + "created_time": lb.CreatedTime, + "deleted_by": lb.DeletedBy, + "deleted_time": lb.DeletedTime, + "desc": lb.Description, + "dp_api_user": lb.DPAPIUser, + "dp_api_password": lb.DPAPIPassword, + "extnet_id": lb.ExtNetID, + "frontend_haip": lb.FrontendHAIP, + "frontends": flattenFrontends(lb.Frontends), + "gid": lb.GID, + "guid": lb.GUID, + "manager_id": lb.ManagerId, + "manager_type": lb.ManagerType, + "image_id": lb.ImageID, + "milestones": lb.Milestones, + "name": lb.Name, + "part_k8s": lb.PartK8s, + "primary_node": flattenNode(lb.PrimaryNode), + "rg_id": lb.RGID, + "rg_name": lb.RGName, + "secondary_node": flattenNode(lb.SecondaryNode), + "status": lb.Status, + "tech_status": lb.TechStatus, + "updated_by": lb.UpdatedBy, + "updated_time": lb.UpdatedTime, + "user_managed": lb.UserManaged, + "vins_id": lb.VINSID, + "lb_id": lb.ID, + "zone_id": lb.ZoneID, + } + res = append(res, temp) + } + return res +} diff --git a/internal/service/cloudapi/lb/lb_resource_subresource.go b/internal/service/cloudapi/lb/lb_resource_subresource.go index 1d579cbf..ae3d42dc 100644 --- a/internal/service/cloudapi/lb/lb_resource_subresource.go +++ b/internal/service/cloudapi/lb/lb_resource_subresource.go @@ -1,119 +1,119 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud -Orchestration Technology) with Terraform by Hashicorp. - -Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort - -Please see README.md to learn where to place source code so that it -builds seamlessly. - -Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki -*/ - -package lb - -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - -func lbResourceSchemaMake() map[string]*schema.Schema { - sch := createLBSchema() - sch["rg_id"] = &schema.Schema{ - Type: schema.TypeInt, - Required: true, - } - sch["name"] = &schema.Schema{ - Type: schema.TypeString, - Required: true, - } - sch["zone_id"] = &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Computed: true, - } - sch["extnet_id"] = &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - } - - sch["vins_id"] = &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - } - sch["start"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - Default: true, - } - sch["desc"] = &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Computed: true, - } - - sch["enable"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - } - - sch["restart"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - } - - sch["restore"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - } - - sch["safe"] = &schema.Schema{ - Type: schema.TypeBool, - Default: true, - Optional: true, - } - - sch["config_reset"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - } - ///4.4.0 - sch["ha_mode"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - } - sch["sysctl_params"] = &schema.Schema{ - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeMap, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - } - - /// - sch["permanently"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - } - return sch -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package lb + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func lbResourceSchemaMake() map[string]*schema.Schema { + sch := createLBSchema() + sch["rg_id"] = &schema.Schema{ + Type: schema.TypeInt, + Required: true, + } + sch["name"] = &schema.Schema{ + Type: schema.TypeString, + Required: true, + } + sch["zone_id"] = &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + } + sch["extnet_id"] = &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + } + + sch["vins_id"] = &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + } + sch["start"] = &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + } + sch["desc"] = &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + } + + sch["enable"] = &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + } + + sch["restart"] = &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + } + + sch["restore"] = &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + } + + sch["safe"] = &schema.Schema{ + Type: schema.TypeBool, + Default: true, + Optional: true, + } + + sch["config_reset"] = &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + } + ///4.4.0 + sch["ha_mode"] = &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + } + sch["sysctl_params"] = &schema.Schema{ + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeMap, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + } + + /// + sch["permanently"] = &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + } + return sch +} diff --git a/internal/service/cloudapi/lb/lb_schema.go b/internal/service/cloudapi/lb/lb_schema.go index 962202b7..841c5f72 100644 --- a/internal/service/cloudapi/lb/lb_schema.go +++ b/internal/service/cloudapi/lb/lb_schema.go @@ -1,396 +1,396 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud -Orchestration Technology) with Terraform by Hashicorp. - -Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort - -Please see README.md to learn where to place source code so that it -builds seamlessly. - -Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki -*/ - -package lb - -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - -func createLBSchema() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeInt, - Computed: true, - }, - "ha_mode": { - Type: schema.TypeBool, - Computed: true, - }, - "backend_haip": { - Type: schema.TypeString, - Computed: true, - }, - "backends": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "algorithm": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "server_default_settings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "downinter": { - Type: schema.TypeInt, - Computed: true, - }, - "fall": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "inter": { - Type: schema.TypeInt, - Computed: true, - }, - "maxconn": { - Type: schema.TypeInt, - Computed: true, - }, - "maxqueue": { - Type: schema.TypeInt, - Computed: true, - }, - "rise": { - Type: schema.TypeInt, - Computed: true, - }, - "slowstart": { - Type: schema.TypeInt, - Computed: true, - }, - "weight": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "servers": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - }, - "check": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - "server_settings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "downinter": { - Type: schema.TypeInt, - Computed: true, - }, - "fall": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "inter": { - Type: schema.TypeInt, - Computed: true, - }, - "maxconn": { - Type: schema.TypeInt, - Computed: true, - }, - "maxqueue": { - Type: schema.TypeInt, - Computed: true, - }, - "rise": { - Type: schema.TypeInt, - Computed: true, - }, - "slowstart": { - Type: schema.TypeInt, - Computed: true, - }, - "weight": { - 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, - }, - "desc": { - Type: schema.TypeString, - Computed: true, - }, - "dp_api_user": { - Type: schema.TypeString, - Computed: true, - }, - "extnet_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontend_haip": { - Type: schema.TypeString, - Computed: true, - }, - "frontends": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend": { - Type: schema.TypeString, - Computed: true, - }, - "bindings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "gid": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeInt, - Computed: true, - }, - "lb_id": { - Type: schema.TypeInt, - Computed: true, - }, - "manager_id": { - Type: schema.TypeInt, - Computed: true, - }, - "manager_type": { - Type: schema.TypeString, - Computed: true, - }, - "image_id": { - Type: schema.TypeInt, - Computed: true, - }, - "milestones": { - Type: schema.TypeInt, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "part_k8s": { - Type: schema.TypeBool, - Computed: true, - }, - "primary_node": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "compute_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_ip": { - Type: schema.TypeString, - Computed: true, - }, - "network_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "rg_id": { - Type: schema.TypeInt, - Computed: true, - }, - "rg_name": { - Type: schema.TypeString, - Computed: true, - }, - "secondary_node": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "compute_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_ip": { - Type: schema.TypeString, - Computed: true, - }, - "network_id": { - Type: schema.TypeInt, - 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, - }, - "user_managed": { - Type: schema.TypeBool, - Computed: true, - }, - "vins_id": { - Type: schema.TypeInt, - Computed: true, - }, - } -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package lb + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func createLBSchema() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ha_mode": { + Type: schema.TypeBool, + Computed: true, + }, + "backend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "backends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "algorithm": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "server_default_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "servers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "check": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + "server_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + 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, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_user": { + Type: schema.TypeString, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "frontends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend": { + Type: schema.TypeString, + Computed: true, + }, + "bindings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "lb_id": { + Type: schema.TypeInt, + Computed: true, + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "part_k8s": { + Type: schema.TypeBool, + Computed: true, + }, + "primary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "secondary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + 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, + }, + "user_managed": { + Type: schema.TypeBool, + Computed: true, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + } +} diff --git a/internal/service/cloudapi/locations/models.go b/internal/service/cloudapi/locations/models.go index 543613cc..7c4d76ad 100644 --- a/internal/service/cloudapi/locations/models.go +++ b/internal/service/cloudapi/locations/models.go @@ -1,36 +1,36 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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. -*/ - -package locations - -type Location struct { - GridID int `json:"gid"` - Id int `json:"id"` - Guid int `json:"guid"` - LocationCode string `json:"locationCode"` - Name string `json:"name"` - NetworkModes []string `json:"network_modes"` - SDNSupport bool `json:"sdn_support"` - Flag string `json:"flag"` - Meta []interface{} `json:"_meta"` - CKey string `json:"_ckey"` -} - -type LocationsList []Location +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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. +*/ + +package locations + +type Location struct { + GridID int `json:"gid"` + Id int `json:"id"` + Guid int `json:"guid"` + LocationCode string `json:"locationCode"` + Name string `json:"name"` + NetworkModes []string `json:"network_modes"` + SDNSupport bool `json:"sdn_support"` + Flag string `json:"flag"` + Meta []interface{} `json:"_meta"` + CKey string `json:"_ckey"` +} + +type LocationsList []Location diff --git a/internal/service/cloudapi/zone/flattens.go b/internal/service/cloudapi/zone/flattens.go index ec267ead..5af35114 100644 --- a/internal/service/cloudapi/zone/flattens.go +++ b/internal/service/cloudapi/zone/flattens.go @@ -1,91 +1,91 @@ -/* -Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 zone - -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - log "github.com/sirupsen/logrus" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone" -) - -func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error { - log.Debugf("flattenZone: start decoding RecordZone name %q / ID %d", - item.Name, item.ID) - - d.Set("zone_id", int(item.ID)) - d.Set("guid", int(item.GUID)) - d.Set("gid", int(item.GID)) - d.Set("name", item.Name) - d.Set("description", item.Description) - d.Set("deletable", item.Deletable) - d.Set("status", item.Status) - d.Set("created_time", item.CreatedTime) - d.Set("updated_time", item.UpdatedTime) - d.Set("node_ids", item.NodeIDs) - d.Set("account_ids", item.AccountIDs) - d.Set("compute_ids", item.ComputeIDs) - d.Set("extnet_ids", item.ExtnetIDs) - d.Set("vins_ids", item.VinsIDs) - d.Set("lb_ids", item.LBIDs) - d.Set("bservice_ids", item.BserviceIDs) - d.Set("k8s_ids", item.K8SIDs) - d.Set("auto_start", item.AutoStart) - - log.Debugf("flattenZone: decoded RecordZone name %q / ID %d, complete", - item.Name, item.ID) - return nil -} - -func flattenZoneList(zone *zone.ListZones) []map[string]interface{} { - log.Debugf("flattenZoneList start") - res := make([]map[string]interface{}, 0, len(zone.Data)) - for _, zone := range zone.Data { - temp := map[string]interface{}{ - "zone_id": int(zone.ID), - "guid": int(zone.GUID), - "gid": int(zone.GID), - "name": zone.Name, - "description": zone.Description, - "deletable": zone.Deletable, - "status": zone.Status, - "created_time": zone.CreatedTime, - "updated_time": zone.UpdatedTime, - "node_ids": zone.NodeIDs, - "auto_start": zone.AutoStart, - } - res = append(res, temp) - } - log.Debugf("flattenZoneList end") - return res - -} +/* +Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 zone + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone" +) + +func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error { + log.Debugf("flattenZone: start decoding RecordZone name %q / ID %d", + item.Name, item.ID) + + d.Set("zone_id", int(item.ID)) + d.Set("guid", int(item.GUID)) + d.Set("gid", int(item.GID)) + d.Set("name", item.Name) + d.Set("description", item.Description) + d.Set("deletable", item.Deletable) + d.Set("status", item.Status) + d.Set("created_time", item.CreatedTime) + d.Set("updated_time", item.UpdatedTime) + d.Set("node_ids", item.NodeIDs) + d.Set("account_ids", item.AccountIDs) + d.Set("compute_ids", item.ComputeIDs) + d.Set("extnet_ids", item.ExtnetIDs) + d.Set("vins_ids", item.VinsIDs) + d.Set("lb_ids", item.LBIDs) + d.Set("bservice_ids", item.BserviceIDs) + d.Set("k8s_ids", item.K8SIDs) + d.Set("auto_start", item.AutoStart) + + log.Debugf("flattenZone: decoded RecordZone name %q / ID %d, complete", + item.Name, item.ID) + return nil +} + +func flattenZoneList(zone *zone.ListZones) []map[string]interface{} { + log.Debugf("flattenZoneList start") + res := make([]map[string]interface{}, 0, len(zone.Data)) + for _, zone := range zone.Data { + temp := map[string]interface{}{ + "zone_id": int(zone.ID), + "guid": int(zone.GUID), + "gid": int(zone.GID), + "name": zone.Name, + "description": zone.Description, + "deletable": zone.Deletable, + "status": zone.Status, + "created_time": zone.CreatedTime, + "updated_time": zone.UpdatedTime, + "node_ids": zone.NodeIDs, + "auto_start": zone.AutoStart, + } + res = append(res, temp) + } + log.Debugf("flattenZoneList end") + return res + +} diff --git a/internal/service/cloudapi/zone/utility_zone.go b/internal/service/cloudapi/zone/utility_zone.go index 32fd92f9..c1ac64bd 100644 --- a/internal/service/cloudapi/zone/utility_zone.go +++ b/internal/service/cloudapi/zone/utility_zone.go @@ -1,62 +1,62 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 zone - -import ( - "context" - "strconv" - - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func utilityZoneCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.RecordZone, error) { - c := m.(*controller.ControllerCfg) - req := zone.GetRequest{} - - if d.Id() != "" { - zoneId, _ := strconv.ParseUint(d.Id(), 10, 64) - req.ID = zoneId - } else { - req.ID = uint64(d.Get("zone_id").(int)) - } - - zoneData, err := c.CloudAPI().Zone().Get(ctx, req) - if err != nil { - return nil, err - } - - return zoneData, nil -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 zone + +import ( + "context" + "strconv" + + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityZoneCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.RecordZone, error) { + c := m.(*controller.ControllerCfg) + req := zone.GetRequest{} + + if d.Id() != "" { + zoneId, _ := strconv.ParseUint(d.Id(), 10, 64) + req.ID = zoneId + } else { + req.ID = uint64(d.Get("zone_id").(int)) + } + + zoneData, err := c.CloudAPI().Zone().Get(ctx, req) + if err != nil { + return nil, err + } + + return zoneData, nil +} diff --git a/internal/service/cloudapi/zone/utility_zone_list.go b/internal/service/cloudapi/zone/utility_zone_list.go index d1bfa97a..65eb3e5f 100644 --- a/internal/service/cloudapi/zone/utility_zone_list.go +++ b/internal/service/cloudapi/zone/utility_zone_list.go @@ -1,85 +1,85 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 zone - -import ( - "context" - - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func utilityZoneListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.ListZones, error) { - c := m.(*controller.ControllerCfg) - req := zone.ListRequest{} - - if byId, ok := d.GetOk("by_id"); ok { - req.ByID = uint64(byId.(int)) - } - if gid, ok := d.GetOk("gid"); ok { - req.GID = uint64(gid.(int)) - } - if name, ok := d.GetOk("name"); ok { - req.Name = name.(string) - } - if description, ok := d.GetOk("description"); ok { - req.Description = description.(string) - } - if status, ok := d.GetOk("status"); ok { - req.Status = status.(string) - } - if deletable, ok := d.GetOk("deletable"); ok { - req.Deletable = deletable.(bool) - } - if nodeID, ok := d.GetOk("nodeId"); ok { - req.NodeID = uint64(nodeID.(int)) - } - if sortBy, ok := d.GetOk("sort_by"); ok { - req.SortBy = sortBy.(string) - } - if size, ok := d.GetOk("size"); ok { - req.Size = uint64(size.(int)) - } - if page, ok := d.GetOk("page"); ok { - req.Page = uint64(page.(int)) - } - - zoneList, err := c.CloudAPI().Zone().List(ctx, req) - if err != nil { - return nil, err - } - - return zoneList, nil -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 zone + +import ( + "context" + + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityZoneListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.ListZones, error) { + c := m.(*controller.ControllerCfg) + req := zone.ListRequest{} + + if byId, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(byId.(int)) + } + if gid, ok := d.GetOk("gid"); ok { + req.GID = uint64(gid.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if description, ok := d.GetOk("description"); ok { + req.Description = description.(string) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if deletable, ok := d.GetOk("deletable"); ok { + req.Deletable = deletable.(bool) + } + if nodeID, ok := d.GetOk("nodeId"); ok { + req.NodeID = uint64(nodeID.(int)) + } + if sortBy, ok := d.GetOk("sort_by"); ok { + req.SortBy = sortBy.(string) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + zoneList, err := c.CloudAPI().Zone().List(ctx, req) + if err != nil { + return nil, err + } + + return zoneList, nil +} diff --git a/internal/service/cloudbroker/flipgroup/flattens.go b/internal/service/cloudbroker/flipgroup/flattens.go index b4f78774..b211a510 100644 --- a/internal/service/cloudbroker/flipgroup/flattens.go +++ b/internal/service/cloudbroker/flipgroup/flattens.go @@ -68,6 +68,34 @@ func flattenFlipgroup(d *schema.ResourceData, flip *flipgroup.RecordFLIPGroup) { d.Set("updated_time", flip.UpdatedTime) } +func flattenFlipgroupResource(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("desc", 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("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 { diff --git a/internal/service/cloudbroker/flipgroup/resource_flipgroup.go b/internal/service/cloudbroker/flipgroup/resource_flipgroup.go index 5e5a5ac0..fdbf6335 100644 --- a/internal/service/cloudbroker/flipgroup/resource_flipgroup.go +++ b/internal/service/cloudbroker/flipgroup/resource_flipgroup.go @@ -110,7 +110,7 @@ func resourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interf return diag.Errorf("The flipgroup status is destroyed and cannot be read.") } - flattenFlipgroup(d, fg) + flattenFlipgroupResource(d, fg) log.Debugf("resourceFlipgroupRead: after flattenFlipgroup: flipgroup_id %s, name %s", d.Id(), d.Get("name").(string)) diff --git a/internal/service/cloudbroker/k8s/schema.go b/internal/service/cloudbroker/k8s/schema.go index 219158eb..d6d879cb 100644 --- a/internal/service/cloudbroker/k8s/schema.go +++ b/internal/service/cloudbroker/k8s/schema.go @@ -1466,14 +1466,14 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema { Optional: true, Description: "insert ssl certificate in x509 pem format", }, - "chipset": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), - Default: "Q35", - Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", - }, - "lb_sysctl_params": { + "chipset": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), + Default: "Q35", + Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", + }, + "lb_sysctl_params": { Type: schema.TypeList, Optional: true, Description: "Custom sysctl values for Load Balancer instance. Applied on boot.", @@ -1810,19 +1810,19 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema { ), Description: "Node RAM in MB.", }, - "chipset": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), - Default: "Q35", - Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", - }, - "disk": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.", - }, + "chipset": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), + Default: "Q35", + Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35", + }, + "disk": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.", + }, "labels": { Type: schema.TypeList, Computed: true, diff --git a/internal/service/cloudbroker/kvmvm/resource_check_input_values.go b/internal/service/cloudbroker/kvmvm/resource_check_input_values.go index c0969933..79971b88 100644 --- a/internal/service/cloudbroker/kvmvm/resource_check_input_values.go +++ b/internal/service/cloudbroker/kvmvm/resource_check_input_values.go @@ -17,8 +17,10 @@ func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *contro errs = append(errs, err) } - if err := ic.ExistImage(ctx, uint64(d.Get("image_id").(int)), c); err != nil { - errs = append(errs, err) + if !d.Get("create_blank").(bool) { + if err := ic.ExistImage(ctx, uint64(d.Get("image_id").(int)), c); err != nil { + errs = append(errs, err) + } } if netErrs := existNetworks(ctx, d, c); errs != nil { diff --git a/internal/service/cloudbroker/kvmvm/resource_compute.go b/internal/service/cloudbroker/kvmvm/resource_compute.go index 8c5f6d16..613fbb3e 100644 --- a/internal/service/cloudbroker/kvmvm/resource_compute.go +++ b/internal/service/cloudbroker/kvmvm/resource_compute.go @@ -251,7 +251,32 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf } log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86") - apiResp, err := c.CloudBroker().KVMX86().Create(ctx, createReqX86) + var apiResp uint64 + var err error + if d.Get("create_blank").(bool) { + log.Debugf("resourceComputeCreate: using createBlank endpoint") + createBlankReq := kvmx86.CreateBlankRequest{ + RGID: createReqX86.RGID, + Name: createReqX86.Name, + CPU: createReqX86.CPU, + RAM: createReqX86.RAM, + StoragePolicyID: createReqX86.StoragePolicyID, + WithoutBootDisk: createReqX86.WithoutBootDisk, + BootDisk: createReqX86.BootDisk, + SEPID: createReqX86.SEPID, + Pool: createReqX86.Pool, + DataDisks: createReqX86.DataDisks, + Interfaces: createReqX86.Interfaces, + Description: createReqX86.Description, + Chipset: createReqX86.Chipset, + PreferredCPU: createReqX86.PreferredCPU, + ZoneID: createReqX86.ZoneID, + OSVersion: createReqX86.OSVersion, + } + apiResp, err = c.CloudBroker().KVMX86().CreateBlank(ctx, createBlankReq) + } else { + apiResp, err = c.CloudBroker().KVMX86().Create(ctx, createReqX86) + } if err != nil { return diag.FromErr(err) } @@ -448,6 +473,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf if nodeID, ok := d.GetOk("node_id"); ok { req.NodeID = uint64(nodeID.(int)) } + if altBootID, ok := d.Get("alt_boot_id").(int); ok { + req.AltBootID = uint64(altBootID) + } log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId) if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil { warnings.Add(err) diff --git a/internal/service/cloudbroker/kvmvm/schema.go b/internal/service/cloudbroker/kvmvm/schema.go index 372d7f24..45536eab 100644 --- a/internal/service/cloudbroker/kvmvm/schema.go +++ b/internal/service/cloudbroker/kvmvm/schema.go @@ -3409,6 +3409,12 @@ func resourceComputeSchemaMake() map[string]*schema.Schema { Optional: true, Default: false, }, + "create_blank": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "If True, the compute is created via kvmx86/createBlank endpoint (without OS image). The image_id field is not required in this case.", + }, "boot_disk_size": { Type: schema.TypeInt, Optional: true, @@ -3531,22 +3537,22 @@ func resourceComputeSchemaMake() map[string]*schema.Schema { DiffSuppressFunc: networkSubresIPAddreDiffSupperss, Description: "unique_identifier of LogicalPort on SDN side", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - Description: "network enable flag", - }, - "net_mask": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - Description: "Subnet mask, used only for DPDK and VFNIC network types", + "enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "network enable flag", + }, + "net_mask": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Subnet mask, used only for DPDK and VFNIC network types", + }, }, }, + Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.", }, - Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.", - }, "libvirt_settings": { Type: schema.TypeSet, @@ -3757,11 +3763,9 @@ func resourceComputeSchemaMake() map[string]*schema.Schema { Description: "Storage endpoint provider ID; by default the same with boot disk", }, "disk_type": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"B", "D"}, false), - Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'", + Type: schema.TypeString, + Computed: true, + Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'", }, "pool": { Type: schema.TypeString, diff --git a/internal/service/cloudbroker/kvmvm/utility_compute.go b/internal/service/cloudbroker/kvmvm/utility_compute.go index 7db0dccb..ed0d7235 100644 --- a/internal/service/cloudbroker/kvmvm/utility_compute.go +++ b/internal/service/cloudbroker/kvmvm/utility_compute.go @@ -209,7 +209,11 @@ func utilityComputeResize(ctx context.Context, d *schema.ResourceData, m interfa } if isStopRequired { - if _, err := c.CloudBroker().Compute().Start(ctx, compute.StartRequest{ComputeID: computeId}); err != nil { + req := compute.StartRequest{ComputeID: computeId} + if altBootID, ok := d.Get("alt_boot_id").(int); ok { + req.AltBootID = uint64(altBootID) + } + if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil { return err } } @@ -362,9 +366,6 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in if diskConv["sep_id"].(int) != 0 { req.SepID = uint64(diskConv["sep_id"].(int)) } - if diskConv["disk_type"].(string) != "" { - req.DiskType = diskConv["disk_type"].(string) - } if diskConv["pool"].(string) != "" { req.Pool = diskConv["pool"].(string) } @@ -981,7 +982,13 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData if needStart { computeId, _ := strconv.ParseUint(d.Id(), 10, 64) - if numErr, err := utilityComputeStart(ctx, computeId, m); err != nil { + var altBootID uint64 + if altBootIDRaw, ok := d.Get("alt_boot_id").(int); ok { + altBootID = uint64(altBootIDRaw) + } else { + altBootID = 0 + } + if numErr, err := utilityComputeStart(ctx, altBootID, computeId, m); err != nil { apiErrCount += numErr lastSavedError = err } @@ -1308,7 +1315,11 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa // If used to be STARTED, we need to start it after update if isStopRequired { - if _, err := c.CloudBroker().Compute().Start(ctx, compute.StartRequest{ComputeID: computeId}); err != nil { + req := compute.StartRequest{ComputeID: computeId} + if altBootID, ok := d.Get("alt_boot_id").(int); ok { + req.AltBootID = uint64(altBootID) + } + if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil { return err } } @@ -1779,6 +1790,9 @@ func utilityComputeRollback(ctx context.Context, d *schema.ResourceData, m inter } startReq := compute.StartRequest{ComputeID: computeId} + if altBootID, ok := d.Get("alt_boot_id").(int); ok { + startReq.AltBootID = uint64(altBootID) + } log.Debugf("utilityComputeRollback: starting compute %d", computeId) @@ -2036,10 +2050,14 @@ func utilityComputeStop(ctx context.Context, d *schema.ResourceData, m interface return nil } -func utilityComputeStart(ctx context.Context, computeID uint64, m interface{}) (int, error) { +func utilityComputeStart(ctx context.Context, computeID uint64, altBootID uint64, m interface{}) (int, error) { c := m.(*controller.ControllerCfg) startReq := compute.StartRequest{ComputeID: computeID} + if altBootID > 0 { + startReq.AltBootID = altBootID + } + log.Debugf("utilityComputeStart: starting compute %d", computeID) _, err := c.CloudBroker().Compute().Start(ctx, startReq) if err != nil { diff --git a/internal/service/cloudbroker/trunk/flattens.go b/internal/service/cloudbroker/trunk/flattens.go index 49510cf9..a8c467e7 100644 --- a/internal/service/cloudbroker/trunk/flattens.go +++ b/internal/service/cloudbroker/trunk/flattens.go @@ -15,11 +15,11 @@ func flattenTrunkResource(d *schema.ResourceData, details *trunk.ItemTrunk) { d.Set("name", details.Name) d.Set("mac", details.MAC) d.Set("description", details.Description) - d.Set("accountIds", details.AccountIDs) - d.Set("ovsBridge", details.OVSBridge) - d.Set("nativeVlanId", details.NativeVLANID) + d.Set("account_ids", details.AccountIDs) + d.Set("ovs_bridge", details.OVSBridge) + d.Set("native_vlan_id", details.NativeVLANID) d.Set("status", details.Status) - d.Set("trunkTags", details.TrunkTags) + d.Set("trunk_tags", details.TrunkTags) d.Set("created_at", details.CreatedAt) d.Set("created_by", details.CreatedBy) d.Set("updated_at", details.UpdatedAt) diff --git a/internal/service/cloudbroker/vfpool/resource_vfpool.go b/internal/service/cloudbroker/vfpool/resource_vfpool.go index 5ea466b5..1e10ce3b 100644 --- a/internal/service/cloudbroker/vfpool/resource_vfpool.go +++ b/internal/service/cloudbroker/vfpool/resource_vfpool.go @@ -33,6 +33,7 @@ package vfpool import ( "context" + "fmt" "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -85,6 +86,12 @@ func resourceVFPoolCreate(ctx context.Context, d *schema.ResourceData, m interfa } config, configOk := d.GetOk("config") + + enableVal := d.Get("enable").(bool) + if enableVal && !configOk { + return diag.FromErr(fmt.Errorf("enable requires config to be set")) + } + if configOk { configArray := config.(*schema.Set).List() req.Config = make([]vfpool.Config, 0, len(configArray)) @@ -117,10 +124,8 @@ func resourceVFPoolCreate(ctx context.Context, d *schema.ResourceData, m interfa warnings := dc.Warnings{} - if enable, ok := d.GetOk("enable"); ok { - if err := utilityVFPoolEnabled(ctx, m, enable.(bool), vfPoolID, configOk); err != nil { - warnings.Add(err) - } + if err := utilityVFPoolEnabled(ctx, m, enableVal, vfPoolID); err != nil { + warnings.Add(err) } log.Debugf("resourceVFPoolCreate: create VFPool with ID: %d, complete", vfPoolID) @@ -147,20 +152,12 @@ func resourceVFPoolUpdate(ctx context.Context, d *schema.ResourceData, m interfa log.Debugf("resourceVFPoolUpdate: called VFPool with id %d", vfPoolID) - _, ok := d.GetOk("config") - - if d.HasChanges("name,", "description", "account_access", "rg_access,", "config") { + if d.HasChanges("name", "description", "account_access", "rg_access", "config", "enable") { if err := utilityVFPoolUpdate(ctx, d, m, vfPoolID); err != nil { return diag.FromErr(err) } } - if d.HasChange("enable") { - if err := utilityVFPoolEnabled(ctx, m, d.Get("enable").(bool), vfPoolID, ok); err != nil { - return diag.FromErr(err) - } - } - log.Debugf("resourceVFPoolUpdate: update VFPool with id %d, complete", vfPoolID) return resourceVFPoolRead(ctx, d, m) diff --git a/internal/service/cloudbroker/vfpool/utility_vfpool.go b/internal/service/cloudbroker/vfpool/utility_vfpool.go index 7fd0c985..8b3e4d55 100644 --- a/internal/service/cloudbroker/vfpool/utility_vfpool.go +++ b/internal/service/cloudbroker/vfpool/utility_vfpool.go @@ -64,37 +64,26 @@ func utilityVFpoolCheckPresence(ctx context.Context, d *schema.ResourceData, m i return vfpoolData, nil } -func utilityVFPoolEnabled(ctx context.Context, m interface{}, enable bool, vfPoolID uint64, configOk bool) error { +func utilityVFPoolEnabled(ctx context.Context, m interface{}, enable bool, vfPoolID uint64) error { c := m.(*controller.ControllerCfg) - if enable && configOk { - req := vfpool.EnableRequest{ - VFPoolID: vfPoolID, - } - _, err := c.CloudBroker().VFPool().Enable(ctx, req) - if err != nil { - return err - } - } - if enable && !configOk { - return fmt.Errorf("you must provide configuration for this resource, after enabling it") - } - if !enable { - req := vfpool.DisableRequest{ - VFPoolID: vfPoolID, - } - _, err := c.CloudBroker().VFPool().Disable(ctx, req) - if err != nil { - return err - } + var err error + + if enable { + _, err = c.CloudBroker().VFPool().Enable(ctx, vfpool.EnableRequest{VFPoolID: vfPoolID}) + } else { + _, err = c.CloudBroker().VFPool().Disable(ctx, vfpool.DisableRequest{VFPoolID: vfPoolID}) } - log.Debugf("utilityVFPoolEnabled: enable=%v vfPool ID %d after completing its resource configuration", enable, vfPoolID) - - return nil + return err } func utilityVFPoolUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, vfPoolID uint64) error { + hasConfig := len(d.Get("config").(*schema.Set).List()) > 0 + if d.Get("enable").(bool) && !hasConfig { + return fmt.Errorf("enable requires config to be set") + } + c := m.(*controller.ControllerCfg) vfPool, err := utilityVFpoolCheckPresence(ctx, d, m) @@ -190,7 +179,7 @@ func utilityVFPoolUpdate(ctx context.Context, d *schema.ResourceData, m interfac } log.Debugf("utilityVFPoolUpdate: update vfPool with ID: %d, complete with params=%v", vfPoolID, req) - if len(d.Get("config").(*schema.Set).List()) > 0 && d.Get("enable").(bool) { + if hasConfig && d.Get("enable").(bool) { reqEnable := vfpool.EnableRequest{ VFPoolID: vfPoolID, } @@ -201,8 +190,6 @@ func utilityVFPoolUpdate(ctx context.Context, d *schema.ResourceData, m interfac return err } log.Debugf("utilityVFPoolUpdate: enable vfPool with ID: %d, complete", vfPoolID) - } else { - return (fmt.Errorf("the vfPool is not enabled after update, you must provide configuration for this resource, after enabling it")) } return nil diff --git a/internal/service/cloudbroker/zone/flattens.go b/internal/service/cloudbroker/zone/flattens.go index e9390862..a439331f 100644 --- a/internal/service/cloudbroker/zone/flattens.go +++ b/internal/service/cloudbroker/zone/flattens.go @@ -1,91 +1,91 @@ -/* -Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 zone - -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - log "github.com/sirupsen/logrus" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone" -) - -func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error { - log.Debugf("flattenZone: start decoding RecordZone name %q / ID %d", - item.Name, item.ID) - - d.Set("zone_id", int(item.ID)) - d.Set("guid", int(item.GUID)) - d.Set("gid", int(item.GID)) - d.Set("name", item.Name) - d.Set("description", item.Description) - d.Set("deletable", item.Deletable) - d.Set("status", item.Status) - d.Set("created_time", item.CreatedTime) - d.Set("updated_time", item.UpdatedTime) - d.Set("node_ids", item.NodeIDs) - d.Set("account_ids", item.AccountIDs) - d.Set("compute_ids", item.ComputeIDs) - d.Set("extnet_ids", item.ExtnetIDs) - d.Set("vins_ids", item.VinsIDs) - d.Set("lb_ids", item.LBIDs) - d.Set("bservice_ids", item.BserviceIDs) - d.Set("k8s_ids", item.K8SIDs) - d.Set("auto_start", item.AutoStart) - - log.Debugf("flattenZone: decoded RecordZone name %q / ID %d, complete", - item.Name, item.ID) - return nil -} - -func flattenZoneList(zone *zone.ListZones) []map[string]interface{} { - log.Debugf("flattenZoneList start") - res := make([]map[string]interface{}, 0, len(zone.Data)) - for _, zone := range zone.Data { - temp := map[string]interface{}{ - "zone_id": int(zone.ID), - "guid": int(zone.GUID), - "gid": int(zone.GID), - "name": zone.Name, - "description": zone.Description, - "deletable": zone.Deletable, - "status": zone.Status, - "created_time": zone.CreatedTime, - "updated_time": zone.UpdatedTime, - "node_ids": zone.NodeIDs, - "auto_start": zone.AutoStart, - } - res = append(res, temp) - } - log.Debugf("flattenZoneList end") - return res - -} +/* +Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 zone + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone" +) + +func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error { + log.Debugf("flattenZone: start decoding RecordZone name %q / ID %d", + item.Name, item.ID) + + d.Set("zone_id", int(item.ID)) + d.Set("guid", int(item.GUID)) + d.Set("gid", int(item.GID)) + d.Set("name", item.Name) + d.Set("description", item.Description) + d.Set("deletable", item.Deletable) + d.Set("status", item.Status) + d.Set("created_time", item.CreatedTime) + d.Set("updated_time", item.UpdatedTime) + d.Set("node_ids", item.NodeIDs) + d.Set("account_ids", item.AccountIDs) + d.Set("compute_ids", item.ComputeIDs) + d.Set("extnet_ids", item.ExtnetIDs) + d.Set("vins_ids", item.VinsIDs) + d.Set("lb_ids", item.LBIDs) + d.Set("bservice_ids", item.BserviceIDs) + d.Set("k8s_ids", item.K8SIDs) + d.Set("auto_start", item.AutoStart) + + log.Debugf("flattenZone: decoded RecordZone name %q / ID %d, complete", + item.Name, item.ID) + return nil +} + +func flattenZoneList(zone *zone.ListZones) []map[string]interface{} { + log.Debugf("flattenZoneList start") + res := make([]map[string]interface{}, 0, len(zone.Data)) + for _, zone := range zone.Data { + temp := map[string]interface{}{ + "zone_id": int(zone.ID), + "guid": int(zone.GUID), + "gid": int(zone.GID), + "name": zone.Name, + "description": zone.Description, + "deletable": zone.Deletable, + "status": zone.Status, + "created_time": zone.CreatedTime, + "updated_time": zone.UpdatedTime, + "node_ids": zone.NodeIDs, + "auto_start": zone.AutoStart, + } + res = append(res, temp) + } + log.Debugf("flattenZoneList end") + return res + +} diff --git a/internal/service/cloudbroker/zone/utility_zone.go b/internal/service/cloudbroker/zone/utility_zone.go index dc8a2e6b..7c4dc595 100644 --- a/internal/service/cloudbroker/zone/utility_zone.go +++ b/internal/service/cloudbroker/zone/utility_zone.go @@ -1,159 +1,159 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 zone - -import ( - "context" - "strconv" - - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - log "github.com/sirupsen/logrus" -) - -func utilityZoneCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.RecordZone, error) { - c := m.(*controller.ControllerCfg) - req := zone.GetRequest{} - - if d.Id() != "" { - zoneId, _ := strconv.ParseUint(d.Id(), 10, 64) - req.ID = zoneId - } else { - req.ID = uint64(d.Get("zone_id").(int)) - } - - zoneData, err := c.CloudBroker().Zone().Get(ctx, req) - if err != nil { - return nil, err - } - - return zoneData, nil -} - -func utilityZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, zoneID uint64) error { - c := m.(*controller.ControllerCfg) - - if d.HasChanges("name", "description", "auto_start") { - req := zone.UpdateRequest{ - ID: zoneID, - } - - if d.HasChange("name") { - req.Name = d.Get("name").(string) - } - if d.HasChange("description") { - req.Description = d.Get("description").(string) - } - - if d.HasChange("auto_start") { - req.AutoStart = d.Get("auto_start").(bool) - } - - _, err := c.CloudBroker().Zone().Update(ctx, req) - if err != nil { - return err - } - log.Debugf("utilityZoneUpdate: update zone with ID: %d, complete with params=%v", zoneID, req) - } - - addedNodes := make([]interface{}, 0) - removedNodes := make([]interface{}, 0) - - old_set, new_set := d.GetChange("node_ids") - oldSlice := old_set.([]interface{}) - newSlice := new_set.([]interface{}) - - for _, oldElem := range oldSlice { - if !containsNodes(newSlice, oldElem) { - removedNodes = append(removedNodes, oldElem) - } - } - - for _, newElem := range newSlice { - if !containsNodes(oldSlice, newElem) { - addedNodes = append(addedNodes, newElem) - } - } - - log.Debugf("Found node_ids change with %v deletion(s) and %v addition(s) [zoneID=%v]", len(removedNodes), len(addedNodes), zoneID) - - if len(addedNodes) > 0 { - - addedUint := make([]uint64, len(addedNodes)) - for i, v := range addedNodes { - addedUint[i] = uint64(v.(int)) - } - - req := zone.AddNodeRequest{ - ID: zoneID, - NodeIDs: addedUint, - } - if _, err := c.CloudBroker().Zone().AddNode(ctx, req); err != nil { - return err - } - - } - - if len(removedNodes) > 0 { - removedUint := make([]uint64, len(removedNodes)) - for i, v := range removedNodes { - removedUint[i] = uint64(v.(int)) - } - - req := zone.DelNodeRequest{ - ID: zoneID, - NodeIDs: removedUint, - } - log.Debug("del") - log.Debug(req.NodeIDs) - if _, err := c.CloudBroker().Zone().DelNode(ctx, req); err != nil { - return err - } - } - - return nil -} - -func containsNodes(set []interface{}, check interface{}) bool { - for _, elem := range set { - elemConv := elem.(int) - checkConv := check.(int) - if elemConv == checkConv { - return true - } - } - - return false -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 zone + +import ( + "context" + "strconv" + + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" +) + +func utilityZoneCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.RecordZone, error) { + c := m.(*controller.ControllerCfg) + req := zone.GetRequest{} + + if d.Id() != "" { + zoneId, _ := strconv.ParseUint(d.Id(), 10, 64) + req.ID = zoneId + } else { + req.ID = uint64(d.Get("zone_id").(int)) + } + + zoneData, err := c.CloudBroker().Zone().Get(ctx, req) + if err != nil { + return nil, err + } + + return zoneData, nil +} + +func utilityZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, zoneID uint64) error { + c := m.(*controller.ControllerCfg) + + if d.HasChanges("name", "description", "auto_start") { + req := zone.UpdateRequest{ + ID: zoneID, + } + + if d.HasChange("name") { + req.Name = d.Get("name").(string) + } + if d.HasChange("description") { + req.Description = d.Get("description").(string) + } + + if d.HasChange("auto_start") { + req.AutoStart = d.Get("auto_start").(bool) + } + + _, err := c.CloudBroker().Zone().Update(ctx, req) + if err != nil { + return err + } + log.Debugf("utilityZoneUpdate: update zone with ID: %d, complete with params=%v", zoneID, req) + } + + addedNodes := make([]interface{}, 0) + removedNodes := make([]interface{}, 0) + + old_set, new_set := d.GetChange("node_ids") + oldSlice := old_set.([]interface{}) + newSlice := new_set.([]interface{}) + + for _, oldElem := range oldSlice { + if !containsNodes(newSlice, oldElem) { + removedNodes = append(removedNodes, oldElem) + } + } + + for _, newElem := range newSlice { + if !containsNodes(oldSlice, newElem) { + addedNodes = append(addedNodes, newElem) + } + } + + log.Debugf("Found node_ids change with %v deletion(s) and %v addition(s) [zoneID=%v]", len(removedNodes), len(addedNodes), zoneID) + + if len(addedNodes) > 0 { + + addedUint := make([]uint64, len(addedNodes)) + for i, v := range addedNodes { + addedUint[i] = uint64(v.(int)) + } + + req := zone.AddNodeRequest{ + ID: zoneID, + NodeIDs: addedUint, + } + if _, err := c.CloudBroker().Zone().AddNode(ctx, req); err != nil { + return err + } + + } + + if len(removedNodes) > 0 { + removedUint := make([]uint64, len(removedNodes)) + for i, v := range removedNodes { + removedUint[i] = uint64(v.(int)) + } + + req := zone.DelNodeRequest{ + ID: zoneID, + NodeIDs: removedUint, + } + log.Debug("del") + log.Debug(req.NodeIDs) + if _, err := c.CloudBroker().Zone().DelNode(ctx, req); err != nil { + return err + } + } + + return nil +} + +func containsNodes(set []interface{}, check interface{}) bool { + for _, elem := range set { + elemConv := elem.(int) + checkConv := check.(int) + if elemConv == checkConv { + return true + } + } + + return false +} diff --git a/internal/service/cloudbroker/zone/utility_zone_list.go b/internal/service/cloudbroker/zone/utility_zone_list.go index febadd32..e17cbf63 100644 --- a/internal/service/cloudbroker/zone/utility_zone_list.go +++ b/internal/service/cloudbroker/zone/utility_zone_list.go @@ -1,85 +1,85 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 zone - -import ( - "context" - - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func utilityZoneListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.ListZones, error) { - c := m.(*controller.ControllerCfg) - req := zone.ListRequest{} - - if byId, ok := d.GetOk("by_id"); ok { - req.ByID = uint64(byId.(int)) - } - if gid, ok := d.GetOk("gid"); ok { - req.GID = uint64(gid.(int)) - } - if name, ok := d.GetOk("name"); ok { - req.Name = name.(string) - } - if description, ok := d.GetOk("description"); ok { - req.Description = description.(string) - } - if status, ok := d.GetOk("status"); ok { - req.Status = status.(string) - } - if deletable, ok := d.GetOk("deletable"); ok { - req.Deletable = deletable.(bool) - } - if nodeID, ok := d.GetOk("nodeId"); ok { - req.NodeID = uint64(nodeID.(int)) - } - if sortBy, ok := d.GetOk("sort_by"); ok { - req.SortBy = sortBy.(string) - } - if size, ok := d.GetOk("size"); ok { - req.Size = uint64(size.(int)) - } - if page, ok := d.GetOk("page"); ok { - req.Page = uint64(page.(int)) - } - - zoneList, err := c.CloudBroker().Zone().List(ctx, req) - if err != nil { - return nil, err - } - - return zoneList, nil -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 zone + +import ( + "context" + + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityZoneListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.ListZones, error) { + c := m.(*controller.ControllerCfg) + req := zone.ListRequest{} + + if byId, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(byId.(int)) + } + if gid, ok := d.GetOk("gid"); ok { + req.GID = uint64(gid.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if description, ok := d.GetOk("description"); ok { + req.Description = description.(string) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if deletable, ok := d.GetOk("deletable"); ok { + req.Deletable = deletable.(bool) + } + if nodeID, ok := d.GetOk("nodeId"); ok { + req.NodeID = uint64(nodeID.(int)) + } + if sortBy, ok := d.GetOk("sort_by"); ok { + req.SortBy = sortBy.(string) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + zoneList, err := c.CloudBroker().Zone().List(ctx, req) + if err != nil { + return nil, err + } + + return zoneList, nil +} diff --git a/internal/service/sdn/access_group/data_decort_sdn_access_group_list.go b/internal/service/sdn/access_group/data_decort_sdn_access_group_list.go index 64ea6c8b..c6886256 100644 --- a/internal/service/sdn/access_group/data_decort_sdn_access_group_list.go +++ b/internal/service/sdn/access_group/data_decort_sdn_access_group_list.go @@ -37,3 +37,4 @@ func DataSourceAccessGroupList() *schema.Resource { Schema: dataSourceAccessGroupListSchemaMake(), } } + diff --git a/internal/service/sdn/access_group/utility_access_group_list.go b/internal/service/sdn/access_group/utility_access_group_list.go index f0c55b15..9f84b701 100644 --- a/internal/service/sdn/access_group/utility_access_group_list.go +++ b/internal/service/sdn/access_group/utility_access_group_list.go @@ -49,3 +49,4 @@ func utilityAccessGroupListCheckPresence(ctx context.Context, d *schema.Resource return accessGroupList, nil } + diff --git a/internal/service/sdn/default_security_policy/data_decort_sdn_default_security_policy_list.go b/internal/service/sdn/default_security_policy/data_decort_sdn_default_security_policy_list.go index 02203214..44758639 100644 --- a/internal/service/sdn/default_security_policy/data_decort_sdn_default_security_policy_list.go +++ b/internal/service/sdn/default_security_policy/data_decort_sdn_default_security_policy_list.go @@ -37,3 +37,4 @@ func DataSourceDefaultSecurityPolicyList() *schema.Resource { Schema: dataSourceDefaultSecurityPolicyListSchemaMake(), } } + diff --git a/internal/service/sdn/default_security_policy/schema.go b/internal/service/sdn/default_security_policy/schema.go index 404f124f..daabaf8a 100644 --- a/internal/service/sdn/default_security_policy/schema.go +++ b/internal/service/sdn/default_security_policy/schema.go @@ -366,3 +366,4 @@ func dataSourceDefaultSecurityPolicyListSchemaMake() map[string]*schema.Schema { return res } + diff --git a/internal/service/sdn/default_security_policy/utility_default_security_policy_list.go b/internal/service/sdn/default_security_policy/utility_default_security_policy_list.go index a1895903..5cf41070 100644 --- a/internal/service/sdn/default_security_policy/utility_default_security_policy_list.go +++ b/internal/service/sdn/default_security_policy/utility_default_security_policy_list.go @@ -37,3 +37,4 @@ func utilityDefaultSecurityPolicyListCheckPresence(ctx context.Context, d *schem return defaultSecurityPolicyList, nil } + diff --git a/internal/service/sdn/segments/utility_segment_list.go b/internal/service/sdn/segments/utility_segment_list.go index 52c8ef93..b034b9d4 100644 --- a/internal/service/sdn/segments/utility_segment_list.go +++ b/internal/service/sdn/segments/utility_segment_list.go @@ -52,7 +52,7 @@ func utilitySegmentListCheckPresence(ctx context.Context, d *schema.ResourceData if updatedTo, ok := d.GetOk("updated_to"); ok { req.UpdatedTo = updatedTo.(string) } - + log.Debugf("utilitySegmentListCheckPresence") segmentList, err := c.SDN().Segments().List(ctx, req) if err != nil { diff --git a/samples/cloudapi/kvmvm/resource_kvmvm/main.tf b/samples/cloudapi/kvmvm/resource_kvmvm/main.tf index 8329b04a..4aaaa374 100644 --- a/samples/cloudapi/kvmvm/resource_kvmvm/main.tf +++ b/samples/cloudapi/kvmvm/resource_kvmvm/main.tf @@ -105,6 +105,12 @@ resource "decort_kvmvm" "comp" { #используется при создании и обновлении #image_id = 111 + #создание без образа ОС + #опциональный параметр + #тип - булев + #используется при создании + #create_blank = false + #создание без загрузочного диска в остановленном состоянии #опциональный параметр #если значение равно True, параметры image_id, boot_disk_size, sep_id, pool игнорируются @@ -120,6 +126,12 @@ resource "decort_kvmvm" "comp" { #используется при создании и обновлении #numa_affinity = "loose" + #id образа CD-ROM для загрузки + #опциональный параметр + #тип - целое число + #используется при создании и обновлении + #alt_boot_id = 1 + #необходимость запускать ВМ на выделенных CPU ядрах #опциональный параметр #по умолчанию - false diff --git a/samples/cloudbroker/kvmvm/resource_kvmvm/main.tf b/samples/cloudbroker/kvmvm/resource_kvmvm/main.tf index b700dae4..346a0f0b 100644 --- a/samples/cloudbroker/kvmvm/resource_kvmvm/main.tf +++ b/samples/cloudbroker/kvmvm/resource_kvmvm/main.tf @@ -83,6 +83,12 @@ resource "decort_cb_kvmvm" "comp" { #используется при создании #without_boot_disk = true + #создание без образа ОС + #опциональный параметр + #тип - булев + #используется при создании + #create_blank = false + #размер загрузочного диска #опциональный параметр #тип - целое число @@ -130,7 +136,7 @@ resource "decort_cb_kvmvm" "comp" { #id образа CD-ROM для загрузки #опциональный параметр #тип - целое число - #используется при обновлении, при повторном старте вм + #используется при создании и обновлении #alt_boot_id = 1 #необходимость выравнивать ВМ по NUMA