Open vlad666 opened 2 weeks ago
Could you elaborate on your test steps that can help reproduce the issue?
This is my main.tf:
locals {
env_vars = { for tuple in regexall("export\\s*(\\S*)\\s*=\\s*(\\S*)\\s*", file(".env")) : tuple[0] => tuple[1] }
}
terraform {
required_providers {
xenserver = {
source = "xenserver/xenserver"
}
}
}
provider "xenserver" {
host = local.env_vars["XENSERVER_HOST"]
username = local.env_vars["XENSERVER_USERNAME"]
password = local.env_vars["XENSERVER_PASSWORD"]
}
data "xenserver_sr" "sr" {
name_label = "PROD119_NFS16_ST12"
}
### resource "xenserver_vdi" "vdi0" {
### name_label = "core-gitlab-runner-docker-dc6-mad_root"
### sr_uuid = data.xenserver_sr.sr.data_items[0].uuid
### virtual_size = 25 * 1024 * 1024 * 1024
### type = "system"
### }
data "xenserver_network" "network" {
name_label = "PRO-PUB-SERVICIOS-CORE"
}
resource "xenserver_vm" "vm" {
name_label = local.env_vars["VMNAME"]
template_name = local.env_vars["TEMPLATE_NAME"]
static_mem_max = 4 * 1024 * 1024 * 1024
vcpus = 4
cores_per_socket = 2
boot_order = "c"
boot_mode = "bios"
network_interface = [
{
device = "0"
network_uuid = data.xenserver_network.network.data_items[0].uuid,
},
]
other_config = {
"tf_created" = "true"
}
}
data "xenserver_vm" "vm" {
}
output "vm_out" {
value = data.xenserver_vm.vm.data_items[0].power_state
}
I execute all command:
terraform init
terraform plan
terraform apply
The vm is create and appears as "Running":
Outputs:
vm_out = "Running"
But is stopped:
Also we are trying to autoconfig network. My template have started getty@ttyS0 with autologin (as override)
Could you try using resource instead of data source here, please ref to the example of resource vm
output "vm_out" {
value = xenserver_vm.vm.power_state
}
Since you set the amount of resources and data sources in the main.tf, Terraform will process in parallel by using the -parallelism flag which defaults to 10.
You could set this to 1 and then Terraform will only process one resource at a time.
Your other option here would be to force Terraform to create dependencies between these resources by using the depends_on configuration block.
That failed.
But i don't need ouput, i need get my new vm powered on where there are created.
Try to query xenserver_vm data source with xenserver_vm.uuid or xenserver_vm.name_label. for example:
resource "xenserver_vm" "vm" {
name_label = "win11"
template_name = "Windows 11_Cus"
static_mem_max = 4294967296
vcpus = 2
network_interface = [
{
device = "0",
network_uuid = "42678ed0-18d1-9483-df1c-10cd632953d1",
mac = "9e:da:6e:5b:f5:30",
},
]
name_description = "VM created from custom template"
}
output "vm_out" {
value = xenserver_vm.vm
}
data "xenserver_vm" "vm" {
name_label = "win11"
}
output "vm_data_out" {
value = data.xenserver_vm.vm.data_items[0].power_state
}
The data source is added later after resource is created, we get
vm_data_out = "Halted"
vm_out = {
"boot_mode" = "uefi"
"boot_order" = "cd"
"cdrom" = ""
"check_ip_timeout" = 0
"cores_per_socket" = 2
"default_ip" = ""
"dynamic_mem_max" = 4294967296
"dynamic_mem_min" = 4294967296
"hard_drive" = toset([])
"id" = "8ae6f195-18e9-c341-c26f-80dfc604d861"
"name_description" = "VM created from custom template"
"name_label" = "win11"
"network_interface" = toset([
{
"device" = "0"
"mac" = "9e:da:6e:5b:f5:30"
"network_uuid" = "42678ed0-18d1-9483-df1c-10cd632953d1"
"other_config" = tomap({})
"vif_ref" = "OpaqueRef:1391144c-279e-1c92-9b5f-5b49c5d11039"
},
])
"other_config" = tomap({})
"static_mem_max" = 4294967296
"static_mem_min" = 4294967296
"template_name" = "Windows 11_Cus"
"uuid" = "8ae6f195-18e9-c341-c26f-80dfc604d861"
"vcpus" = 2
}
When created a VM not is power on. The VM is created. The data.xenserver_vm.X.data_items[0].power_state report it as "Running".
Why?