Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
739289fbb8 | ||
|
|
c89574c3e6 | ||
|
|
a1e61674c8 | ||
|
|
cb9ff26bb0 | ||
|
|
6932f9d305 | ||
|
|
712f8edf9e | ||
|
|
805ffe1f29 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ examples/
|
||||
url_scrapping/
|
||||
terraform-provider-decort*
|
||||
.vscode/
|
||||
.DS_Store
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
## Version 4.3.2
|
||||
## Version 4.3.8
|
||||
|
||||
## Bugfix
|
||||
- Fixed bugs with restore and newCreate after destroy
|
||||
|
||||
## Bugfixes
|
||||
- Fixed bootdisk flattens
|
||||
- Updated golang-decort-sdk version with fixed permamently field in cloudapi/cloudbroker/compute/diskDel
|
||||
5
Makefile
5
Makefile
@@ -7,11 +7,8 @@ ZIPDIR = ./zip
|
||||
BINARY=${NAME}
|
||||
WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH}
|
||||
MAINPATH = ./cmd/decort/
|
||||
VERSION=4.3.2
|
||||
VERSION=4.3.8
|
||||
OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH)
|
||||
# OS_ARCH=darwin_arm64
|
||||
# OS_ARCH=windows_amd64
|
||||
# OS_ARCH=linux_amd64
|
||||
|
||||
FILES = ${BINARY}_${VERSION}_darwin_amd64\
|
||||
${BINARY}_${VERSION}_darwin_arm64\
|
||||
|
||||
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ require (
|
||||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
golang.org/x/net v0.12.0
|
||||
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3
|
||||
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.10
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
4
go.sum
4
go.sum
@@ -339,5 +339,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
|
||||
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.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.5.3 h1:Rt5tE4EZcUr4ONK9u/XYe2mG1CC37xLUnNuCLYKDwYs=
|
||||
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE=
|
||||
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.10 h1:LnnOxO8QxSaIfetrzivmRf7qBZJkiakHD0FJLYYAvv8=
|
||||
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.10/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE=
|
||||
|
||||
@@ -54,7 +54,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceAccountRead: called for account with ID: %v", d.Id())
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
// c := m.(*controller.ControllerCfg)
|
||||
|
||||
acc, err := utilityAccountCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
@@ -67,22 +67,23 @@ func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
switch acc.Status {
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceAccountCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceAccountCreate(ctx, d, m)
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The account is in progress with status: %s", acc.Status)
|
||||
case status.Deleted:
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
// id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
|
||||
req := account.RestoreRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
// req := account.RestoreRequest{
|
||||
// AccountID: id,
|
||||
// }
|
||||
|
||||
_, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
hasChanged = true
|
||||
// hasChanged = true
|
||||
case status.Disabled:
|
||||
log.Debugf("The account is in status: %s, troubles may occur with update. Please, enable account first.", acc.Status)
|
||||
case status.Confirmed:
|
||||
@@ -142,7 +143,8 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
switch acc.Status {
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceAccountCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceAccountCreate(ctx, d, m)
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The account is in progress with status: %s", acc.Status)
|
||||
case status.Deleted:
|
||||
|
||||
@@ -83,7 +83,7 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i
|
||||
func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceBasicServiceRead")
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
// c := m.(*controller.ControllerCfg)
|
||||
|
||||
bs, err := utilityBasicServiceCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
@@ -104,29 +104,30 @@ func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m int
|
||||
case status.Disabling:
|
||||
log.Debugf("The basic service is in status: %s, troubles can occur with the update.", bs.Status)
|
||||
case status.Deleted:
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
restoreReq := bservice.RestoreRequest{
|
||||
ServiceID: id,
|
||||
}
|
||||
enableReq := bservice.EnableRequest{
|
||||
ServiceID: id,
|
||||
}
|
||||
// id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
// restoreReq := bservice.RestoreRequest{
|
||||
// ServiceID: id,
|
||||
// }
|
||||
// enableReq := bservice.EnableRequest{
|
||||
// ServiceID: id,
|
||||
// }
|
||||
|
||||
_, err := c.CloudAPI().BService().Restore(ctx, restoreReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().BService().Restore(ctx, restoreReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
_, err = c.CloudAPI().BService().Enable(ctx, enableReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err = c.CloudAPI().BService().Enable(ctx, enableReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
hasChanged = true
|
||||
// hasChanged = true
|
||||
case status.Deleting:
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceBasicServiceCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceBasicServiceCreate(ctx, d, m)
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The basic service is in progress with status: %s", bs.Status)
|
||||
case status.Restoring:
|
||||
@@ -224,7 +225,8 @@ func resourceBasicServiceUpdate(ctx context.Context, d *schema.ResourceData, m i
|
||||
case status.Deleting:
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceBasicServiceCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceBasicServiceCreate(ctx, d, m)
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The basic service is in progress with status: %s", bs.Status)
|
||||
case status.Restoring:
|
||||
|
||||
@@ -142,7 +142,7 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
|
||||
func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
// c := m.(*controller.ControllerCfg)
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
@@ -157,23 +157,24 @@ func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
case status.Destroyed, status.Purged:
|
||||
d.Set("disk_id", 0)
|
||||
d.SetId("")
|
||||
return resourceDiskCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceDiskCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
req := disks.RestoreRequest{
|
||||
DiskID: disk.ID,
|
||||
}
|
||||
// hasChangeState = true
|
||||
// req := disks.RestoreRequest{
|
||||
// DiskID: disk.ID,
|
||||
// }
|
||||
|
||||
if reason, ok := d.GetOk("reason"); ok {
|
||||
req.Reason = reason.(string)
|
||||
} else {
|
||||
req.Reason = "Terraform automatic restore"
|
||||
}
|
||||
// if reason, ok := d.GetOk("reason"); ok {
|
||||
// req.Reason = reason.(string)
|
||||
// } else {
|
||||
// req.Reason = "Terraform automatic restore"
|
||||
// }
|
||||
|
||||
_, err := c.CloudAPI().Disks().Restore(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().Disks().Restore(ctx, req)
|
||||
// if err != nil {
|
||||
// warnings.Add(err)
|
||||
// }
|
||||
case status.Assigned:
|
||||
case status.Modeled:
|
||||
return diag.Errorf("The disk is in status: %s, please, contact support for more information", disk.Status)
|
||||
@@ -227,7 +228,8 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
case status.Destroyed, status.Purged:
|
||||
d.Set("disk_id", 0)
|
||||
d.SetId("")
|
||||
return resourceDiskCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceDiskCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
req := disks.RestoreRequest{
|
||||
@@ -271,7 +273,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
Size: uint64(newSize.(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Disks().Resize(ctx, req)
|
||||
_, err := c.CloudAPI().Disks().Resize2(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,8 @@ func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
case status.Created:
|
||||
case status.Destroyed, status.Purged:
|
||||
d.SetId("")
|
||||
return resourceImageCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceImageCreate(ctx, d, m)
|
||||
}
|
||||
|
||||
flattenImage(d, img)
|
||||
@@ -233,7 +234,8 @@ func resourceImageUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
case status.Created:
|
||||
case status.Destroyed, status.Purged:
|
||||
d.SetId("")
|
||||
return resourceImageCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceImageCreate(ctx, d, m)
|
||||
}
|
||||
|
||||
if d.HasChange("name") {
|
||||
|
||||
@@ -205,31 +205,32 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{})
|
||||
case status.Created:
|
||||
case status.Deleting:
|
||||
case status.Deleted:
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
restoreReq := k8s.RestoreRequest{
|
||||
K8SID: id,
|
||||
}
|
||||
// id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
// restoreReq := k8s.RestoreRequest{
|
||||
// K8SID: id,
|
||||
// }
|
||||
|
||||
_, err := c.CloudAPI().K8S().Restore(ctx, restoreReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().K8S().Restore(ctx, restoreReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
enableReq := k8s.DisableEnableRequest{
|
||||
K8SID: id,
|
||||
}
|
||||
// enableReq := k8s.DisableEnableRequest{
|
||||
// K8SID: id,
|
||||
// }
|
||||
|
||||
_, err = c.CloudAPI().K8S().Enable(ctx, enableReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err = c.CloudAPI().K8S().Enable(ctx, enableReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
hasChanged = true
|
||||
// hasChanged = true
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The k8s cluster is in progress with status: %s", cluster.Status)
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceK8sCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceK8sCreate(ctx, d, m)
|
||||
case status.Enabling:
|
||||
case status.Enabled:
|
||||
case status.Disabling:
|
||||
@@ -388,7 +389,8 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
return diag.Errorf("The k8s cluster is in progress with status: %s", cluster.Status)
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceK8sCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceK8sCreate(ctx, d, m)
|
||||
case status.Enabling:
|
||||
case status.Enabled:
|
||||
case status.Disabling:
|
||||
|
||||
@@ -204,31 +204,32 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
case status.Created:
|
||||
case status.Deleting:
|
||||
case status.Deleted:
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
restoreReq := k8s.RestoreRequest{
|
||||
K8SID: id,
|
||||
}
|
||||
// id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
// restoreReq := k8s.RestoreRequest{
|
||||
// K8SID: id,
|
||||
// }
|
||||
|
||||
_, err := c.CloudAPI().K8S().Restore(ctx, restoreReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().K8S().Restore(ctx, restoreReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
enableReq := k8s.DisableEnableRequest{
|
||||
K8SID: id,
|
||||
}
|
||||
// enableReq := k8s.DisableEnableRequest{
|
||||
// K8SID: id,
|
||||
// }
|
||||
|
||||
_, err = c.CloudAPI().K8S().Enable(ctx, enableReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err = c.CloudAPI().K8S().Enable(ctx, enableReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
hasChanged = true
|
||||
// hasChanged = true
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The k8s cluster is in progress with status: %s", cluster.Status)
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceK8sCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceK8sCreate(ctx, d, m)
|
||||
case status.Enabling:
|
||||
case status.Enabled:
|
||||
case status.Disabling:
|
||||
@@ -387,7 +388,8 @@ func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
return diag.Errorf("The k8s cluster is in progress with status: %s", cluster.Status)
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceK8sCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceK8sCreate(ctx, d, m)
|
||||
case status.Enabling:
|
||||
case status.Enabled:
|
||||
case status.Disabling:
|
||||
|
||||
@@ -637,10 +637,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
// "custom_fields": {
|
||||
// Type: schema.TypeString,
|
||||
// Computed: true,
|
||||
// },
|
||||
"custom_fields": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -154,10 +154,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
// "custom_fields": { //NEED
|
||||
// Type: schema.TypeString,
|
||||
// Computed: true,
|
||||
// },
|
||||
"custom_fields": { //NEED
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -36,7 +36,6 @@ import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -151,7 +150,7 @@ func flattenListACL(listAcl compute.ListACL) []map[string]interface{} {
|
||||
func flattenComputeList(computes *compute.ListComputes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, compute := range computes.Data {
|
||||
// customFields, _ := json.Marshal(compute.CustomFields)
|
||||
customFields, _ := json.Marshal(compute.CustomFields)
|
||||
devices, _ := json.Marshal(compute.Devices)
|
||||
temp := map[string]interface{}{
|
||||
"acl": flattenListACL(compute.ACL),
|
||||
@@ -170,44 +169,44 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
|
||||
"cpus": compute.CPU,
|
||||
"created_by": compute.CreatedBy,
|
||||
"created_time": compute.CreatedTime,
|
||||
// "custom_fields": string(customFields),
|
||||
"deleted_by": compute.DeletedBy,
|
||||
"deleted_time": compute.DeletedTime,
|
||||
"desc": compute.Description,
|
||||
"devices": string(devices),
|
||||
"disks": flattenDisks(compute.Disks),
|
||||
"driver": compute.Driver,
|
||||
"gid": compute.GID,
|
||||
"guid": compute.GUID,
|
||||
"compute_id": compute.ID,
|
||||
"image_id": compute.ImageID,
|
||||
"interfaces": flattenInterfaces(compute.Interfaces),
|
||||
"lock_status": compute.LockStatus,
|
||||
"manager_id": compute.ManagerID,
|
||||
"manager_type": compute.ManagerType,
|
||||
"migrationjob": compute.MigrationJob,
|
||||
"milestones": compute.Milestones,
|
||||
"name": compute.Name,
|
||||
"pinned": compute.Pinned,
|
||||
"ram": compute.RAM,
|
||||
"reference_id": compute.ReferenceID,
|
||||
"registered": compute.Registered,
|
||||
"res_name": compute.ResName,
|
||||
"rg_id": compute.RGID,
|
||||
"rg_name": compute.RGName,
|
||||
"snap_sets": flattenSnapSets(compute.SnapSets),
|
||||
"stateless_sep_id": compute.StatelessSepID,
|
||||
"stateless_sep_type": compute.StatelessSepType,
|
||||
"status": compute.Status,
|
||||
"tags": flattenTags(compute.Tags),
|
||||
"tech_status": compute.TechStatus,
|
||||
"total_disk_size": compute.TotalDiskSize,
|
||||
"updated_by": compute.UpdatedBy,
|
||||
"updated_time": compute.UpdatedTime,
|
||||
"user_managed": compute.UserManaged,
|
||||
"vgpus": compute.VGPUs,
|
||||
"vins_connected": compute.VINSConnected,
|
||||
"virtual_image_id": compute.VirtualImageID,
|
||||
"custom_fields": string(customFields),
|
||||
"deleted_by": compute.DeletedBy,
|
||||
"deleted_time": compute.DeletedTime,
|
||||
"desc": compute.Description,
|
||||
"devices": string(devices),
|
||||
"disks": flattenDisks(compute.Disks),
|
||||
"driver": compute.Driver,
|
||||
"gid": compute.GID,
|
||||
"guid": compute.GUID,
|
||||
"compute_id": compute.ID,
|
||||
"image_id": compute.ImageID,
|
||||
"interfaces": flattenInterfaces(compute.Interfaces),
|
||||
"lock_status": compute.LockStatus,
|
||||
"manager_id": compute.ManagerID,
|
||||
"manager_type": compute.ManagerType,
|
||||
"migrationjob": compute.MigrationJob,
|
||||
"milestones": compute.Milestones,
|
||||
"name": compute.Name,
|
||||
"pinned": compute.Pinned,
|
||||
"ram": compute.RAM,
|
||||
"reference_id": compute.ReferenceID,
|
||||
"registered": compute.Registered,
|
||||
"res_name": compute.ResName,
|
||||
"rg_id": compute.RGID,
|
||||
"rg_name": compute.RGName,
|
||||
"snap_sets": flattenSnapSets(compute.SnapSets),
|
||||
"stateless_sep_id": compute.StatelessSepID,
|
||||
"stateless_sep_type": compute.StatelessSepType,
|
||||
"status": compute.Status,
|
||||
"tags": flattenTags(compute.Tags),
|
||||
"tech_status": compute.TechStatus,
|
||||
"total_disk_size": compute.TotalDiskSize,
|
||||
"updated_by": compute.UpdatedBy,
|
||||
"updated_time": compute.UpdatedTime,
|
||||
"user_managed": compute.UserManaged,
|
||||
"vgpus": compute.VGPUs,
|
||||
"vins_connected": compute.VINSConnected,
|
||||
"virtual_image_id": compute.VirtualImageID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -237,10 +236,10 @@ func flattenBootDisk(bootDisk *compute.ItemComputeDisk) []map[string]interface{}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []interface{}) []map[string]interface{} {
|
||||
func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []interface{}, bootDiskId uint64) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(disksList))
|
||||
for _, disk := range disksList {
|
||||
if strings.Contains(disk.Name, "bootdisk") || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
if disk.ID == bootDiskId || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
continue
|
||||
}
|
||||
temp := map[string]interface{}{
|
||||
@@ -261,6 +260,7 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []in
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ func flattenNetwork(interfaces compute.ListInterfaces) []map[string]interface{}
|
||||
|
||||
func findBootDisk(disks compute.ListComputeDisks) *compute.ItemComputeDisk {
|
||||
for _, disk := range disks {
|
||||
if strings.Contains(disk.Name, "bootdisk") {
|
||||
if disk.Type == "B" {
|
||||
return &disk
|
||||
}
|
||||
}
|
||||
@@ -301,7 +301,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) er
|
||||
|
||||
//check extraDisks, ipa_type, is,
|
||||
d.SetId(strconv.FormatUint(computeRec.ID, 10))
|
||||
d.Set("acl", flattenACL(computeRec.ACL))
|
||||
// d.Set("acl", flattenACL(computeRec.ACL))
|
||||
d.Set("account_id", computeRec.AccountID)
|
||||
d.Set("account_name", computeRec.AccountName)
|
||||
d.Set("affinity_weight", computeRec.AffinityWeight)
|
||||
@@ -317,11 +317,12 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) er
|
||||
d.Set("computeci_id", computeRec.ComputeCIID)
|
||||
d.Set("created_by", computeRec.CreatedBy)
|
||||
d.Set("created_time", computeRec.CreatedTime)
|
||||
// d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
|
||||
d.Set("deleted_by", computeRec.DeletedBy)
|
||||
d.Set("deleted_time", computeRec.DeletedTime)
|
||||
d.Set("description", computeRec.Description)
|
||||
d.Set("devices", string(devices))
|
||||
err := d.Set("disks", flattenComputeDisksDemo(computeRec.Disks, d.Get("extra_disks").(*schema.Set).List()))
|
||||
err := d.Set("disks", flattenComputeDisksDemo(computeRec.Disks, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -542,7 +543,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
|
||||
d.Set("cpus", computeRec.CPU)
|
||||
d.Set("created_by", computeRec.CreatedBy)
|
||||
d.Set("created_time", computeRec.CreatedTime)
|
||||
// d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
|
||||
d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
|
||||
d.Set("deleted_by", computeRec.DeletedBy)
|
||||
d.Set("deleted_time", computeRec.DeletedTime)
|
||||
d.Set("desc", computeRec.Description)
|
||||
|
||||
550
internal/service/cloudapi/kvmvm/old_schemas.go
Normal file
550
internal/service/cloudapi/kvmvm/old_schemas.go
Normal file
@@ -0,0 +1,550 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs"
|
||||
)
|
||||
|
||||
func resourceComputeResourceV1() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Name of this compute. Compute names are case sensitive and must be unique in the resource group.",
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
ValidateFunc: validation.IntAtLeast(1),
|
||||
Description: "ID of the resource group where this compute should be deployed.",
|
||||
},
|
||||
"driver": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
StateFunc: statefuncs.StateFuncToUpper,
|
||||
ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86", "KVM_PPC"}, false), // observe case while validating
|
||||
Description: "Hardware architecture of this compute instance.",
|
||||
},
|
||||
"cpu": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ValidateFunc: validation.IntBetween(1, constants.MaxCpusPerCompute),
|
||||
Description: "Number of CPUs to allocate to this compute instance.",
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ValidateFunc: validation.IntAtLeast(constants.MinRamPerCompute),
|
||||
Description: "Amount of RAM in MB to allocate to this compute instance.",
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
//ForceNew: true, //REDEPLOY
|
||||
Description: "ID of the OS image to base this compute instance on.",
|
||||
},
|
||||
"boot_disk_size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "This compute instance boot disk size in GB. Make sure it is large enough to accomodate selected OS image.",
|
||||
},
|
||||
"affinity_label": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Set affinity label for compute",
|
||||
},
|
||||
"affinity_rules": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"topology": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"node", "compute"}, false),
|
||||
Description: "compute or node, for whom rule applies",
|
||||
},
|
||||
"policy": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"RECOMMENDED", "REQUIRED"}, false),
|
||||
Description: "RECOMMENDED or REQUIRED, the degree of 'strictness' of this rule",
|
||||
},
|
||||
"mode": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"EQ", "NE", "ANY"}, false),
|
||||
Description: "EQ or NE or ANY - the comparison mode is 'value', recorded by the specified 'key'",
|
||||
},
|
||||
"key": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "key that are taken into account when analyzing this rule will be identified",
|
||||
},
|
||||
"value": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "value that must match the key to be taken into account when analyzing this rule",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"anti_affinity_rules": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"topology": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"node", "compute"}, false),
|
||||
Description: "compute or node, for whom rule applies",
|
||||
},
|
||||
"policy": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"RECOMMENDED", "REQUIRED"}, false),
|
||||
Description: "RECOMMENDED or REQUIRED, the degree of 'strictness' of this rule",
|
||||
},
|
||||
"mode": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"EQ", "NE", "ANY"}, false),
|
||||
Description: "EQ or NE or ANY - the comparison mode is 'value', recorded by the specified 'key'",
|
||||
},
|
||||
"key": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "key that are taken into account when analyzing this rule will be identified",
|
||||
},
|
||||
"value": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "value that must match the key to be taken into account when analyzing this rule",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"disks": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: disksSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
"custom_fields": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"key": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"val": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"stateless": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Compute will be stateless (SVA_KVM_X86) if set to True",
|
||||
},
|
||||
"with_default_vins": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "Create compute with default resgroup ViNS (true) or without any interfaces (false). This parameter is ignored if network block is specified",
|
||||
},
|
||||
"boot_disk": {
|
||||
Type: schema.TypeSet,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: disksSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
Description: "ID of SEP to create bootDisk on. Uses image's sepId if not set.",
|
||||
},
|
||||
"pool": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
Description: "Pool to use if sepId is set, can be also empty if needed to be chosen by system.",
|
||||
},
|
||||
|
||||
"extra_disks": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
MaxItems: constants.MaxExtraDisksPerCompute,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "Optional list of IDs of extra disks to attach to this compute. You may specify several extra disks.",
|
||||
},
|
||||
|
||||
"network": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
MinItems: 1,
|
||||
MaxItems: constants.MaxNetworksPerCompute,
|
||||
Elem: &schema.Resource{
|
||||
Schema: networkSubresourceSchemaMake(),
|
||||
},
|
||||
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
|
||||
},
|
||||
|
||||
"tags": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: tagsSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
|
||||
"port_forwarding": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: portForwardingSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
|
||||
"user_access": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: userAccessSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
|
||||
"snapshot": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: snapshotSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
|
||||
"rollback": {
|
||||
Type: schema.TypeSet,
|
||||
MaxItems: 1,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: snapshotRollbackSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
|
||||
"cd": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: cdSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
|
||||
"pin_to_stack": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
},
|
||||
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Optional text description of this compute instance.",
|
||||
},
|
||||
|
||||
"cloud_init": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Optional cloud_init parameters. Applied when creating new compute instance only, ignored in all other cases.",
|
||||
},
|
||||
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "If true - enable compute, else - disable",
|
||||
},
|
||||
|
||||
"pause": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
},
|
||||
|
||||
"reset": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
},
|
||||
|
||||
"auto_start": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Flag for redeploy compute",
|
||||
},
|
||||
"force_stop": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Flag for redeploy compute",
|
||||
},
|
||||
"data_disks": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"KEEP", "DETACH", "DESTROY"}, false),
|
||||
Default: "DETACH",
|
||||
Description: "Flag for redeploy compute",
|
||||
},
|
||||
"started": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "Is compute started.",
|
||||
},
|
||||
"detach_disks": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
},
|
||||
"is": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "system name",
|
||||
},
|
||||
"ipa_type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "compute purpose",
|
||||
},
|
||||
// The rest are Compute properties, which are "computed" once it is created
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of the account this compute instance belongs to.",
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the account this compute instance belongs to.",
|
||||
},
|
||||
"affinity_weight": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"arch": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"boot_order": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"boot_disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "This compute instance boot disk ID.",
|
||||
},
|
||||
"clone_reference": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"clones": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"computeci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"devices": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"interfaces": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: computeInterfacesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"lock_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"manager_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"manager_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"migrationjob": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"natable_vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"natable_vins_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"natable_vins_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"natable_vins_network": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"natable_vins_network_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"os_users": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: osUsersSubresourceSchemaMake(),
|
||||
},
|
||||
Description: "Guest OS users provisioned on this compute instance.",
|
||||
},
|
||||
"pinned": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"registered": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"res_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the resource group where this compute instance is located.",
|
||||
},
|
||||
"snap_sets": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: computeSnapSetsSchemaMake(),
|
||||
},
|
||||
},
|
||||
"stateless_sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"stateless_sep_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"user_managed": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"vgpus": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"virtual_image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"virtual_image_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -192,6 +192,16 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
|
||||
createReqX86.Driver = driver
|
||||
|
||||
if custom_fields, ok := d.GetOk("custom_fields"); ok {
|
||||
val := custom_fields.(string)
|
||||
val = strings.ReplaceAll(val, "\\", "")
|
||||
val = strings.ReplaceAll(val, "\n", "")
|
||||
val = strings.ReplaceAll(val, "\t", "")
|
||||
val = strings.TrimSpace(val)
|
||||
|
||||
createReqX86.CustomFields = val
|
||||
}
|
||||
|
||||
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
|
||||
apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86)
|
||||
if err != nil {
|
||||
@@ -226,7 +236,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
argVal, ok = d.GetOk("extra_disks")
|
||||
if ok && argVal.(*schema.Set).Len() > 0 {
|
||||
log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len())
|
||||
err = utilityComputeExtraDisksConfigure(ctx, d, m, false)
|
||||
err = utilityComputeExtraDisksConfigure(ctx, d, m, false, nil)
|
||||
if err != nil {
|
||||
log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", computeId, err)
|
||||
cleanup = true
|
||||
@@ -247,13 +257,13 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if enabled, ok := d.GetOk("enabled"); ok {
|
||||
if enabled.(bool) {
|
||||
req := compute.EnableRequest{ComputeID: computeId}
|
||||
log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", computeId, enabled)
|
||||
log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", enabled, computeId)
|
||||
if _, err := c.CloudAPI().Compute().Enable(ctx, req); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
} else {
|
||||
req := compute.DisableRequest{ComputeID: computeId}
|
||||
log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", computeId, enabled)
|
||||
log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", enabled, computeId)
|
||||
if _, err := c.CloudAPI().Compute().Disable(ctx, req); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -486,7 +496,7 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
log.Debugf("resourceComputeRead: called for Compute name %s, RG ID %d",
|
||||
d.Get("name").(string), d.Get("rg_id").(int))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
// c := m.(*controller.ControllerCfg)
|
||||
|
||||
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
@@ -497,23 +507,24 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
|
||||
switch computeRec.Status {
|
||||
case status.Deleted:
|
||||
restoreReq := compute.RestoreRequest{ComputeID: computeRec.ID}
|
||||
enableReq := compute.EnableRequest{ComputeID: computeRec.ID}
|
||||
// restoreReq := compute.RestoreRequest{ComputeID: computeRec.ID}
|
||||
// enableReq := compute.EnableRequest{ComputeID: computeRec.ID}
|
||||
|
||||
_, err := c.CloudAPI().Compute().Restore(ctx, restoreReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().Compute().Restore(ctx, restoreReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
_, err = c.CloudAPI().Compute().Enable(ctx, enableReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err = c.CloudAPI().Compute().Enable(ctx, enableReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
hasChanged = true
|
||||
// hasChanged = true
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceComputeCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceComputeCreate(ctx, d, m)
|
||||
case status.Disabled:
|
||||
log.Debugf("The compute is in status: %s, troubles may occur with update. Please, enable compute first.", computeRec.Status)
|
||||
case status.Redeploying:
|
||||
@@ -574,11 +585,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
switch networkData["net_type"].(string) {
|
||||
case "VINS":
|
||||
if vinsId, ok := existVinsId(ctx, m, networkData["net_id"].(int)); !ok {
|
||||
return diag.Errorf("resourceComputeCreate: can't create compute because vins ID %d is not allowed or does not exist", vinsId)
|
||||
return diag.Errorf("resourceComputeCreate: can't update compute because vins ID %d is not allowed or does not exist", vinsId)
|
||||
}
|
||||
case "EXTNET":
|
||||
if extNetId, ok := existExtNetId(ctx, m, networkData["net_id"].(int)); !ok {
|
||||
return diag.Errorf("resourceComputeCreate: can't create compute because extnet ID %d is not allowed or does not exist", extNetId)
|
||||
return diag.Errorf("resourceComputeCreate: can't update compute because extnet ID %d is not allowed or does not exist", extNetId)
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -632,7 +643,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceComputeCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceComputeCreate(ctx, d, m)
|
||||
case status.Disabled:
|
||||
log.Debugf("The compute is in status: %s, may troubles can be occured with update. Please, enable compute first.", computeRec.Status)
|
||||
case status.Redeploying:
|
||||
@@ -706,7 +718,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
|
||||
if d.HasChange("extra_disks") {
|
||||
err := utilityComputeExtraDisksConfigure(ctx, d, m, true) // pass do_delta = true to apply changes, if any
|
||||
err := utilityComputeExtraDisksConfigure(ctx, d, m, true, computeRec.Disks) // pass do_delta = true to apply changes, if any
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -745,7 +757,23 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
|
||||
for _, el := range oldConv {
|
||||
if !isContainsDisk(newConv, el) {
|
||||
deletedDisks = append(deletedDisks, el)
|
||||
flag := false
|
||||
extraDisks := d.Get("extra_disks").(*schema.Set).List()
|
||||
delDisk := el.(map[string]interface{})
|
||||
delDiskId := delDisk["disk_id"].(int)
|
||||
|
||||
for _, extraDiskId := range extraDisks {
|
||||
if extraDiskId.(int) == delDiskId {
|
||||
flag = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !flag {
|
||||
deletedDisks = append(deletedDisks, el)
|
||||
} else {
|
||||
log.Debugf("disk %d will not be deleted because it is present in the extra_disks block", delDiskId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -772,7 +800,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
|
||||
for _, disk := range deletedDisks {
|
||||
diskConv := disk.(map[string]interface{})
|
||||
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") {
|
||||
if diskConv["disk_type"].(string) == "B" {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -782,6 +810,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
Permanently: diskConv["permanently"].(bool),
|
||||
}
|
||||
|
||||
log.Debugf("trying to delete disk %d", req.DiskID)
|
||||
|
||||
_, err := c.CloudAPI().Compute().DiskDel(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -800,7 +830,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if len(addedDisks) > 0 {
|
||||
for _, disk := range addedDisks {
|
||||
diskConv := disk.(map[string]interface{})
|
||||
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") {
|
||||
if diskConv["disk_type"].(string) == "B" {
|
||||
continue
|
||||
}
|
||||
req := compute.DiskAddRequest{
|
||||
@@ -832,7 +862,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if len(updatedDisks) > 0 {
|
||||
for _, disk := range updatedDisks {
|
||||
diskConv := disk.(map[string]interface{})
|
||||
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") {
|
||||
if diskConv["disk_type"].(string) == "B" {
|
||||
continue
|
||||
}
|
||||
req := compute.DiskResizeRequest{
|
||||
@@ -1335,6 +1365,35 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("custom_fields") {
|
||||
val := d.Get("custom_fields").(string)
|
||||
val = strings.ReplaceAll(val, "\\", "")
|
||||
val = strings.ReplaceAll(val, "\n", "")
|
||||
val = strings.ReplaceAll(val, "\t", "")
|
||||
val = strings.TrimSpace(val)
|
||||
|
||||
if len(val) > 0 {
|
||||
req := compute.SetCustomFieldsRequest{
|
||||
ComputeID: computeRec.ID,
|
||||
CustomFields: val,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().SetCustomFields(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
req := compute.DeleteCustomFieldsRequest{
|
||||
ComputeID: computeRec.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().DeleteCustomFields(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we may reuse dataSourceComputeRead here as we maintain similarity
|
||||
// between Compute resource and Compute data source schemas
|
||||
defer resourceComputeRead(ctx, d, m)
|
||||
@@ -1678,6 +1737,11 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Schema: disksSubresourceSchemaMake(),
|
||||
},
|
||||
},
|
||||
"custom_fields": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"stateless": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
@@ -1715,6 +1779,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
"extra_disks": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MaxItems: constants.MaxExtraDisksPerCompute,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
@@ -2075,7 +2140,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
|
||||
func ResourceCompute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
SchemaVersion: 2,
|
||||
|
||||
CreateContext: resourceComputeCreate,
|
||||
ReadContext: resourceComputeRead,
|
||||
@@ -2095,5 +2160,12 @@ func ResourceCompute() *schema.Resource {
|
||||
},
|
||||
|
||||
Schema: ResourceComputeSchemaMake(),
|
||||
StateUpgraders: []schema.StateUpgrader{
|
||||
{
|
||||
Type: resourceComputeResourceV1().CoreConfigSchema().ImpliedType(),
|
||||
Upgrade: resourceCompueteStateUpgradeV1,
|
||||
Version: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
33
internal/service/cloudapi/kvmvm/state_upgraders.go
Normal file
33
internal/service/cloudapi/kvmvm/state_upgraders.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceCompueteStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
|
||||
log.Debug("resourceCompueteStateUpgradeV1: upgrading state")
|
||||
customFields, ok := rawState["custom_fields"]
|
||||
if !ok || customFields == nil {
|
||||
rawState["custom_fields"] = "{}"
|
||||
return rawState, nil
|
||||
}
|
||||
|
||||
b := &strings.Builder{}
|
||||
b.WriteString("{")
|
||||
oldCustomFieldsSlice := customFields.([]interface{})
|
||||
for i := range oldCustomFieldsSlice {
|
||||
oldCustomFields := oldCustomFieldsSlice[i].(map[string]interface{})
|
||||
b.WriteString(fmt.Sprintf(`"%s":"%s"`, oldCustomFields["key"], oldCustomFields["val"]))
|
||||
if i < len(oldCustomFieldsSlice)-1 {
|
||||
b.WriteString(",")
|
||||
}
|
||||
}
|
||||
b.WriteString("}")
|
||||
rawState["custom_fields"] = b.String()
|
||||
|
||||
return rawState, nil
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func matchComputes(computeList *compute.ListComputes) *compute.ListComputes {
|
||||
return &result
|
||||
}
|
||||
|
||||
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
|
||||
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool, disks compute.ListComputeDisks) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
log.Debugf("utilityComputeExtraDisksConfigure: called for Compute ID %s with do_delta = %t", d.Id(), do_delta)
|
||||
@@ -138,6 +138,22 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
||||
DiskID: uint64(diskId.(int)),
|
||||
}
|
||||
|
||||
log.Debug("before attach HERE0")
|
||||
|
||||
flag := false
|
||||
|
||||
// check if there is an extra disk in the disks from the platform, so as not to attach it if it is already attached
|
||||
for _, elem := range disks {
|
||||
if elem.ID == uint64(diskId.(int)) {
|
||||
flag = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if flag {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().DiskAttach(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||
@@ -165,6 +181,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
Force: true,
|
||||
}
|
||||
|
||||
log.Debugf("utilityComputeNetworksConfigure: stopping compute %d", computeID)
|
||||
_, err := c.CloudAPI().Compute().Stop(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -255,6 +272,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
|
||||
startReq := compute.StartRequest{ComputeID: computeID}
|
||||
|
||||
log.Debugf("utilityComputeNetworksConfigure: starting compute %d", computeID)
|
||||
_, err = c.CloudAPI().Compute().Start(ctx, startReq)
|
||||
if err != nil {
|
||||
apiErrCount++
|
||||
@@ -279,7 +297,7 @@ func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m
|
||||
|
||||
computeRecord, err := c.CloudAPI().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return *computeRecord, err
|
||||
return compute.RecordCompute{}, err
|
||||
}
|
||||
|
||||
return *computeRecord, nil
|
||||
|
||||
@@ -128,7 +128,7 @@ func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBRead")
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
// c := m.(*controller.ControllerCfg)
|
||||
|
||||
lbRec, err := utilityLBCheckPresence(ctx, d, m)
|
||||
if lbRec == nil {
|
||||
@@ -145,25 +145,26 @@ func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{})
|
||||
case status.Created:
|
||||
case status.Deleting:
|
||||
case status.Deleted:
|
||||
lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
restoreReq := lb.RestoreRequest{LBID: lbId}
|
||||
enableReq := lb.DisableEnableRequest{LBID: lbId}
|
||||
// lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
// restoreReq := lb.RestoreRequest{LBID: lbId}
|
||||
// enableReq := lb.DisableEnableRequest{LBID: lbId}
|
||||
|
||||
_, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
_, err = c.CloudAPI().LB().Enable(ctx, enableReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
// _, err = c.CloudAPI().LB().Enable(ctx, enableReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
hasChanged = true
|
||||
// hasChanged = true
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceLBCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceLBCreate(ctx, d, m)
|
||||
case status.Enabled:
|
||||
case status.Enabling:
|
||||
case status.Disabling:
|
||||
@@ -276,7 +277,8 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceLBCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceLBCreate(ctx, d, m)
|
||||
case status.Enabled:
|
||||
case status.Enabling:
|
||||
case status.Disabling:
|
||||
|
||||
@@ -256,7 +256,7 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
log.Debugf("resourceResgroupRead: called for RG name %s, account ID %d",
|
||||
d.Get("name").(string), d.Get("account_id").(int))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
// c := m.(*controller.ControllerCfg)
|
||||
|
||||
rgData, err := utilityResgroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
@@ -272,24 +272,25 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
case status.Created:
|
||||
case status.Enabled:
|
||||
case status.Deleted:
|
||||
restoreReq := rg.RestoreRequest{RGID: rgData.ID}
|
||||
enableReq := rg.EnableRequest{RGID: rgData.ID}
|
||||
// restoreReq := rg.RestoreRequest{RGID: rgData.ID}
|
||||
// enableReq := rg.EnableRequest{RGID: rgData.ID}
|
||||
|
||||
_, err := c.CloudAPI().RG().Restore(ctx, restoreReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().RG().Restore(ctx, restoreReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
_, err = c.CloudAPI().RG().Enable(ctx, enableReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// _, err = c.CloudAPI().RG().Enable(ctx, enableReq)
|
||||
// if err != nil {
|
||||
// return diag.FromErr(err)
|
||||
// }
|
||||
|
||||
hasChanged = true
|
||||
// hasChanged = true
|
||||
case status.Deleting:
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceResgroupCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceResgroupCreate(ctx, d, m)
|
||||
case status.Destroying:
|
||||
case status.Disabled:
|
||||
case status.Disabling:
|
||||
@@ -369,7 +370,8 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
|
||||
case status.Deleting:
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceResgroupCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceResgroupCreate(ctx, d, m)
|
||||
case status.Destroying:
|
||||
case status.Disabled:
|
||||
case status.Disabling:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -34,8 +34,8 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
@@ -47,8 +47,9 @@ func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(vins.ID, 10))
|
||||
flattenVinsData(d, *vins)
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
flattenVinsData(d, vins)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -640,7 +641,7 @@ func rulesSchemaMake() map[string]*schema.Schema {
|
||||
}
|
||||
}
|
||||
|
||||
func configSchrmaMake() map[string]*schema.Schema {
|
||||
func natConfigSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"net_mask": {
|
||||
Type: schema.TypeInt,
|
||||
@@ -678,7 +679,7 @@ func natSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: configSchrmaMake(),
|
||||
Schema: natConfigSchemaMake(),
|
||||
},
|
||||
},
|
||||
"devices": {
|
||||
@@ -768,7 +769,6 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
Required: true,
|
||||
Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.",
|
||||
},
|
||||
|
||||
"vnf_dev": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
@@ -776,10 +776,6 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
Schema: vnfDevSchemaMake(),
|
||||
},
|
||||
},
|
||||
"_ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -797,6 +793,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
Schema: vinsComputeSchemaMake(),
|
||||
},
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"default_gw": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -808,6 +812,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
Schema: qosSchemaMake(),
|
||||
},
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -874,6 +886,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
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,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -49,7 +49,7 @@ func dataSourceVinsExtNetListRead(ctx context.Context, d *schema.ResourceData, m
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsExtNetList(extNetList))
|
||||
|
||||
d.Set("entry_count", extNetList.EntryCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -92,6 +92,10 @@ func DataSourceVinsExtNetListchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -49,7 +49,7 @@ func dataSourceVinsIpListRead(ctx context.Context, d *schema.ResourceData, m int
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsIpList(ips))
|
||||
|
||||
d.Set("entry_count", ips.EntryCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -96,6 +96,10 @@ func DataSourceVinsIpListSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -49,6 +49,8 @@ func dataSourceVinsNatRuleListRead(ctx context.Context, d *schema.ResourceData,
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsNatRuleList(natRules))
|
||||
d.Set("entry_count", natRules.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -99,6 +101,10 @@ func DataSourceVinsNatRuleListSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -49,7 +49,7 @@ func flattenMGMT(mgmt vins.RecordMGMT) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenResources(resources *vins.RecordResources) []map[string]interface{} {
|
||||
func flattenResources(resources vins.RecordResources) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": resources.CPU,
|
||||
@@ -65,7 +65,7 @@ func flattenConfig(config vins.RecordVNFConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"mgmt": flattenMGMT(config.MGMT),
|
||||
"resources": flattenResources(&config.Resources),
|
||||
"resources": flattenResources(config.Resources),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
@@ -84,8 +84,7 @@ func flattenQOS(qos vins.QOS) []map[string]interface{} {
|
||||
}
|
||||
|
||||
func flattenInterfaces(interfaces []vins.ItemVNFInterface) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
|
||||
res := make([]map[string]interface{}, 0, len(interfaces))
|
||||
for _, vnfInterface := range interfaces {
|
||||
temp := map[string]interface{}{
|
||||
"conn_id": vnfInterface.ConnID,
|
||||
@@ -141,7 +140,7 @@ func flattenVNFDev(vnfDev vins.RecordVNFDev) []map[string]interface{} {
|
||||
}
|
||||
|
||||
func flattenComputes(computes vins.ListVINSComputes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(computes))
|
||||
for _, compute := range computes {
|
||||
temp := map[string]interface{}{
|
||||
"compute_id": compute.ID,
|
||||
@@ -154,7 +153,7 @@ func flattenComputes(computes vins.ListVINSComputes) []map[string]interface{} {
|
||||
}
|
||||
|
||||
func flattenReservations(reservations vins.ListReservations) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(reservations))
|
||||
for _, reservation := range reservations {
|
||||
temp := map[string]interface{}{
|
||||
"client_type": reservation.ClientType,
|
||||
@@ -275,9 +274,9 @@ func flattenGW(gw vins.RecordGW) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRules(rules vins.ListNATRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rule := range rules.Data {
|
||||
func flattenRules(rules vins.ListNATRulesConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(rules))
|
||||
for _, rule := range rules {
|
||||
tmp := map[string]interface{}{
|
||||
"rule_id": rule.ID,
|
||||
"local_ip": rule.LocalIP,
|
||||
@@ -343,9 +342,9 @@ func flattenVNFS(vnfs vins.RecordVNFs) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rule := range rules.Data {
|
||||
func flattenRuleBlock(rules vins.ListNATRulesConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(rules))
|
||||
for _, rule := range rules {
|
||||
tmp := map[string]interface{}{
|
||||
"int_ip": rule.LocalIP,
|
||||
"int_port": rule.LocalPort,
|
||||
@@ -359,15 +358,18 @@ func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVins(d *schema.ResourceData, vins vins.RecordVINS) {
|
||||
func flattenVins(d *schema.ResourceData, vins *vins.RecordVINS) {
|
||||
d.Set("vins_id", vins.ID)
|
||||
d.Set("vnf_dev", flattenVNFDev(vins.VNFDev))
|
||||
d.Set("_ckey", vins.CKey)
|
||||
d.Set("account_id", vins.AccountID)
|
||||
d.Set("account_name", vins.AccountName)
|
||||
d.Set("computes", flattenComputes(vins.Computes))
|
||||
d.Set("created_by", vins.CreatedBy)
|
||||
d.Set("created_time", vins.CreatedTime)
|
||||
d.Set("default_gw", vins.DefaultGW)
|
||||
d.Set("default_qos", flattenQOS(vins.DefaultQOS))
|
||||
d.Set("deleted_by", vins.DeletedBy)
|
||||
d.Set("deleted_time", vins.DeletedTime)
|
||||
d.Set("desc", vins.Description)
|
||||
d.Set("gid", vins.GID)
|
||||
d.Set("guid", vins.GUID)
|
||||
@@ -384,21 +386,26 @@ func flattenVins(d *schema.ResourceData, vins vins.RecordVINS) {
|
||||
d.Set("rg_name", vins.RGName)
|
||||
d.Set("sec_vnf_dev_id", vins.SecVNFDevID)
|
||||
d.Set("status", vins.Status)
|
||||
d.Set("updated_by", vins.UpdatedBy)
|
||||
d.Set("updated_time", vins.UpdatedTime)
|
||||
d.Set("user_managed", vins.UserManaged)
|
||||
d.Set("vnfs", flattenVNFS(vins.VNFs))
|
||||
d.Set("vxlan_id", vins.VXLANID)
|
||||
d.Set("nat_rule", flattenRuleBlock(vins.VNFs.NAT.Config.Rules))
|
||||
}
|
||||
|
||||
func flattenVinsData(d *schema.ResourceData, vins vins.RecordVINS) {
|
||||
func flattenVinsData(d *schema.ResourceData, vins *vins.RecordVINS) {
|
||||
d.Set("vins_id", vins.ID)
|
||||
d.Set("vnf_dev", flattenVNFDev(vins.VNFDev))
|
||||
d.Set("_ckey", vins.CKey)
|
||||
d.Set("account_id", vins.AccountID)
|
||||
d.Set("account_name", vins.AccountName)
|
||||
d.Set("computes", flattenComputes(vins.Computes))
|
||||
d.Set("created_by", vins.CreatedBy)
|
||||
d.Set("created_time", vins.CreatedTime)
|
||||
d.Set("default_gw", vins.DefaultGW)
|
||||
d.Set("default_qos", flattenQOS(vins.DefaultQOS))
|
||||
d.Set("deleted_by", vins.DeletedBy)
|
||||
d.Set("deleted_time", vins.DeletedTime)
|
||||
d.Set("desc", vins.Description)
|
||||
d.Set("gid", vins.GID)
|
||||
d.Set("guid", vins.GUID)
|
||||
@@ -415,14 +422,16 @@ func flattenVinsData(d *schema.ResourceData, vins vins.RecordVINS) {
|
||||
d.Set("rg_name", vins.RGName)
|
||||
d.Set("sec_vnf_dev_id", vins.SecVNFDevID)
|
||||
d.Set("status", vins.Status)
|
||||
d.Set("updated_by", vins.UpdatedBy)
|
||||
d.Set("updated_time", vins.UpdatedTime)
|
||||
d.Set("user_managed", vins.UserManaged)
|
||||
d.Set("vnfs", flattenVNFS(vins.VNFs))
|
||||
d.Set("vxlan_id", vins.VXLANID)
|
||||
}
|
||||
|
||||
func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, audit := range auidts {
|
||||
func flattenVinsAudits(audits vins.ListAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(audits))
|
||||
for _, audit := range audits {
|
||||
temp := map[string]interface{}{
|
||||
"call": audit.Call,
|
||||
"response_time": audit.ResponseTime,
|
||||
@@ -437,7 +446,7 @@ func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} {
|
||||
}
|
||||
|
||||
func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(extNetList.Data))
|
||||
for _, extNet := range extNetList.Data {
|
||||
temp := map[string]interface{}{
|
||||
"default_gw": extNet.DefaultGW,
|
||||
@@ -454,7 +463,7 @@ func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{
|
||||
}
|
||||
|
||||
func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(ips.Data))
|
||||
for _, ip := range ips.Data {
|
||||
temp := map[string]interface{}{
|
||||
"client_type": ip.ClientType,
|
||||
@@ -472,7 +481,7 @@ func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} {
|
||||
}
|
||||
|
||||
func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(vl.Data))
|
||||
for _, v := range vl.Data {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": v.AccountID,
|
||||
@@ -498,7 +507,7 @@ func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
|
||||
}
|
||||
|
||||
func flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(natRules.Data))
|
||||
for _, natRule := range natRules.Data {
|
||||
temp := map[string]interface{}{
|
||||
"id": natRule.ID,
|
||||
|
||||
@@ -129,8 +129,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
if desc, ok := d.GetOk("desc"); ok {
|
||||
req.Description = desc.(string)
|
||||
}
|
||||
req.PreReservationsNum = uint(d.Get("pre_reservations_num").(int))
|
||||
|
||||
if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok {
|
||||
req.PreReservationsNum = uint64(preReservationsNum.(int))
|
||||
}
|
||||
|
||||
id, err := c.CloudAPI().VINS().CreateInRG(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -141,7 +143,6 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
req := vins.CreateInAccountRequest{
|
||||
Name: d.Get("name").(string),
|
||||
AccountID: uint64(accountId.(int)),
|
||||
PreReservationsNum: uint64(d.Get("pre_reservations_num").(int)),
|
||||
}
|
||||
|
||||
if gid, ok := d.GetOk("gid"); ok {
|
||||
@@ -153,7 +154,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
if desc, ok := d.GetOk("desc"); ok {
|
||||
req.Description = desc.(string)
|
||||
}
|
||||
|
||||
if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok {
|
||||
req.PreReservationsNum = uint64(preReservationsNum.(int))
|
||||
}
|
||||
|
||||
id, err := c.CloudAPI().VINS().CreateInAccount(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -214,15 +218,15 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
defer resourceVinsRead(ctx, d, m)
|
||||
return warnings.Get()
|
||||
|
||||
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
vinsData, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
vinsData, err := utilityDataVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
@@ -236,18 +240,19 @@ func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
case status.Destroyed:
|
||||
d.Set("vins_id", 0)
|
||||
d.SetId("")
|
||||
return resourceVinsCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceVinsCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
// hasChangeState = true
|
||||
|
||||
req := vins.RestoreRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
// req := vins.RestoreRequest{
|
||||
// VINSID: vinsData.ID,
|
||||
// }
|
||||
|
||||
_, err := c.CloudAPI().VINS().Restore(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
// _, err := c.CloudAPI().VINS().Restore(ctx, req)
|
||||
// if err != nil {
|
||||
// warnings.Add(err)
|
||||
// }
|
||||
case status.Modeled:
|
||||
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vinsData.Status)
|
||||
case status.Created:
|
||||
@@ -282,14 +287,14 @@ func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
}
|
||||
|
||||
if hasChangeState {
|
||||
vinsData, err = utilityVinsCheckPresence(ctx, d, m)
|
||||
vinsData, err = utilityDataVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
flattenVins(d, *vinsData)
|
||||
flattenVins(d, vinsData)
|
||||
|
||||
return warnings.Get()
|
||||
}
|
||||
@@ -366,7 +371,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
vinsData, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
vinsData, err := utilityDataVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
@@ -379,7 +384,8 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
switch vinsData.Status {
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceVinsCreate(ctx, d, m)
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceVinsCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
|
||||
@@ -425,7 +431,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
|
||||
if hasChangeState {
|
||||
vinsData, err = utilityVinsCheckPresence(ctx, d, m)
|
||||
vinsData, err = utilityDataVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
@@ -631,8 +637,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
defer resourceVinsRead(ctx, d, m)
|
||||
return warnings.Get()
|
||||
return append (warnings.Get(), resourceVinsRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
@@ -658,7 +663,7 @@ func extNetSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"ext_net_id": {
|
||||
Type: schema.TypeInt,
|
||||
Default: 0,
|
||||
Default: -1,
|
||||
Optional: true,
|
||||
},
|
||||
"ext_net_ip": {
|
||||
@@ -674,6 +679,7 @@ func ipSchemaMake() map[string]*schema.Schema {
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string {"DHCP", "VIP", "EXCLUDE"}, false),
|
||||
},
|
||||
"ip_addr": {
|
||||
Type: schema.TypeString,
|
||||
@@ -823,7 +829,6 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
Optional: true,
|
||||
Default: false,
|
||||
}
|
||||
|
||||
rets["vins_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -44,8 +44,13 @@ import (
|
||||
|
||||
func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.GetRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
req := vins.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
vins, err := c.CloudAPI().VINS().Get(ctx, req)
|
||||
@@ -56,17 +61,3 @@ func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m
|
||||
return vins, nil
|
||||
}
|
||||
|
||||
func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := vins.GetRequest{
|
||||
VINSID: vinsId,
|
||||
}
|
||||
|
||||
vins, err := c.CloudAPI().VINS().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return vins, nil
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -34,6 +34,7 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
@@ -42,8 +43,13 @@ import (
|
||||
|
||||
func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListAudits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.AuditsRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
req := vins.AuditsRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
audits, err := c.CloudAPI().VINS().Audits(ctx, req)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -34,6 +34,7 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
@@ -46,6 +47,13 @@ func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceD
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
extNetList, err := c.CloudAPI().VINS().ExtNetList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -34,6 +34,7 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
@@ -42,8 +43,13 @@ import (
|
||||
|
||||
func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListIPs, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.IPListRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
req := vins.IPListRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
ips, err := c.CloudAPI().VINS().IPList(ctx, req)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -34,6 +34,7 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
@@ -42,8 +43,13 @@ import (
|
||||
|
||||
func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListNATRules, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.NATRuleListRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
req := vins.NATRuleListRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
natRuleList, err := c.CloudAPI().VINS().NATRuleList(ctx, req)
|
||||
|
||||
@@ -142,6 +142,17 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
}
|
||||
}
|
||||
|
||||
if d.Get("enable").(bool) {
|
||||
log.Debugf("resourceExtnetCreate: trying to enable extnet with ID %d", netID)
|
||||
_, err := c.CloudBroker().ExtNet().Enable(ctx, extnet.EnableRequest{
|
||||
NetID: netID,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceExtnetRead(ctx, d, m)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user