This commit is contained in:
2025-11-18 16:20:26 +03:00
parent 4b3f21d9be
commit e42fbcef39
397 changed files with 17560 additions and 1501 deletions

View File

@@ -441,6 +441,10 @@ func computeListDisksSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_id": {
Type: schema.TypeInt,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
@@ -449,6 +453,10 @@ func computeListDisksSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
}
}
@@ -495,6 +503,10 @@ func computeInterfacesSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -561,6 +573,13 @@ func computeInterfacesSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,
@@ -726,6 +745,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"cd_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -1125,6 +1148,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"os_version": {
Type: schema.TypeString,
Computed: true,
},
}
}

View File

@@ -50,6 +50,7 @@ func dataSourceComputeAuditsRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenComputeAudits(computeAudits))
d.Set("entry_count", computeAudits.EntryCount)
return nil
}
@@ -59,6 +60,42 @@ func dataSourceComputeAuditsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"timestamp_at": {
Type: schema.TypeInt,
Optional: true,
},
"timestamp_to": {
Type: schema.TypeInt,
Optional: true,
},
"user": {
Type: schema.TypeString,
Optional: true,
},
"call": {
Type: schema.TypeString,
Optional: true,
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
},
"page": {
Type: schema.TypeInt,
Optional: true,
},
"size": {
Type: schema.TypeInt,
Optional: true,
},
"min_status_code": {
Type: schema.TypeInt,
Optional: true,
},
"max_status_code": {
Type: schema.TypeInt,
Optional: true,
},
"items": {
Type: schema.TypeList,
@@ -88,6 +125,10 @@ func dataSourceComputeAuditsSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}

View File

