package schemas import ( "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/validate" ) func MakeSchemaResourceCompute() map[string]schema.Attribute { return map[string]schema.Attribute{ // required attributes "name": schema.StringAttribute{ Required: true, Description: "Name of this compute. Compute names are case sensitive and must be unique in the resource group.", }, "rg_id": schema.Int64Attribute{ Required: true, Validators: []validator.Int64{ int64validator.AtLeast(1), }, Description: "ID of the resource group where this compute should be deployed.", }, "driver": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("SVA_KVM_X86", "KVM_X86"), }, Description: "Hardware architecture of this compute instance.", }, "cpu": schema.Int64Attribute{ Required: true, Validators: []validator.Int64{ int64validator.Between(1, constants.MaxCpusPerCompute), }, Description: "Number of CPUs to allocate to this compute instance.", }, "ram": schema.Int64Attribute{ Required: true, Validators: []validator.Int64{ validate.DivisibleBy(constants.DivisibleByRAM), }, Description: "Amount of RAM in MB to allocate to this compute instance.", }, // optional attributes "image_id": schema.Int64Attribute{ Optional: true, Description: "ID of the OS image to base this compute instance on.", }, "without_boot_disk": schema.BoolAttribute{ //default false Optional: true, Description: "If True, the imageId, bootDisk, sepId, pool parameters are ignored and the compute is created without a boot disk in the stopped state.", }, "boot_disk_size": schema.Int64Attribute{ 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": schema.StringAttribute{ Optional: true, Computed: true, Description: "Set affinity label for compute", }, "affinity_rules": schema.SetNestedAttribute{ Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "topology": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("node", "compute"), }, Description: "compute or node, for whom rule applies", }, "policy": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("RECOMMENDED", "REQUIRED"), }, Description: "RECOMMENDED or REQUIRED, the degree of 'strictness' of this rule", }, "mode": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("EQ", "NE", "ANY"), }, Description: "EQ or NE or ANY - the comparison mode is 'value', recorded by the specified 'key'", }, "key": schema.StringAttribute{ Required: true, Description: "key that are taken into account when analyzing this rule will be identified", }, "value": schema.StringAttribute{ Optional: true, Description: "value that must match the key to be taken into account when analyzing this rule", }, }, }, }, "anti_affinity_rules": schema.SetNestedAttribute{ Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "topology": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("node", "compute"), }, Description: "compute or node, for whom rule applies", }, "policy": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("RECOMMENDED", "REQUIRED"), }, Description: "RECOMMENDED or REQUIRED, the degree of 'strictness' of this rule", }, "mode": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("EQ", "NE", "ANY"), }, Description: "EQ or NE or ANY - the comparison mode is 'value', recorded by the specified 'key'", }, "key": schema.StringAttribute{ Required: true, Description: "key that are taken into account when analyzing this rule will be identified", }, "value": schema.StringAttribute{ Optional: true, Description: "value that must match the key to be taken into account when analyzing this rule", }, }, }, }, "custom_fields": schema.StringAttribute{ Optional: true, Computed: true, Description: "custom fields for Compute. Must be dict", }, "stateless": schema.BoolAttribute{ //default false Optional: true, Description: "Compute will be stateless (SVA_KVM_X86) if set to True", }, "sep_id": schema.Int64Attribute{ Optional: true, Computed: true, Description: "ID of SEP to create bootDisk on. Uses image's sepId if not set.", }, "pool": schema.StringAttribute{ Optional: true, Computed: true, Description: "Pool to use if sepId is set, can be also empty if needed to be chosen by system.", }, "extra_disks": schema.SetAttribute{ Optional: true, //Computed: true, Validators: []validator.Set{ setvalidator.SizeAtMost(constants.MaxExtraDisksPerCompute), }, ElementType: types.Int64Type, Description: "Optional list of IDs of extra disks to attach to this compute. You may specify several extra disks.", }, "network": schema.SetNestedAttribute{ Optional: true, Computed: true, Validators: []validator.Set{ setvalidator.SizeBetween(1, constants.MaxNetworksPerCompute), }, Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.", NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "net_type": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("EXTNET", "VINS", "VFNIC", "DPDK"), }, Description: "Type of the network for this connection, either EXTNET or VINS.", }, "net_id": schema.Int64Attribute{ Required: true, Description: "ID of the network for this connection.", }, "ip_address": schema.StringAttribute{ Optional: true, Computed: true, Description: "Optional IP address to assign to this connection. This IP should belong to the selected network and free for use.", }, "mac": schema.StringAttribute{ Computed: true, Description: "MAC address associated with this connection. MAC address is assigned automatically.", }, "weight": schema.Int64Attribute{ Optional: true, Computed: true, Description: "Weight the network if you need to sort network list, the smallest attach first. zero or null weight attach last", }, "mtu": schema.Int64Attribute{ Optional: true, Computed: true, Validators: []validator.Int64{ int64validator.Between(1, 9216), }, Description: "Maximum transmission unit, used only for DPDK type, must be 1-9216", }, }, }, }, "tags": schema.SetNestedAttribute{ Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "key": schema.StringAttribute{ Required: true, }, "value": schema.StringAttribute{ Required: true, }, }, }, }, "port_forwarding": schema.SetNestedAttribute{ Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "public_port_start": schema.Int64Attribute{ Required: true, }, "public_port_end": schema.Int64Attribute{ Optional: true, //Default: -1, }, "local_port": schema.Int64Attribute{ Optional: true, }, "proto": schema.StringAttribute{ Required: true, Validators: []validator.String{ stringvalidator.OneOf("tcp", "udp"), }, }, }, }, }, "user_access": schema.SetNestedAttribute{ Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "username": schema.StringAttribute{ Required: true, }, "access_type": schema.StringAttribute{ Required: true, }, }, }, }, "snapshot": schema.SetNestedAttribute{ Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "label": schema.StringAttribute{ Required: true, }, }, }, }, "rollback": schema.SingleNestedAttribute{ Optional: true, Attributes: map[string]schema.Attribute{ "label": schema.StringAttribute{ Required: true, }, }, }, "cd": schema.SingleNestedAttribute{ Optional: true, Attributes: map[string]schema.Attribute{ "cdrom_id": schema.Int64Attribute{ Required: true, }, }, }, "pin_to_stack": schema.BoolAttribute{ Optional: true, Computed: true, Default: booldefault.StaticBool(false), }, "description": schema.StringAttribute{ Optional: true, Computed: true, Description: "Optional text description of this compute instance.", }, "cloud_init": schema.StringAttribute{ Optional: true, Description: "Optional cloud_init parameters. Applied when creating new compute instance only, ignored in all other cases.", }, "enabled": schema.BoolAttribute{ Optional: true, Computed: true, Default: booldefault.StaticBool(true), Description: "If true - enable compute, else - disable", }, "pause": schema.BoolAttribute{ Optional: true, //Default: false, }, "reset": schema.BoolAttribute{ Optional: true, //Default: false, }, "restore": schema.BoolAttribute{ Optional: true, Computed: true, Default: booldefault.StaticBool(true), //Default: true, }, "auto_start": schema.BoolAttribute{ Optional: true, //Default: false, Description: "Flag for redeploy compute", }, "force_stop": schema.BoolAttribute{ Optional: true, //Default: false, Description: "Flag for redeploy compute", }, "force_resize": schema.BoolAttribute{ Optional: true, //Default: false, Description: "Flag for resize compute", }, "data_disks": schema.StringAttribute{ Optional: true, Validators: []validator.String{ stringvalidator.OneOf("KEEP", "DETACH", "DESTROY"), }, //Default: "DETACH", Description: "Flag for redeploy compute", }, "started": schema.BoolAttribute{ Optional: true, Computed: true, Default: booldefault.StaticBool(true), Description: "Is compute started.", }, "detach_disks": schema.BoolAttribute{ Optional: true, Computed: true, Default: booldefault.StaticBool(true), }, "permanently": schema.BoolAttribute{ Optional: true, Computed: true, Default: booldefault.StaticBool(true), }, "is": schema.StringAttribute{ Optional: true, Description: "system name", }, "ipa_type": schema.StringAttribute{ Optional: true, Description: "compute purpose", }, "numa_affinity": schema.StringAttribute{ Optional: true, Validators: []validator.String{ stringvalidator.OneOf("none", "strict", "loose"), }, //Default: "none", Description: "Rule for VM placement with NUMA affinity.", }, "cpu_pin": schema.BoolAttribute{ Optional: true, Computed: true, Default: booldefault.StaticBool(false), Description: "Run VM on dedicated CPUs. To use this feature, the system must be pre-configured by allocating CPUs on the physical node.", }, "hp_backed": schema.BoolAttribute{ Optional: true, Computed: true, Default: booldefault.StaticBool(false), Description: "Use Huge Pages to allocate RAM of the virtual machine. The system must be pre-configured by allocating Huge Pages on the physical node.", }, "pci_devices": schema.SetAttribute{ Optional: true, ElementType: types.Int64Type, Description: "ID of the connected pci devices", }, "chipset": schema.StringAttribute{ Optional: true, Computed: true, Validators: []validator.String{ stringvalidator.OneOf("i440fx", "Q35"), }, Description: "Type of the emulated system, Q35 or i440fx", }, "auto_start_w_node": schema.BoolAttribute{ Optional: true, Computed: true, Description: "Flag for start compute after node exits from MAINTENANCE state", Default: booldefault.StaticBool(false), }, // computed attributes "compute_id": schema.Int64Attribute{ Computed: true, }, "boot_disk": schema.SingleNestedAttribute{ Computed: true, Attributes: MakeSchemaResourceComputeDisks(), }, // computed attributes "id": schema.StringAttribute{ Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), }, }, "account_id": schema.Int64Attribute{ Computed: true, }, "account_name": schema.StringAttribute{ Computed: true, }, "acl": schema.SingleNestedAttribute{ Computed: true, Attributes: map[string]schema.Attribute{ "account_acl": schema.ListNestedAttribute{ Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "explicit": schema.BoolAttribute{ Computed: true, }, "guid": schema.StringAttribute{ Computed: true, }, "right": schema.StringAttribute{ Computed: true, }, "status": schema.StringAttribute{ Computed: true, }, "type": schema.StringAttribute{ Computed: true, }, "user_group_id": schema.StringAttribute{ Computed: true, }, }, }, }, "compute_acl": schema.ListNestedAttribute{ Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "explicit": schema.BoolAttribute{ Computed: true, }, "guid": schema.StringAttribute{ Computed: true, }, "right": schema.StringAttribute{ Computed: true, }, "status": schema.StringAttribute{ Computed: true, }, "type": schema.StringAttribute{ Computed: true, }, "user_group_id": schema.StringAttribute{ Computed: true, }, }, }, }, "rg_acl": schema.ListNestedAttribute{ Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "explicit": schema.BoolAttribute{ Computed: true, }, "guid": schema.StringAttribute{ Computed: true, }, "right": schema.StringAttribute{ Computed: true, }, "status": schema.StringAttribute{ Computed: true, }, "type": schema.StringAttribute{ Computed: true, }, "user_group_id": schema.StringAttribute{ Computed: true, }, }, }, }, }, }, "affinity_weight": schema.Int64Attribute{ Computed: true, }, "arch": schema.StringAttribute{ Computed: true, }, "boot_order": schema.ListAttribute{ Computed: true, ElementType: types.StringType, }, "boot_disk_id": schema.Int64Attribute{ Computed: true, }, "cd_image_id": schema.Int64Attribute{ Computed: true, }, "clone_reference": schema.Int64Attribute{ Computed: true, }, "clones": schema.ListAttribute{ Computed: true, ElementType: types.Int64Type, }, "computeci_id": schema.Int64Attribute{ Computed: true, }, "created_by": schema.StringAttribute{ Computed: true, }, "created_time": schema.Int64Attribute{ Computed: true, }, "deleted_by": schema.StringAttribute{ Computed: true, }, "deleted_time": schema.Int64Attribute{ Computed: true, }, "devices": schema.StringAttribute{ Computed: true, }, "disks": schema.ListNestedAttribute{ Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: MakeSchemaResourceComputeDisks(), }, }, "gid": schema.Int64Attribute{ Computed: true, }, "guid": schema.Int64Attribute{ Computed: true, }, "image_name": schema.StringAttribute{ Computed: true, }, "interfaces": schema.ListNestedAttribute{ Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "bus_number": schema.Int64Attribute{ Computed: true, }, "conn_id": schema.Int64Attribute{ Computed: true, }, "conn_type": schema.StringAttribute{ Computed: true, }, "get_gw": schema.StringAttribute{ Computed: true, }, "enabled": schema.BoolAttribute{ Computed: true, }, "flip_group_id": schema.Int64Attribute{ Computed: true, }, "guid": schema.StringAttribute{ Computed: true, }, "ip_address": schema.StringAttribute{ Computed: true, }, "listen_ssh": schema.BoolAttribute{ Computed: true, }, "mac": schema.StringAttribute{ Computed: true, }, "mtu": schema.Int64Attribute{ Computed: true, }, "name": schema.StringAttribute{ Computed: true, }, "net_id": schema.Int64Attribute{ Computed: true, }, "netmask": schema.Int64Attribute{ Computed: true, }, "net_type": schema.StringAttribute{ Computed: true, }, "node_id": schema.Int64Attribute{ Computed: true, }, "pci_slot": schema.Int64Attribute{ Computed: true, }, "qos": schema.SingleNestedAttribute{ Computed: true, Attributes: map[string]schema.Attribute{ "e_rate": schema.Int64Attribute{ Computed: true, }, "guid": schema.StringAttribute{ Computed: true, }, "in_burst": schema.Int64Attribute{ Computed: true, }, "in_rate": schema.Int64Attribute{ Computed: true, }, }, }, "libvirt_settings": schema.SingleNestedAttribute{ Computed: true, Attributes: map[string]schema.Attribute{ "guid": schema.StringAttribute{ Computed: true, }, "txmode": schema.StringAttribute{ Computed: true, }, "ioeventfd": schema.StringAttribute{ Computed: true, }, "event_idx": schema.StringAttribute{ Computed: true, }, "queues": schema.Int64Attribute{ Computed: true, }, "rx_queue_size": schema.Int64Attribute{ Computed: true, }, "tx_queue_size": schema.Int64Attribute{ Computed: true, }, }, }, "target": schema.StringAttribute{ Computed: true, }, "type": schema.StringAttribute{ Computed: true, }, "vnfs": schema.ListAttribute{ Computed: true, ElementType: types.Int64Type, }, }, }, }, "lock_status": schema.StringAttribute{ Computed: true, }, "manager_id": schema.Int64Attribute{ Computed: true, }, "manager_type": schema.StringAttribute{ Computed: true, }, "migrationjob": schema.Int64Attribute{ Computed: true, }, "milestones": schema.Int64Attribute{ Computed: true, }, "need_reboot": schema.BoolAttribute{ Computed: true, }, "numa_node_id": schema.Int64Attribute{ Computed: true, }, "natable_vins_id": schema.Int64Attribute{ Computed: true, }, "natable_vins_ip": schema.StringAttribute{ Computed: true, }, "natable_vins_name": schema.StringAttribute{ Computed: true, }, "natable_vins_network": schema.StringAttribute{ Computed: true, }, "natable_vins_network_name": schema.StringAttribute{ Computed: true, }, "os_users": schema.ListNestedAttribute{ Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "guid": schema.StringAttribute{ Computed: true, }, "login": schema.StringAttribute{ Computed: true, }, "password": schema.StringAttribute{ Computed: true, }, "public_key": schema.StringAttribute{ Computed: true, }, }, }, }, "pinned": schema.BoolAttribute{ Computed: true, }, "reference_id": schema.StringAttribute{ Computed: true, }, "registered": schema.BoolAttribute{ Computed: true, }, "res_name": schema.StringAttribute{ Computed: true, }, "reserved_node_cpus": schema.ListAttribute{ Computed: true, ElementType: types.Int64Type, }, "rg_name": schema.StringAttribute{ Computed: true, }, "snap_sets": schema.ListNestedAttribute{ Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "disks": schema.ListAttribute{ Computed: true, ElementType: types.Int64Type, }, "guid": schema.StringAttribute{ Computed: true, }, "label": schema.StringAttribute{ Computed: true, }, "timestamp": schema.Int64Attribute{ Computed: true, }, }, }, }, "stateless_sep_id": schema.Int64Attribute{ Computed: true, }, "stateless_sep_type": schema.StringAttribute{ Computed: true, }, "status": schema.StringAttribute{ Computed: true, }, "tech_status": schema.StringAttribute{ Computed: true, }, "updated_by": schema.StringAttribute{ Computed: true, }, "updated_time": schema.Int64Attribute{ Computed: true, }, "user_data": schema.StringAttribute{ Computed: true, }, "user_managed": schema.BoolAttribute{ Computed: true, }, "vgpus": schema.ListAttribute{ Computed: true, ElementType: types.Int64Type, }, "virtual_image_id": schema.Int64Attribute{ Computed: true, }, "virtual_image_name": schema.StringAttribute{ Computed: true, }, "vnc_password": schema.StringAttribute{ Computed: true, }, } } func MakeSchemaResourceComputeDisks() map[string]schema.Attribute { return map[string]schema.Attribute{ "ckey": schema.StringAttribute{ Computed: true, }, "acl": schema.StringAttribute{ Computed: true, }, "account_id": schema.Int64Attribute{ Computed: true, }, "boot_partition": schema.Int64Attribute{ Computed: true, }, "bus_number": schema.Int64Attribute{ Computed: true, }, "created_time": schema.Int64Attribute{ Computed: true, }, "deleted_time": schema.Int64Attribute{ Computed: true, }, "desc": schema.StringAttribute{ Computed: true, }, "destruction_time": schema.Int64Attribute{ Computed: true, }, "disk_path": schema.StringAttribute{ Computed: true, }, "gid": schema.Int64Attribute{ Computed: true, }, "guid": schema.Int64Attribute{ Computed: true, }, "disk_id": schema.Int64Attribute{ Computed: true, }, "image_id": schema.Int64Attribute{ Computed: true, }, "images": schema.ListAttribute{ Computed: true, ElementType: types.StringType, }, "iotune": schema.SingleNestedAttribute{ Computed: true, Attributes: map[string]schema.Attribute{ "read_bytes_sec": schema.Int64Attribute{ Computed: true, }, "read_bytes_sec_max": schema.Int64Attribute{ Computed: true, }, "read_iops_sec": schema.Int64Attribute{ Computed: true, }, "read_iops_sec_max": schema.Int64Attribute{ Computed: true, }, "size_iops_sec": schema.Int64Attribute{ Computed: true, }, "total_bytes_sec": schema.Int64Attribute{ Computed: true, }, "total_bytes_sec_max": schema.Int64Attribute{ Computed: true, }, "total_iops_sec": schema.Int64Attribute{ Computed: true, }, "total_iops_sec_max": schema.Int64Attribute{ Computed: true, }, "write_bytes_sec": schema.Int64Attribute{ Computed: true, }, "write_bytes_sec_max": schema.Int64Attribute{ Computed: true, }, "write_iops_sec": schema.Int64Attribute{ Computed: true, }, "write_iops_sec_max": schema.Int64Attribute{ Computed: true, }, }, }, "iqn": schema.StringAttribute{ Computed: true, }, "login": schema.StringAttribute{ Computed: true, }, "milestones": schema.Int64Attribute{ Computed: true, }, "name": schema.StringAttribute{ Computed: true, }, "order": schema.Int64Attribute{ Computed: true, }, "params": schema.StringAttribute{ Computed: true, }, "parent_id": schema.Int64Attribute{ Computed: true, }, "passwd": schema.StringAttribute{ Computed: true, }, "pci_slot": schema.Int64Attribute{ Computed: true, }, "pool": schema.StringAttribute{ Computed: true, }, "present_to": schema.ListAttribute{ Computed: true, ElementType: types.Int64Type, }, "purge_time": schema.Int64Attribute{ Computed: true, }, "replication": schema.SingleNestedAttribute{ Computed: true, Attributes: map[string]schema.Attribute{ "disk_id": schema.Int64Attribute{ Computed: true, }, "pool_id": schema.StringAttribute{ Computed: true, }, "role": schema.StringAttribute{ Computed: true, }, "self_volume_id": schema.StringAttribute{ Computed: true, }, "storage_id": schema.StringAttribute{ Computed: true, }, "volume_id": schema.StringAttribute{ Computed: true, }, }, }, "reality_device_number": schema.Int64Attribute{ Computed: true, }, "reference_id": schema.StringAttribute{ Computed: true, }, "res_id": schema.StringAttribute{ Computed: true, }, "role": schema.StringAttribute{ Computed: true, }, "sep_id": schema.Int64Attribute{ Computed: true, }, "shareable": schema.BoolAttribute{ Computed: true, }, "size_max": schema.Int64Attribute{ Computed: true, }, "size_used": schema.Float64Attribute{ Computed: true, }, "snapshots": schema.ListNestedAttribute{ Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "guid": schema.StringAttribute{ Computed: true, }, "label": schema.StringAttribute{ Computed: true, }, "reference_id": schema.StringAttribute{ Computed: true, }, "res_id": schema.StringAttribute{ Computed: true, }, "snap_set_guid": schema.StringAttribute{ Computed: true, }, "snap_set_time": schema.Int64Attribute{ Computed: true, }, "timestamp": schema.Int64Attribute{ Computed: true, }, }, }, }, "status": schema.StringAttribute{ Computed: true, }, "tech_status": schema.StringAttribute{ Computed: true, }, "type": schema.StringAttribute{ Computed: true, }, "vmid": schema.Int64Attribute{ Computed: true, }, } }