Compare commits

...

6 Commits
4.3.2 ... 4.3.7

Author SHA1 Message Date
Nikita Sorokin
c89574c3e6 4.3.7 2023-09-22 12:49:22 +03:00
Nikita Sorokin
a1e61674c8 4.3.6 2023-09-04 11:15:01 +03:00
Nikita Sorokin
cb9ff26bb0 4.3.5 2023-08-29 16:26:37 +03:00
Nikita Sorokin
6932f9d305 4.3.5 2023-08-28 13:02:41 +03:00
Nikita Sorokin
712f8edf9e 4.3.4 2023-08-23 16:32:48 +03:00
Nikita Sorokin
805ffe1f29 4.3.3 2023-08-22 13:15:17 +03:00
30 changed files with 912 additions and 166 deletions

2
.gitignore vendored
View File

@@ -3,3 +3,5 @@ examples/
url_scrapping/ url_scrapping/
terraform-provider-decort* terraform-provider-decort*
.vscode/ .vscode/
.DS_Store

View File

@@ -1,5 +1,6 @@
## Version 4.3.2 ## Version 4.3.7
## Bugfix
- Fixed bug with get request. Update cloudapi/vins
- Updated decort-golang-sdk version
## Bugfixes
- Fixed bootdisk flattens
- Updated golang-decort-sdk version with fixed permamently field in cloudapi/cloudbroker/compute/diskDel

View File

@@ -7,11 +7,8 @@ ZIPDIR = ./zip
BINARY=${NAME} BINARY=${NAME}
WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH} WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH}
MAINPATH = ./cmd/decort/ MAINPATH = ./cmd/decort/
VERSION=4.3.2 VERSION=4.3.7
OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) 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\ FILES = ${BINARY}_${VERSION}_darwin_amd64\
${BINARY}_${VERSION}_darwin_arm64\ ${BINARY}_${VERSION}_darwin_arm64\

2
go.mod
View File