@@ -136,6 +136,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"cd_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -273,6 +277,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"os_version": {
Type: schema.TypeString,
Computed: true,
},
"pinned": {
Type: schema.TypeBool,
Computed: true,
@@ -514,6 +522,11 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Default: false,
Description: "If set to true, ignores any VMs associated with any k8s cluster",
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Zone ID",
},
"items": {
Type: schema.TypeList,
Computed: true,

View File

@@ -75,6 +75,7 @@ func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface
"conn_type": interfaceItem.ConnType,
"def_gw": interfaceItem.DefGW,
"enabled": interfaceItem.Enabled,
"enable_secgroups": interfaceItem.EnableSecGroups,
"flip_group_id": interfaceItem.FLIPGroupID,
"guid": interfaceItem.GUID,
"ip_address": interfaceItem.IPAddress,
@@ -88,6 +89,7 @@ func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface
"node_id": interfaceItem.NodeID,
"pci_slot": interfaceItem.PCISlot,
"qos": flattenQOS(interfaceItem.QOS),
"security_groups": interfaceItem.SecGroups,
"sdn_interface_id": interfaceItem.SDNInterfaceID,
"target": interfaceItem.Target,
"type": interfaceItem.Type,
@@ -177,38 +179,40 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
customFields, _ := json.Marshal(compute.CustomFields)
devices, _ := json.Marshal(compute.Devices)
temp := map[string]interface{}{
"acl": flattenListACL(compute.ACL),
"account_id": compute.AccountID,
"account_name": compute.AccountName,
"affinity_label": compute.AffinityLabel,
"affinity_rules": flattenListRules(compute.AffinityRules),
"affinity_weight": compute.AffinityWeight,
"anti_affinity_rules": flattenListRules(compute.AntiAffinityRules),
"arch": compute.Architecture,
"auto_start_w_node": compute.AutoStart,
"boot_order": compute.BootOrder,
"bootdisk_size": compute.BootDiskSize,
"chipset": compute.Chipset,
"cd_image_id": compute.CdImageId,
"clone_reference": compute.CloneReference,
"clones": compute.Clones,
"computeci_id": compute.ComputeCIID,
"cpu_pin": compute.CPUPin,
"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,
"hp_backed": compute.HPBacked,
"compute_id": compute.ID,
"image_id": compute.ImageID,
"acl": flattenListACL(compute.ACL),
"account_id": compute.AccountID,
"account_name": compute.AccountName,
"affinity_label": compute.AffinityLabel,
"affinity_rules": flattenListRules(compute.AffinityRules),
"affinity_weight": compute.AffinityWeight,
"anti_affinity_rules": flattenListRules(compute.AntiAffinityRules),
"arch": compute.Architecture,
"auto_start_w_node": compute.AutoStart,
"boot_order": compute.BootOrder,
"bootdisk_size": compute.BootDiskSize,
"boot_image_id": compute.BootImageID,
"chipset": compute.Chipset,
"cd_image_id": compute.CdImageId,
"clone_reference": compute.CloneReference,
"clones": compute.Clones,
"computeci_id": compute.ComputeCIID,
"cpu_pin": compute.CPUPin,
"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,
"hp_backed": compute.HPBacked,
"compute_id": compute.ID,
//TODO
// "image_id": compute.ImageID,
"interfaces": flattenInterfaces(compute.Interfaces),
"live_migration_job_id": compute.LiveMigrationJobID,
"lock_status": compute.LockStatus,
@@ -220,33 +224,36 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"need_reboot": compute.NeedReboot,
"numa_affinity": compute.NumaAffinity,
"numa_node_id": compute.NumaNodeId,
"os_version": compute.OSVersion,
// "pinned": compute.Pinned,
"preferred_cpu": compute.PreferredCPU,
"qemu_guest": flattenQemuQuest(compute.QemuQuest),
"ram": compute.RAM,
"reference_id": compute.ReferenceID,
"registered": compute.Registered,
"res_name": compute.ResName,
"reserved_node_cpus": compute.ReservedNodeCpus,
"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,
"preferred_cpu": compute.PreferredCPU,
"qemu_guest": flattenQemuQuest(compute.QemuQuest),
"ram": compute.RAM,
"reference_id": compute.ReferenceID,
"registered": compute.Registered,
"res_name": compute.ResName,
"reserved_node_cpus": compute.ReservedNodeCpus,
"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,
//TODO
// "virtual_image_id": compute.VirtualImageID,
"loader_type": compute.LoaderType,
"boot_type": compute.BootType,
"hot_resize": compute.HotResize,
"network_interface_naming": compute.NetworkInterfaceNaming,
"zone_id": compute.ZoneID,
}
res = append(res, temp)
}
@@ -258,18 +265,20 @@ func flattenBootDisk(bootDisk *compute.ItemComputeDisk) []map[string]interface{}
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"disk_name": bootDisk.Name,
"disk_id": bootDisk.ID,
"disk_type": bootDisk.Type,
"sep_id": bootDisk.SepID,
"shareable": bootDisk.Shareable,
"size_max": bootDisk.SizeMax,
"size_used": bootDisk.SizeUsed,
"pool": bootDisk.Pool,
"desc": bootDisk.Description,
"image_id": bootDisk.ImageID,
"size": bootDisk.SizeMax,
"present_to": bootDisk.PresentTo,
"disk_name": bootDisk.Name,
"disk_id": bootDisk.ID,
"disk_type": bootDisk.Type,
"sep_id": bootDisk.SepID,
"shareable": bootDisk.Shareable,
"size_max": bootDisk.SizeMax,
"size_used": bootDisk.SizeUsed,
"pool": bootDisk.Pool,
"desc": bootDisk.Description,
"image_id": bootDisk.ImageID,
"size": bootDisk.SizeMax,
"present_to": bootDisk.PresentTo,
"storage_policy_id": bootDisk.StoragePolicyID,
"to_clean": bootDisk.ToClean,
}
res = append(res, temp)
@@ -298,19 +307,20 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, disksBlocks, ex
pernamentlyValue := disksBlocks[indexDataDisks].(map[string]interface{})["permanently"].(bool)
temp := map[string]interface{}{
"disk_name": disk.Name,
"disk_id": disk.ID,
"disk_type": disk.Type,
"sep_id": disk.SepID,
"shareable": disk.Shareable,
"size_max": disk.SizeMax,
"size_used": disk.SizeUsed,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"size": disk.SizeMax,
"permanently": pernamentlyValue,
"present_to": disk.PresentTo,
"disk_name": disk.Name,
"disk_id": disk.ID,
"disk_type": disk.Type,
"sep_id": disk.SepID,
"shareable": disk.Shareable,
"size_max": disk.SizeMax,
"size_used": disk.SizeUsed,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"size": disk.SizeMax,
"permanently": pernamentlyValue,
"present_to": disk.PresentTo,
"storage_policy_id": disk.StoragePolicyID,
}
res = append(res, temp)
indexDataDisks++
@@ -331,6 +341,7 @@ func flattenNetwork(networks []interface{}, interfaces compute.ListInterfaces) [
"mtu": network.MTU,
"sdn_interface_id": network.SDNInterfaceID,
"weight": flattenNetworkWeight(networks, network.NetID, network.NetType),
"enabled": network.Enabled,
}
res = append(res, temp)
}
@@ -381,6 +392,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pc
d.Set("boot_disk_size", bootDisk.SizeMax)
d.Set("boot_disk", flattenBootDisk(bootDisk))
d.Set("boot_disk_id", bootDisk.ID)
d.Set("boot_image_id", computeRec.BootImageID)
d.Set("cd_image_id", computeRec.CdImageId)
d.Set("sep_id", bootDisk.SepID)
d.Set("pool", bootDisk.Pool)
@@ -404,11 +416,12 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pc
d.Set("gid", computeRec.GID)
d.Set("guid", computeRec.GUID)
d.Set("compute_id", computeRec.ID)
if computeRec.VirtualImageID != 0 {
d.Set("image_id", computeRec.VirtualImageID)
} else {
d.Set("image_id", computeRec.ImageID)
}
//TODO
// if computeRec.VirtualImageID != 0 {
// d.Set("image_id", computeRec.VirtualImageID)
// } else {
// d.Set("image_id", computeRec.ImageID)
// }
d.Set("interfaces", flattenInterfaces(computeRec.Interfaces))
d.Set("lock_status", computeRec.LockStatus)
d.Set("manager_id", computeRec.ManagerID)
@@ -446,8 +459,9 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pc
d.Set("user_managed", computeRec.UserManaged)
d.Set("vnc_password", computeRec.VNCPassword)
d.Set("vgpus", flattenVGPUs(computeRec.VGPUs))
d.Set("virtual_image_id", computeRec.VirtualImageID)
d.Set("virtual_image_name", computeRec.VirtualImageName)
//TODO
// d.Set("virtual_image_id", computeRec.VirtualImageID)
// d.Set("virtual_image_name", computeRec.VirtualImageName)
d.Set("loader_type", computeRec.LoaderType)
d.Set("boot_type", computeRec.BootType)
d.Set("hot_resize", computeRec.HotResize)
@@ -467,6 +481,8 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pc
d.Set("network", flattenNetwork(d.Get("network").(*schema.Set).List(), computeRec.Interfaces))
d.Set("pci_devices", flattenPCI(*pciList))
d.Set("os_version", computeRec.OSVersion)
return nil
}
@@ -581,8 +597,10 @@ func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interf
"size_used": disk.SizeUsed,
"snapshots": flattenSnapshots(disk.Snapshots),
"status": disk.Status,
"storage_policy_id": disk.StoragePolicyID,
"tech_status": disk.TechStatus,
"type": disk.Type,
"to_clean": disk.ToClean,
}
res = append(res, temp)
}
@@ -638,6 +656,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("chipset", computeRec.Chipset)
d.Set("boot_order", computeRec.BootOrder)
d.Set("bootdisk_size", computeRec.BootDiskSize)
d.Set("boot_image_id", computeRec.BootImageID)
d.Set("cd_image_id", computeRec.CdImageId)
d.Set("clone_reference", computeRec.CloneReference)
d.Set("clones", computeRec.Clones)
@@ -698,14 +717,16 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("userdata", string(userdata))
d.Set("vnc_password", computeRec.VNCPassword)
d.Set("vgpus", flattenVGPUs(computeRec.VGPUs))
d.Set("virtual_image_id", computeRec.VirtualImageID)
d.Set("virtual_image_name", computeRec.VirtualImageName)
//TODO
// d.Set("virtual_image_id", computeRec.VirtualImageID)
// d.Set("virtual_image_name", computeRec.VirtualImageName)
d.Set("pci_devices", flattenPCI(*pciList))
d.Set("loader_type", computeRec.LoaderType)
d.Set("boot_type", computeRec.BootType)
d.Set("hot_resize", computeRec.HotResize)
d.Set("network_interface_naming", computeRec.NetworkInterfaceNaming)
d.Set("zone_id", computeRec.ZoneID)
d.Set("os_version", computeRec.OSVersion)
}
func flattenPCI(pciList compute.ListPCIDevices) []uint64 {
@@ -719,8 +740,8 @@ func flattenPCI(pciList compute.ListPCIDevices) []uint64 {
}
func flattenComputeAudits(computeAudits compute.ListAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(computeAudits))
for _, computeAudit := range computeAudits {
res := make([]map[string]interface{}, 0, len(computeAudits.Data))
for _, computeAudit := range computeAudits.Data {
temp := map[string]interface{}{
"call": computeAudit.Call,
"responsetime": computeAudit.ResponseTime,

View File

@@ -0,0 +1,10 @@
package kvmvm
type updatedNetwork struct {
DetachMap []map[string]interface{}
ChangeIPMap []map[string]interface{}
ChangeMacMap []map[string]interface{}
ChangeMTUMap []map[string]interface{}
AttachMap []map[string]interface{}
EnableMap []map[string]interface{}
}

View File

@@ -177,6 +177,13 @@ func networkSubresourceSchemaMake() map[string]*schema.Schema {
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
Description: "unique_identifier of LogicalPort on SDN side",
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "network enable flag",
},
}
return rets
}

View File

@@ -35,6 +35,8 @@ package kvmvm
import (
"context"
"errors"
"fmt"
"sort"
"strconv"
"strings"
@@ -172,6 +174,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
NetID: uint64(netInterfaceVal["net_id"].(int)),
}
if enabledNetwork(d.GetRawConfig().GetAttr("network"), reqInterface.NetID, reqInterface.NetType) {
reqInterface.Enabled = netInterfaceVal["enabled"].(bool)
}
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" {
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
}
@@ -204,8 +210,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
for _, elem := range disks.([]interface{}) {
diskVal := elem.(map[string]interface{})
reqDataDisk := kvmx86.DataDisk{
DiskName: diskVal["disk_name"].(string),
Size: uint64(diskVal["size"].(int)),
DiskName: diskVal["disk_name"].(string),
Size: uint64(diskVal["size"].(int)),
StoragePolicyID: uint64(diskVal["storage_policy_id"].(int)),
}
if sepId, ok := diskVal["sep_id"]; ok {
reqDataDisk.SepID = uint64(sepId.(int))
@@ -235,14 +242,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
var computeId uint64
driver := d.Get("driver").(string)
createReqX86.RGID = uint64(d.Get("rg_id").(int))
createReqX86.Name = d.Get("name").(string)
createReqX86.CPU = uint64(d.Get("cpu").(int))
createReqX86.RAM = uint64(d.Get("ram").(int))
createReqX86.Driver = driver
createReqX86.StoragePolicyID = uint64(d.Get("storage_policy_id").(int))
if image, ok := d.GetOk("image_id"); ok {
createReqX86.ImageID = uint64(image.(int))
@@ -278,6 +283,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if osVersion, ok := d.GetOk("os_version"); ok {
createReqX86.OSVersion = osVersion.(string)
}
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86)
if err != nil {
@@ -289,6 +298,11 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
warnings := dc.Warnings{}
simpleCompRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
warnings.Add(err)
}
cleanup := false
defer func() {
if cleanup {
@@ -312,7 +326,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
loaderType, loaderTypeOk := d.GetOk("loader_type")
bootType, bootTypeOk := d.GetOk("boot_type")
hotResize, hotResizeOk := d.GetOk("hot_resize")
hotResize, hotResizeOk := d.GetOkExists("hot_resize")
networkInterfaceNaming, networkInterfaceNamingOk := d.GetOk("network_interface_naming")
if loaderTypeOk {
@@ -388,14 +402,42 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.Get("pin_to_stack").(bool) {
req := compute.PinToStackRequest{
ComputeID: computeId,
}
req.AutoStart = d.Get("auto_start_w_node").(bool)
_, err := c.CloudAPI().Compute().PinToStack(ctx, req)
if err != nil {
warnings.Add(err)
if secGroups, ok := d.GetOk("security_groups"); ok {
if secGroups.(*schema.Set).Len() > 0 {
sgl := secGroups.(*schema.Set).List()
for _, elem := range sgl {
secGroupsMap := elem.(map[string]interface{})
netType := secGroupsMap["net_type"].(string)
netId := uint64(secGroupsMap["net_id"].(int))
var mac string
for _, iface := range simpleCompRec.Interfaces {
if iface.NetID == netId && iface.NetType == netType {
mac = iface.MAC
break
}
}
if mac == "" {
warnings.Add(errors.New(fmt.Sprintf("add security groups: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId)))
continue
}
secGroupsIDs := make([]uint64, 0)
for _, id := range secGroupsMap["security_groups"].(*schema.Set).List() {
secGroupsIDs = append(secGroupsIDs, uint64(id.(int)))
}
log.Debugf("resourceComputeCreate: Configure security groups interface parameters on Network with type %s and id %d", netType, netId)
req := compute.ChangeSecGroupsRequest{
ComputeID: computeId,
Interface: mac,
SecGroups: secGroupsIDs,
EnableSecGroups: secGroupsMap["enable_secgroups"].(bool),
}
_, err := c.CloudAPI().Compute().ChangeSecGroups(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
}
@@ -418,6 +460,22 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.Get("pin_to_stack").(bool) {
if !d.Get("started").(bool) {
warnings.Add(errors.New("cannot pin to stack a VM, VM should be started"))
}
if d.Get("started").(bool) {
req := compute.PinToStackRequest{
ComputeID: computeId,
}
req.AutoStart = d.Get("auto_start_w_node").(bool)
_, err = c.CloudAPI().Compute().PinToStack(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
if affinityLabel, ok := d.GetOk("affinity_label"); ok {
req := compute.AffinityLabelSetRequest{
ComputeID: computeId,
@@ -899,21 +957,36 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if !oldPin.(bool) {
if !d.Get("started").(bool) {
return diag.Errorf("Cannot pin to stack a VM, that is not started")
}
reqToStart := compute.StartRequest{
ComputeID: computeRec.ID,
}
_, err := c.CloudAPI().Compute().Start(ctx, reqToStart)
if err != nil {
return diag.FromErr(err)
}
req := compute.PinToStackRequest{
ComputeID: computeRec.ID,
}
req.AutoStart = d.Get("auto_start_w_node").(bool)
_, err := c.CloudAPI().Compute().PinToStack(ctx, req)
_, err = c.CloudAPI().Compute().PinToStack(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
// Note bene: numa_affinity, cpu_pin, cpu, ram and hp_backed are not allowed to be changed for compute in STARTED tech status.
// If STARTED, we need to stop it before update
// Note bene: numa_affinity, cpu_pin and hp_backed are not allowed to be changed for compute in STARTED tech status.
var isStopRequired bool
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu", "cpu", "ram") && d.Get("started").(bool) {
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu", "hot_resize") && d.Get("started").(bool) {
isStopRequired = true
}
old, new := d.GetChange("cpu")
if old.(int) > new.(int) && d.Get("started").(bool) && d.Get("force_resize").(bool) {
isStopRequired = true
}
if isStopRequired {
@@ -989,7 +1062,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
"loader_type",
"boot_type",
"hot_resize",
"network_interface_naming") {
"network_interface_naming",
"os_version") {
req := compute.UpdateRequest{
ComputeID: computeRec.ID,
}
@@ -1041,6 +1115,10 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
req.NetworkInterfaceNaming = d.Get("network_interface_naming").(string)
}
if d.HasChange("os_version") {
req.OSVersion = d.Get("os_version").(string)
}
// perform update
if _, err := c.CloudAPI().Compute().Update(ctx, req); err != nil {
return diag.FromErr(err)
@@ -1062,18 +1140,26 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("security_groups") {
err = utilityComputeSecGroupsConfigure(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("disks") {
deletedDisks := make([]interface{}, 0)
addedDisks := make([]interface{}, 0)
resizedDisks := make([]interface{}, 0)
renamedDisks := make([]interface{}, 0)
changeStoragePolicyDisks := make([]interface{}, 0)
oldDisks, newDisks := d.GetChange("disks")
oldConv := oldDisks.([]interface{})
newConv := newDisks.([]interface{})
for _, el := range oldConv {
if !isContainsDisk(newConv, el) && !isRenameDisk(newConv, el) && !isResizeDisk(newConv, el) {
if !isContainsDisk(newConv, el) && !isRenameDisk(newConv, el) && !isResizeDisk(newConv, el) && !isChangeStoragePolicy(newConv, el) {
flag := false
extraDisks := d.Get("extra_disks").(*schema.Set).List()
delDisk := el.(map[string]interface{})
@@ -1104,19 +1190,12 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if isRenameDisk(oldConv, el) {
renamedDisks = append(renamedDisks, el)
}
if isChangeStoragePolicy(oldConv, el) {
changeStoragePolicyDisks = append(changeStoragePolicyDisks, el)
}
}
if len(deletedDisks) > 0 {
stopReq := compute.StopRequest{
ComputeID: computeRec.ID,
Force: false,
}
_, err := c.CloudAPI().Compute().Stop(ctx, stopReq)
if err != nil {
return diag.FromErr(err)
}
for _, disk := range deletedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
@@ -1136,14 +1215,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err)
}
}
req := compute.StartRequest{
ComputeID: computeRec.ID,
AltBootID: 0,
}
_, err = c.CloudAPI().Compute().Start(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
if len(addedDisks) > 0 {
@@ -1153,9 +1224,10 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
continue
}
req := compute.DiskAddRequest{
ComputeID: computeRec.ID,
DiskName: diskConv["disk_name"].(string),
Size: uint64(diskConv["size"].(int)),
ComputeID: computeRec.ID,
DiskName: diskConv["disk_name"].(string),
Size: uint64(diskConv["size"].(int)),
StoragePolicyID: uint64(diskConv["storage_policy_id"].(int)),
}
if diskConv["sep_id"].(int) != 0 {
@@ -1214,6 +1286,22 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
}
if len(changeStoragePolicyDisks) > 0 {
for _, disk := range changeStoragePolicyDisks {
diskConv := disk.(map[string]interface{})
req := disks.ChangeDiskStoragePolicyRequest{
DiskID: uint64(diskConv["disk_id"].(int)),
StoragePolicyID: uint64(diskConv["storage_policy_id"].(int)),
}
_, err := c.CloudAPI().Disks().ChangeDiskStoragePolicy(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
}
if d.HasChange("affinity_label") {
@@ -1650,9 +1738,10 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if oldImage.(int) != newImage.(int) {
req := compute.RedeployRequest{
ComputeID: computeRec.ID,
ImageID: uint64(newImage.(int)),
DataDisks: "KEEP",
ComputeID: computeRec.ID,
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
ImageID: uint64(newImage.(int)),
DataDisks: "KEEP",
}
if diskSize, ok := d.GetOk("boot_disk_size"); ok {
@@ -1665,6 +1754,10 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
req.ForceStop = forceStop.(bool)
}
if osVersion, ok := d.GetOk("os_version"); ok {
req.OSVersion = osVersion.(string)
}
_, err := c.CloudAPI().Compute().Redeploy(ctx, req)
if err != nil {
return diag.FromErr(err)
@@ -1758,6 +1851,18 @@ func isRenameDisk(els []interface{}, el interface{}) bool {
return false
}
func isChangeStoragePolicy(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
elConv := el.(map[string]interface{})
if elOldConv["disk_id"].(int) == elConv["disk_id"].(int) &&
elOldConv["storage_policy_id"].(int) != elConv["storage_policy_id"].(int) {
return true
}
}
return false
}
func isContainsDisk(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
@@ -1848,6 +1953,11 @@ func disksSubresourceSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Disk size in GiB",
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "Storage policy id of disk. The rules of the specified storage policy will be used.",
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
@@ -1908,6 +2018,10 @@ func disksSubresourceSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
}
return rets
}
@@ -2002,14 +2116,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
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{"KVM_X86"}, false), // observe case while validating
Description: "Hardware architecture of this compute instance.",
},
"cpu": {
Type: schema.TypeInt,
Required: true,
@@ -2025,6 +2131,11 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
),
Description: "Amount of RAM in MB to allocate to this compute instance.",
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "Storage policy id of compute. The rules of the specified storage policy will be used.",
},
"boot_type": {
Type: schema.TypeString,
Optional: true,
@@ -2158,6 +2269,10 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Schema: disksSubresourceSchemaMake(),
},
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
@@ -2377,6 +2492,46 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Description: "ID of the connected pci devices",
},
"security_groups": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"net_type": {
Type: schema.TypeString,
Required: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"VINS", "EXTNET", "VFNIC", "DPDK", "SDN", "TRUNK"}, false), // observe case while validating
Description: "Type of the network",
},
"net_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the network",
},
"security_groups": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"enable_secgroups": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
Description: "list of security group IDs to apply to this interface",
},
"os_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "the OS version installed on the VM",
},
// The rest are Compute properties, which are "computed" once it is created
"account_id": {
Type: schema.TypeInt,
@@ -2451,6 +2606,10 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"driver": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
@@ -2701,7 +2860,7 @@ func ResourceCompute() *schema.Resource {
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
if diff.HasChanges() || diff.HasChanges("chipset", "pin_to_stack", "auto_start_w_node", "network", "affinity_rules", "anti_affinity_rules",
"extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices", "preferred_cpu") {
"extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices", "preferred_cpu", "security_groups") {
diff.SetNewComputed("updated_time")
diff.SetNewComputed("updated_by")
}

View File

@@ -34,10 +34,13 @@ package kvmvm
import (
"context"
"errors"
"fmt"
"regexp"
"sort"
"strconv"
"github.com/hashicorp/go-cty/cty"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
@@ -164,13 +167,13 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
oldList := oldSet.(*schema.Set).List()
newList := newSet.(*schema.Set).List()
detachMap, changeIpMap, changeMacMap, changeMTUMap, attachMap := differenceNetwork(oldList, newList)
updateNetwork := differenceNetwork(oldList, newList)
apiErrCount := 0
var lastSavedError error
log.Debugf("utilityComputeNetworksConfigure: detach set has %d items for Compute ID %s", len(detachMap), d.Id())
for _, netData := range detachMap {
log.Debugf("utilityComputeNetworksConfigure: detach set has %d items for Compute ID %s", len(updateNetwork.DetachMap), d.Id())
for _, netData := range updateNetwork.DetachMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.NetDetachRequest{
ComputeID: computeId,
@@ -187,8 +190,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeIp set has %d items for Compute ID %s", len(changeIpMap), d.Id())
for _, netData := range changeIpMap {
log.Debugf("utilityComputeNetworksConfigure: changeIp set has %d items for Compute ID %s", len(updateNetwork.ChangeIPMap), d.Id())
for _, netData := range updateNetwork.ChangeIPMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeIPRequest{
ComputeID: computeId,
@@ -208,7 +211,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
needStart := false
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 || hasDPDKnetwork(attachMap) || len(changeMacMap) != 0 {
if oldSet.(*schema.Set).Len() == len(updateNetwork.DetachMap) || oldSet.(*schema.Set).Len() == 0 || hasDPDKnetwork(updateNetwork.AttachMap) || len(updateNetwork.ChangeMacMap) != 0 {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
if err := utilityComputeStop(ctx, computeId, m); err != nil {
apiErrCount++
@@ -219,8 +222,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeMac set has %d items for Compute ID %s", len(changeMacMap), d.Id())
for _, netData := range changeMacMap {
log.Debugf("utilityComputeNetworksConfigure: changeMac set has %d items for Compute ID %s", len(updateNetwork.ChangeMacMap), d.Id())
for _, netData := range updateNetwork.ChangeMacMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeMACRequest{
ComputeID: computeId,
@@ -237,9 +240,9 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
sort.Slice(attachMap, func(i, j int) bool {
weightI := attachMap[i]["weight"].(int)
weightJ := attachMap[j]["weight"].(int)
sort.Slice(updateNetwork.AttachMap, func(i, j int) bool {
weightI := updateNetwork.AttachMap[i]["weight"].(int)
weightJ := updateNetwork.AttachMap[j]["weight"].(int)
if weightI == 0 {
return false
}
@@ -249,8 +252,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
return weightI < weightJ
})
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", len(attachMap), d.Id())
for _, netData := range attachMap {
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", len(updateNetwork.AttachMap), d.Id())
for _, netData := range updateNetwork.AttachMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.NetAttachRequest{
ComputeID: computeId,
@@ -270,7 +273,11 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
req.SDNInterfaceID = netData["sdn_interface_id"].(string)
}
if req.NetType == "DPDK" {
if enabledNetwork(d.GetRawConfig().GetAttr("network"), req.NetID, req.NetType) {
req.Enabled = netData["enabled"].(bool)
}
if req.NetType == "DPDK" || req.NetType == "EXTNET" {
req.MTU = uint64(netData["mtu"].(int))
}
@@ -291,8 +298,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeMTU set has %d items for Compute ID %s", len(changeMTUMap), d.Id())
for _, netData := range changeMTUMap {
log.Debugf("utilityComputeNetworksConfigure: changeMTU set has %d items for Compute ID %s", len(updateNetwork.ChangeMTUMap), d.Id())
for _, netData := range updateNetwork.ChangeMTUMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeMTURequest{
ComputeID: computeId,
@@ -309,6 +316,28 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: enableMap set has %d items for Compute ID %s", len(updateNetwork.EnableMap), d.Id())
for _, netData := range updateNetwork.EnableMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeLinkStateRequest{
ComputeID: computeId,
Interface: netData["mac"].(string),
State: "off",
}
if netData["enabled"].(bool) {
req.State = "on"
}
_, err := c.CloudAPI().Compute().ChangeLinkState(ctx, req)
if err != nil {
log.Errorf("utilityComputeNetworksConfigure: failed to change link state network ID %d of type %s from Compute ID %s: %s",
netData["net_id"].(int), netData["net_type"].(string), d.Id(), err)
apiErrCount++
lastSavedError = err
}
}
if apiErrCount > 0 {
log.Errorf("utilityComputeNetworksConfigure: there were %d error(s) when managing networks of Compute ID %s. Last error was: %s",
apiErrCount, d.Id(), lastSavedError)
@@ -318,6 +347,75 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
return nil
}
func utilityComputeSecGroupsConfigure(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
simpleCompRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
apiErrCount := 0
var lastSavedError error
oldSecGroups, newSecGroups := d.GetChange("security_groups")
updateSecGroups := (newSecGroups.(*schema.Set).Difference(oldSecGroups.(*schema.Set))).List()
log.Debugf("utilityComputeSecGroupsConfigure: update security groups has %d items for Compute ID %s", len(updateSecGroups), d.Id())
if len(updateSecGroups) > 0 {
for _, elem := range updateSecGroups {
secGroupsMap := elem.(map[string]interface{})
netType := secGroupsMap["net_type"].(string)
netId := uint64(secGroupsMap["net_id"].(int))
var mac string
for _, iface := range simpleCompRec.Interfaces {
if iface.NetID == netId && iface.NetType == netType {
mac = iface.MAC
break
}
}
if mac == "" {
log.Errorf("utilityComputeSecGroupsConfigure: Network with type %s and id %d is not connected to the compute %s",
netType, netId, d.Id())
apiErrCount++
lastSavedError = errors.New(fmt.Sprintf("utilityComputeSecGroupsConfigure: Network with type %s and id %d is not connected to the compute %s",
netType, netId, d.Id()))
continue
}
secGroupsIDs := make([]uint64, 0)
for _, id := range secGroupsMap["security_groups"].(*schema.Set).List() {
secGroupsIDs = append(secGroupsIDs, uint64(id.(int)))
}
log.Debugf("utilityComputeSecGroupsConfigure: Configure security groups interface parameters on Network with type %s and id %d", netType, netId)
req := compute.ChangeSecGroupsRequest{
ComputeID: computeId,
Interface: mac,
SecGroups: secGroupsIDs,
}
if secGroupsMap["enable_secgroups"] != nil {
req.EnableSecGroups = secGroupsMap["enable_secgroups"].(bool)
}
_, err := c.CloudAPI().Compute().ChangeSecGroups(ctx, req)
if err != nil {
apiErrCount++
lastSavedError = err
}
}
}
if apiErrCount > 0 {
log.Errorf("utilityComputeSecGroupsConfigure: there were %d error(s) when managing security groups of Compute ID %s. Last error was: %s",
apiErrCount, d.Id(), lastSavedError)
return lastSavedError
}
return nil
}
func hasDPDKnetwork(networkAttachMap []map[string]interface{}) bool {
for _, elem := range networkAttachMap {
if elem["net_type"].(string) == "DPDK" {
@@ -407,12 +505,13 @@ func utilityComputeUpdatePciDevices(ctx context.Context, d *schema.ResourceData,
return nil
}
func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap, changeMacMap, changeMTUMap, attachMap []map[string]interface{}) {
attachMap = make([]map[string]interface{}, 0)
changeIpMap = make([]map[string]interface{}, 0)
changeMacMap = make([]map[string]interface{}, 0)
changeMTUMap = make([]map[string]interface{}, 0)
detachMap = make([]map[string]interface{}, 0)
func differenceNetwork(oldList, newList []interface{}) *updatedNetwork {
attachMap := make([]map[string]interface{}, 0)
changeIpMap := make([]map[string]interface{}, 0)
changeMacMap := make([]map[string]interface{}, 0)
changeMTUMap := make([]map[string]interface{}, 0)
detachMap := make([]map[string]interface{}, 0)
enableMap := make([]map[string]interface{}, 0)
for _, oldNetwork := range oldList {
oldMap := oldNetwork.(map[string]interface{})
found := false
@@ -430,6 +529,13 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "DPDK") && (newMap["mtu"] != oldMap["mtu"] && newMap["mtu"].(int) != 0) {
changeMTUMap = append(changeMTUMap, newMap)
}
if newMap["enabled"].(bool) != oldMap["enabled"].(bool) {
mac, _ := newMap["mac"].(string)
if mac == "" {
newMap["mac"] = oldMap["mac"]
}
enableMap = append(enableMap, newMap)
}
}
if found {
break
@@ -457,7 +563,16 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
attachMap = append(attachMap, newMap)
}
return
res := updatedNetwork{
DetachMap: detachMap,
ChangeIPMap: changeIpMap,
ChangeMacMap: changeMacMap,
ChangeMTUMap: changeMTUMap,
AttachMap: attachMap,
EnableMap: enableMap,
}
return &res
}
func compareNetwork(newMap, oldMap map[string]interface{}) bool {
@@ -485,3 +600,25 @@ func utilityComputeUpdateZoneID(ctx context.Context, d *schema.ResourceData, m i
return nil
}
func enabledNetwork(rawNetworkConfig cty.Value, netID uint64, netType string) bool {
for _, netConfigVal := range rawNetworkConfig.AsValueSlice() {
if netConfigVal.IsNull() {
continue
}
netConfig := netConfigVal.AsValueMap()
tempID, _ := netConfig["net_id"].AsBigFloat().Int64()
configNetID := uint64(tempID)
configNetType := netConfig["net_type"].AsString()
if configNetID == netID && configNetType == netType {
enabledVal := netConfig["enabled"]
return !enabledVal.IsNull()
}
}
return false
}

View File

@@ -45,10 +45,37 @@ func utilityComputeAuditsCheckPresence(ctx context.Context, d *schema.ResourceDa
req := compute.AuditsRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
}
if timestampAt, ok := d.GetOk("timestamp_at"); ok {
req.TimestampAT = uint64(timestampAt.(int))
}
if timestampTo, ok := d.GetOk("timestamp_to"); ok {
req.TimestampTO = uint64(timestampTo.(int))
}
if user, ok := d.GetOk("user"); ok {
req.User = user.(string)
}
if call, ok := d.GetOk("call"); ok {
req.Call = call.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if minStatusCode, ok := d.GetOk("min_status_code"); ok {
req.MinStatusCode = uint64(minStatusCode.(int))
}
if maxStatusCode, ok := d.GetOk("max_status_code"); ok {
req.MaxStatusCode = uint64(maxStatusCode.(int))
}
computeAudits, err := c.CloudAPI().Compute().Audits(ctx, req)
if err != nil {
return nil, err
return compute.ListAudits{}, err
}
return computeAudits, nil
return *computeAudits, nil
}

View File

@@ -86,6 +86,9 @@ func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.Resource
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
listComputes, err := c.CloudAPI().Compute().List(ctx, req)
if err != nil {