@@ -9,7 +9,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.0
golang.org/x/net v0.12.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.8
) )
require ( require (

4
go.sum
View File

@@ -339,5 +339,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3 h1:Rt5tE4EZcUr4ONK9u/XYe2mG1CC37xLUnNuCLYKDwYs= repository.basistech.ru/BASIS/decort-golang-sdk v1.5.8 h1:NQ9cEZmWhqXzG3Gxsh0zkQjnqR/HI7JWbN9+EOqGUnE=
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE= repository.basistech.ru/BASIS/decort-golang-sdk v1.5.8/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE=

View File

@@ -271,7 +271,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
Size: uint64(newSize.(int)), Size: uint64(newSize.(int)),
} }
_, err := c.CloudAPI().Disks().Resize(ctx, req) _, err := c.CloudAPI().Disks().Resize2(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -637,10 +637,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
// "custom_fields": { "custom_fields": {
// Type: schema.TypeString, Type: schema.TypeString,
// Computed: true, Computed: true,
// }, },
"deleted_by": { "deleted_by": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

View File

@@ -154,10 +154,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
// "custom_fields": { //NEED "custom_fields": { //NEED
// Type: schema.TypeString, Type: schema.TypeString,
// Computed: true, Computed: true,
// }, },
"deleted_by": { "deleted_by": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

View File

@@ -36,7 +36,6 @@ import (
"encoding/json" "encoding/json"
"sort" "sort"
"strconv" "strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus" 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{} { func flattenComputeList(computes *compute.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, compute := range computes.Data { for _, compute := range computes.Data {
// customFields, _ := json.Marshal(compute.CustomFields) customFields, _ := json.Marshal(compute.CustomFields)
devices, _ := json.Marshal(compute.Devices) devices, _ := json.Marshal(compute.Devices)
temp := map[string]interface{}{ temp := map[string]interface{}{
"acl": flattenListACL(compute.ACL), "acl": flattenListACL(compute.ACL),
@@ -170,44 +169,44 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"cpus": compute.CPU, "cpus": compute.CPU,
"created_by": compute.CreatedBy, "created_by": compute.CreatedBy,
"created_time": compute.CreatedTime, "created_time": compute.CreatedTime,
// "custom_fields": string(customFields), "custom_fields": string(customFields),
"deleted_by": compute.DeletedBy, "deleted_by": compute.DeletedBy,
"deleted_time": compute.DeletedTime, "deleted_time": compute.DeletedTime,
"desc": compute.Description, "desc": compute.Description,
"devices": string(devices), "devices": string(devices),
"disks": flattenDisks(compute.Disks), "disks": flattenDisks(compute.Disks),
"driver": compute.Driver, "driver": compute.Driver,
"gid": compute.GID, "gid": compute.GID,
"guid": compute.GUID, "guid": compute.GUID,
"compute_id": compute.ID, "compute_id": compute.ID,
"image_id": compute.ImageID, "image_id": compute.ImageID,
"interfaces": flattenInterfaces(compute.Interfaces), "interfaces": flattenInterfaces(compute.Interfaces),
"lock_status": compute.LockStatus, "lock_status": compute.LockStatus,
"manager_id": compute.ManagerID, "manager_id": compute.ManagerID,
"manager_type": compute.ManagerType, "manager_type": compute.ManagerType,
"migrationjob": compute.MigrationJob, "migrationjob": compute.MigrationJob,
"milestones": compute.Milestones, "milestones": compute.Milestones,
"name": compute.Name, "name": compute.Name,
"pinned": compute.Pinned, "pinned": compute.Pinned,
"ram": compute.RAM, "ram": compute.RAM,
"reference_id": compute.ReferenceID, "reference_id": compute.ReferenceID,
"registered": compute.Registered, "registered": compute.Registered,
"res_name": compute.ResName, "res_name": compute.ResName,
"rg_id": compute.RGID, "rg_id": compute.RGID,
"rg_name": compute.RGName, "rg_name": compute.RGName,
"snap_sets": flattenSnapSets(compute.SnapSets), "snap_sets": flattenSnapSets(compute.SnapSets),
"stateless_sep_id": compute.StatelessSepID, "stateless_sep_id": compute.StatelessSepID,
"stateless_sep_type": compute.StatelessSepType, "stateless_sep_type": compute.StatelessSepType,
"status": compute.Status, "status": compute.Status,
"tags": flattenTags(compute.Tags), "tags": flattenTags(compute.Tags),
"tech_status": compute.TechStatus, "tech_status": compute.TechStatus,
"total_disk_size": compute.TotalDiskSize, "total_disk_size": compute.TotalDiskSize,
"updated_by": compute.UpdatedBy, "updated_by": compute.UpdatedBy,
"updated_time": compute.UpdatedTime, "updated_time": compute.UpdatedTime,
"user_managed": compute.UserManaged, "user_managed": compute.UserManaged,
"vgpus": compute.VGPUs, "vgpus": compute.VGPUs,
"vins_connected": compute.VINSConnected, "vins_connected": compute.VINSConnected,
"virtual_image_id": compute.VirtualImageID, "virtual_image_id": compute.VirtualImageID,
} }
res = append(res, temp) res = append(res, temp)
} }
@@ -237,10 +236,10 @@ func flattenBootDisk(bootDisk *compute.ItemComputeDisk) []map[string]interface{}
return res 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)) res := make([]map[string]interface{}, 0, len(disksList))
for _, disk := range 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 continue
} }
temp := map[string]interface{}{ temp := map[string]interface{}{
@@ -261,6 +260,7 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []in
sort.Slice(res, func(i, j int) bool { sort.Slice(res, func(i, j int) bool {
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64) return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
}) })
return res return res
} }
@@ -281,7 +281,7 @@ func flattenNetwork(interfaces compute.ListInterfaces) []map[string]interface{}
func findBootDisk(disks compute.ListComputeDisks) *compute.ItemComputeDisk { func findBootDisk(disks compute.ListComputeDisks) *compute.ItemComputeDisk {
for _, disk := range disks { for _, disk := range disks {
if strings.Contains(disk.Name, "bootdisk") { if disk.Type == "B" {
return &disk return &disk
} }
} }
@@ -301,7 +301,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) er
//check extraDisks, ipa_type, is, //check extraDisks, ipa_type, is,
d.SetId(strconv.FormatUint(computeRec.ID, 10)) 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_id", computeRec.AccountID)
d.Set("account_name", computeRec.AccountName) d.Set("account_name", computeRec.AccountName)
d.Set("affinity_weight", computeRec.AffinityWeight) 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("computeci_id", computeRec.ComputeCIID)
d.Set("created_by", computeRec.CreatedBy) d.Set("created_by", computeRec.CreatedBy)
d.Set("created_time", computeRec.CreatedTime) d.Set("created_time", computeRec.CreatedTime)
// d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
d.Set("deleted_by", computeRec.DeletedBy) d.Set("deleted_by", computeRec.DeletedBy)
d.Set("deleted_time", computeRec.DeletedTime) d.Set("deleted_time", computeRec.DeletedTime)
d.Set("description", computeRec.Description) d.Set("description", computeRec.Description)
d.Set("devices", string(devices)) 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 { if err != nil {
return err return err
} }
@@ -542,7 +543,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("cpus", computeRec.CPU) d.Set("cpus", computeRec.CPU)
d.Set("created_by", computeRec.CreatedBy) d.Set("created_by", computeRec.CreatedBy)
d.Set("created_time", computeRec.CreatedTime) 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_by", computeRec.DeletedBy)
d.Set("deleted_time", computeRec.DeletedTime) d.Set("deleted_time", computeRec.DeletedTime)
d.Set("desc", computeRec.Description) d.Set("desc", computeRec.Description)

View 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,
},
},
}
}

View File

@@ -192,6 +192,16 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.Driver = driver 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") log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86) apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86)
if err != nil { if err != nil {
@@ -226,7 +236,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
argVal, ok = d.GetOk("extra_disks") argVal, ok = d.GetOk("extra_disks")
if ok && argVal.(*schema.Set).Len() > 0 { if ok && argVal.(*schema.Set).Len() > 0 {
log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len()) 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 { if err != nil {
log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", computeId, err) log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", computeId, err)
cleanup = true 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, ok := d.GetOk("enabled"); ok {
if enabled.(bool) { if enabled.(bool) {
req := compute.EnableRequest{ComputeID: computeId} 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 { if _, err := c.CloudAPI().Compute().Enable(ctx, req); err != nil {
warnings.Add(err) warnings.Add(err)
} }
} else { } else {
req := compute.DisableRequest{ComputeID: computeId} 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 { if _, err := c.CloudAPI().Compute().Disable(ctx, req); err != nil {
warnings.Add(err) warnings.Add(err)
} }
@@ -574,11 +584,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
switch networkData["net_type"].(string) { switch networkData["net_type"].(string) {
case "VINS": case "VINS":
if vinsId, ok := existVinsId(ctx, m, networkData["net_id"].(int)); !ok { 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": case "EXTNET":
if extNetId, ok := existExtNetId(ctx, m, networkData["net_id"].(int)); !ok { 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: default:
@@ -706,7 +716,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
} }
if d.HasChange("extra_disks") { 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 { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -745,7 +755,23 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
for _, el := range oldConv { for _, el := range oldConv {
if !isContainsDisk(newConv, el) { 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 +798,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
for _, disk := range deletedDisks { for _, disk := range deletedDisks {
diskConv := disk.(map[string]interface{}) diskConv := disk.(map[string]interface{})
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") { if diskConv["disk_type"].(string) == "B" {
continue continue
} }
@@ -782,6 +808,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
Permanently: diskConv["permanently"].(bool), Permanently: diskConv["permanently"].(bool),
} }
log.Debugf("trying to delete disk %d", req.DiskID)
_, err := c.CloudAPI().Compute().DiskDel(ctx, req) _, err := c.CloudAPI().Compute().DiskDel(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
@@ -800,7 +828,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if len(addedDisks) > 0 { if len(addedDisks) > 0 {
for _, disk := range addedDisks { for _, disk := range addedDisks {
diskConv := disk.(map[string]interface{}) diskConv := disk.(map[string]interface{})
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") { if diskConv["disk_type"].(string) == "B" {
continue continue
} }
req := compute.DiskAddRequest{ req := compute.DiskAddRequest{
@@ -832,7 +860,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if len(updatedDisks) > 0 { if len(updatedDisks) > 0 {
for _, disk := range updatedDisks { for _, disk := range updatedDisks {
diskConv := disk.(map[string]interface{}) diskConv := disk.(map[string]interface{})
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") { if diskConv["disk_type"].(string) == "B" {
continue continue
} }
req := compute.DiskResizeRequest{ req := compute.DiskResizeRequest{
@@ -1335,6 +1363,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 // we may reuse dataSourceComputeRead here as we maintain similarity
// between Compute resource and Compute data source schemas // between Compute resource and Compute data source schemas
defer resourceComputeRead(ctx, d, m) defer resourceComputeRead(ctx, d, m)
@@ -1678,6 +1735,11 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Schema: disksSubresourceSchemaMake(), Schema: disksSubresourceSchemaMake(),
}, },
}, },
"custom_fields": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"stateless": { "stateless": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
@@ -1715,6 +1777,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
"extra_disks": { "extra_disks": {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Computed: true,
MaxItems: constants.MaxExtraDisksPerCompute, MaxItems: constants.MaxExtraDisksPerCompute,
Elem: &schema.Schema{ Elem: &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
@@ -2075,7 +2138,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
func ResourceCompute() *schema.Resource { func ResourceCompute() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
SchemaVersion: 1, SchemaVersion: 2,
CreateContext: resourceComputeCreate, CreateContext: resourceComputeCreate,
ReadContext: resourceComputeRead, ReadContext: resourceComputeRead,
@@ -2095,5 +2158,12 @@ func ResourceCompute() *schema.Resource {
}, },
Schema: ResourceComputeSchemaMake(), Schema: ResourceComputeSchemaMake(),
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceComputeResourceV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceCompueteStateUpgradeV1,
Version: 1,
},
},
} }
} }

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

View File

@@ -54,7 +54,7 @@ func matchComputes(computeList *compute.ListComputes) *compute.ListComputes {
return &result 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) c := m.(*controller.ControllerCfg)
log.Debugf("utilityComputeExtraDisksConfigure: called for Compute ID %s with do_delta = %t", d.Id(), do_delta) 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)), 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) _, err := c.CloudAPI().Compute().DiskAttach(ctx, req)
if err != nil { if err != nil {
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err) 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, Force: true,
} }
log.Debugf("utilityComputeNetworksConfigure: stopping compute %d", computeID)
_, err := c.CloudAPI().Compute().Stop(ctx, req) _, err := c.CloudAPI().Compute().Stop(ctx, req)
if err != nil { if err != nil {
return err return err
@@ -255,6 +272,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
startReq := compute.StartRequest{ComputeID: computeID} startReq := compute.StartRequest{ComputeID: computeID}
log.Debugf("utilityComputeNetworksConfigure: starting compute %d", computeID)
_, err = c.CloudAPI().Compute().Start(ctx, startReq) _, err = c.CloudAPI().Compute().Start(ctx, startReq)
if err != nil { if err != nil {
apiErrCount++ apiErrCount++
@@ -279,7 +297,7 @@ func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m
computeRecord, err := c.CloudAPI().Compute().Get(ctx, req) computeRecord, err := c.CloudAPI().Compute().Get(ctx, req)
if err != nil { if err != nil {
return *computeRecord, err return compute.RecordCompute{}, err
} }
return *computeRecord, nil return *computeRecord, nil

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,8 +34,8 @@ package vins
import ( import (
"context" "context"
"strconv"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "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) return diag.FromErr(err)
} }
d.SetId(strconv.FormatUint(vins.ID, 10)) id := uuid.New()
flattenVinsData(d, *vins) d.SetId(id.String())
flattenVinsData(d, vins)
return nil 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{ return map[string]*schema.Schema{
"net_mask": { "net_mask": {
Type: schema.TypeInt, Type: schema.TypeInt,
@@ -678,7 +679,7 @@ func natSchemaMake() map[string]*schema.Schema {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: configSchrmaMake(), Schema: natConfigSchemaMake(),
}, },
}, },
"devices": { "devices": {
@@ -768,7 +769,6 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Required: true, Required: true,
Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.", Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.",
}, },
"vnf_dev": { "vnf_dev": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
@@ -776,10 +776,6 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Schema: vnfDevSchemaMake(), Schema: vnfDevSchemaMake(),
}, },
}, },
"_ckey": {
Type: schema.TypeString,
Computed: true,
},
"account_id": { "account_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@@ -797,6 +793,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Schema: vinsComputeSchemaMake(), Schema: vinsComputeSchemaMake(),
}, },
}, },
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": { "default_gw": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@@ -808,6 +812,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Schema: qosSchemaMake(), Schema: qosSchemaMake(),
}, },
}, },
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": { "desc": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@@ -874,6 +886,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"user_managed": { "user_managed": {
Type: schema.TypeBool, Type: schema.TypeBool,
Computed: true, Computed: true,

View File

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

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -49,7 +49,7 @@ func dataSourceVinsExtNetListRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenVinsExtNetList(extNetList)) d.Set("items", flattenVinsExtNetList(extNetList))
d.Set("entry_count", extNetList.EntryCount)
return nil return nil
} }
@@ -92,6 +92,10 @@ func DataSourceVinsExtNetListchemaMake() map[string]*schema.Schema {
}, },
}, },
}, },
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
} }
return rets return rets
} }

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -49,7 +49,7 @@ func dataSourceVinsIpListRead(ctx context.Context, d *schema.ResourceData, m int
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenVinsIpList(ips)) d.Set("items", flattenVinsIpList(ips))
d.Set("entry_count", ips.EntryCount)
return nil return nil
} }
@@ -96,6 +96,10 @@ func DataSourceVinsIpListSchemaMake() map[string]*schema.Schema {
}, },
}, },
}, },
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
} }
return rets return rets
} }

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -49,6 +49,8 @@ func dataSourceVinsNatRuleListRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenVinsNatRuleList(natRules)) d.Set("items", flattenVinsNatRuleList(natRules))
d.Set("entry_count", natRules.EntryCount)
return nil return nil
} }
@@ -99,6 +101,10 @@ func DataSourceVinsNatRuleListSchemaMake() map[string]*schema.Schema {
}, },
}, },
}, },
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
} }
return rets return rets
} }

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -49,7 +49,7 @@ func flattenMGMT(mgmt vins.RecordMGMT) []map[string]interface{} {
return res return res
} }
func flattenResources(resources *vins.RecordResources) []map[string]interface{} { func flattenResources(resources vins.RecordResources) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
"cpu": resources.CPU, "cpu": resources.CPU,
@@ -65,7 +65,7 @@ func flattenConfig(config vins.RecordVNFConfig) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
"mgmt": flattenMGMT(config.MGMT), "mgmt": flattenMGMT(config.MGMT),
"resources": flattenResources(&config.Resources), "resources": flattenResources(config.Resources),
} }
res = append(res, temp) res = append(res, temp)
return res return res
@@ -84,8 +84,7 @@ func flattenQOS(qos vins.QOS) []map[string]interface{} {
} }
func flattenInterfaces(interfaces []vins.ItemVNFInterface) []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 { for _, vnfInterface := range interfaces {
temp := map[string]interface{}{ temp := map[string]interface{}{
"conn_id": vnfInterface.ConnID, "conn_id": vnfInterface.ConnID,
@@ -141,7 +140,7 @@ func flattenVNFDev(vnfDev vins.RecordVNFDev) []map[string]interface{} {
} }
func flattenComputes(computes vins.ListVINSComputes) []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 { for _, compute := range computes {
temp := map[string]interface{}{ temp := map[string]interface{}{
"compute_id": compute.ID, "compute_id": compute.ID,
@@ -154,7 +153,7 @@ func flattenComputes(computes vins.ListVINSComputes) []map[string]interface{} {
} }
func flattenReservations(reservations vins.ListReservations) []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 { for _, reservation := range reservations {
temp := map[string]interface{}{ temp := map[string]interface{}{
"client_type": reservation.ClientType, "client_type": reservation.ClientType,
@@ -275,9 +274,9 @@ func flattenGW(gw vins.RecordGW) []map[string]interface{} {
return res return res
} }
func flattenRules(rules vins.ListNATRules) []map[string]interface{} { func flattenRules(rules vins.ListNATRulesConfig) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules.Data { for _, rule := range rules {
tmp := map[string]interface{}{ tmp := map[string]interface{}{
"rule_id": rule.ID, "rule_id": rule.ID,
"local_ip": rule.LocalIP, "local_ip": rule.LocalIP,
@@ -343,9 +342,9 @@ func flattenVNFS(vnfs vins.RecordVNFs) []map[string]interface{} {
return res return res
} }
func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} { func flattenRuleBlock(rules vins.ListNATRulesConfig) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules.Data { for _, rule := range rules {
tmp := map[string]interface{}{ tmp := map[string]interface{}{
"int_ip": rule.LocalIP, "int_ip": rule.LocalIP,
"int_port": rule.LocalPort, "int_port": rule.LocalPort,
@@ -359,15 +358,18 @@ func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} {
return res 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("vins_id", vins.ID)
d.Set("vnf_dev", flattenVNFDev(vins.VNFDev)) d.Set("vnf_dev", flattenVNFDev(vins.VNFDev))
d.Set("_ckey", vins.CKey)
d.Set("account_id", vins.AccountID) d.Set("account_id", vins.AccountID)
d.Set("account_name", vins.AccountName) d.Set("account_name", vins.AccountName)
d.Set("computes", flattenComputes(vins.Computes)) 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_gw", vins.DefaultGW)
d.Set("default_qos", flattenQOS(vins.DefaultQOS)) 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("desc", vins.Description)
d.Set("gid", vins.GID) d.Set("gid", vins.GID)
d.Set("guid", vins.GUID) 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("rg_name", vins.RGName)
d.Set("sec_vnf_dev_id", vins.SecVNFDevID) d.Set("sec_vnf_dev_id", vins.SecVNFDevID)
d.Set("status", vins.Status) 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("user_managed", vins.UserManaged)
d.Set("vnfs", flattenVNFS(vins.VNFs)) d.Set("vnfs", flattenVNFS(vins.VNFs))
d.Set("vxlan_id", vins.VXLANID) d.Set("vxlan_id", vins.VXLANID)
d.Set("nat_rule", flattenRuleBlock(vins.VNFs.NAT.Config.Rules)) 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("vins_id", vins.ID)
d.Set("vnf_dev", flattenVNFDev(vins.VNFDev)) d.Set("vnf_dev", flattenVNFDev(vins.VNFDev))
d.Set("_ckey", vins.CKey)
d.Set("account_id", vins.AccountID) d.Set("account_id", vins.AccountID)
d.Set("account_name", vins.AccountName) d.Set("account_name", vins.AccountName)
d.Set("computes", flattenComputes(vins.Computes)) 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_gw", vins.DefaultGW)
d.Set("default_qos", flattenQOS(vins.DefaultQOS)) 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("desc", vins.Description)
d.Set("gid", vins.GID) d.Set("gid", vins.GID)
d.Set("guid", vins.GUID) 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("rg_name", vins.RGName)
d.Set("sec_vnf_dev_id", vins.SecVNFDevID) d.Set("sec_vnf_dev_id", vins.SecVNFDevID)
d.Set("status", vins.Status) 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("user_managed", vins.UserManaged)
d.Set("vnfs", flattenVNFS(vins.VNFs)) d.Set("vnfs", flattenVNFS(vins.VNFs))
d.Set("vxlan_id", vins.VXLANID) d.Set("vxlan_id", vins.VXLANID)
} }
func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} { func flattenVinsAudits(audits vins.ListAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0, len(audits))
for _, audit := range auidts { for _, audit := range audits {
temp := map[string]interface{}{ temp := map[string]interface{}{
"call": audit.Call, "call": audit.Call,
"response_time": audit.ResponseTime, "response_time": audit.ResponseTime,
@@ -437,7 +446,7 @@ func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} {
} }
func flattenVinsExtNetList(extNetList *vins.ListExtNets) []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 { for _, extNet := range extNetList.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"default_gw": extNet.DefaultGW, "default_gw": extNet.DefaultGW,
@@ -454,7 +463,7 @@ func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{
} }
func flattenVinsIpList(ips *vins.ListIPs) []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 { for _, ip := range ips.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"client_type": ip.ClientType, "client_type": ip.ClientType,
@@ -472,7 +481,7 @@ func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} {
} }
func flattenVinsList(vl *vins.ListVINS) []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 { for _, v := range vl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"account_id": v.AccountID, "account_id": v.AccountID,
@@ -498,7 +507,7 @@ func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
} }
func flattenVinsNatRuleList(natRules *vins.ListNATRules) []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 { for _, natRule := range natRules.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"id": natRule.ID, "id": natRule.ID,

View File

@@ -129,8 +129,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
if desc, ok := d.GetOk("desc"); ok { if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string) 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) id, err := c.CloudAPI().VINS().CreateInRG(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
@@ -141,7 +143,6 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
req := vins.CreateInAccountRequest{ req := vins.CreateInAccountRequest{
Name: d.Get("name").(string), Name: d.Get("name").(string),
AccountID: uint64(accountId.(int)), AccountID: uint64(accountId.(int)),
PreReservationsNum: uint64(d.Get("pre_reservations_num").(int)),
} }
if gid, ok := d.GetOk("gid"); ok { 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 { if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string) 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) id, err := c.CloudAPI().VINS().CreateInAccount(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) 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 { func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
warnings := dc.Warnings{} warnings := dc.Warnings{}
vinsData, err := utilityVinsCheckPresence(ctx, d, m) vinsData, err := utilityDataVinsCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
@@ -282,14 +286,14 @@ func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}
} }
if hasChangeState { if hasChangeState {
vinsData, err = utilityVinsCheckPresence(ctx, d, m) vinsData, err = utilityDataVinsCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
flattenVins(d, *vinsData) flattenVins(d, vinsData)
return warnings.Get() return warnings.Get()
} }
@@ -366,7 +370,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 { if err != nil {
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
@@ -425,7 +429,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
} }
if hasChangeState { if hasChangeState {
vinsData, err = utilityVinsCheckPresence(ctx, d, m) vinsData, err = utilityDataVinsCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
@@ -631,8 +635,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
} }
} }
defer resourceVinsRead(ctx, d, m) return append (warnings.Get(), resourceVinsRead(ctx, d, m)...)
return warnings.Get()
} }
func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -658,7 +661,7 @@ func extNetSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{ return map[string]*schema.Schema{
"ext_net_id": { "ext_net_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Default: 0, Default: -1,
Optional: true, Optional: true,
}, },
"ext_net_ip": { "ext_net_ip": {
@@ -674,6 +677,7 @@ func ipSchemaMake() map[string]*schema.Schema {
"type": { "type": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ValidateFunc: validation.StringInSlice([]string {"DHCP", "VIP", "EXCLUDE"}, false),
}, },
"ip_addr": { "ip_addr": {
Type: schema.TypeString, Type: schema.TypeString,
@@ -823,7 +827,6 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Optional: true, Optional: true,
Default: false, Default: false,
} }
rets["vins_id"] = &schema.Schema{ rets["vins_id"] = &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -44,8 +44,13 @@ import (
func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) { func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := vins.GetRequest{ req := vins.GetRequest{}
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))
} }
vins, err := c.CloudAPI().VINS().Get(ctx, req) vins, err := c.CloudAPI().VINS().Get(ctx, req)
@@ -56,17 +61,3 @@ func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m
return vins, nil 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
}

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,6 +34,7 @@ package vins
import ( import (
"context" "context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins" "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) { func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListAudits, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := vins.AuditsRequest{ req := vins.AuditsRequest{}
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))
} }
audits, err := c.CloudAPI().VINS().Audits(ctx, req) audits, err := c.CloudAPI().VINS().Audits(ctx, req)

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,6 +34,7 @@ package vins
import ( import (
"context" "context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins" "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)), 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) extNetList, err := c.CloudAPI().VINS().ExtNetList(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,6 +34,7 @@ package vins
import ( import (
"context" "context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins" "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) { func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListIPs, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := vins.IPListRequest{ req := vins.IPListRequest{}
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))
} }
ips, err := c.CloudAPI().VINS().IPList(ctx, req) ips, err := c.CloudAPI().VINS().IPList(ctx, req)

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,6 +34,7 @@ package vins
import ( import (
"context" "context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins" "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) { func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListNATRules, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := vins.NATRuleListRequest{ req := vins.NATRuleListRequest{}
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))
} }
natRuleList, err := c.CloudAPI().VINS().NATRuleList(ctx, req) natRuleList, err := c.CloudAPI().VINS().NATRuleList(ctx, req)

View File

@@ -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) return resourceExtnetRead(ctx, d, m)
} }