Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider does not create VM if notes property contains anything but ASCII #166

Open
silentirk opened this issue Oct 18, 2022 · 1 comment
Labels

Comments

@silentirk
Copy link

silentirk commented Oct 18, 2022

If .tf file (while being in UTF8 of course) contains something like:

resource "hyperv_machine_instance" "test-sph-m01" {
  provider = hyperv.test-hv26
  name = "test-sph-m01"
  generation = 2
  automatic_start_action = "Start"
  automatic_stop_action = "Shutdown"
  memory_startup_bytes = 4294967296
  static_memory = true
  **notes = "Сервер управления узлами кластера"**
...

than it seems that provider does not create VM and leaves not very helpful message:

│ Error: run command operation returned code=1
│ stderr:
│
│ stdOut:
│ Get-VMNetworkAdapter : Hyper-V was unable to find a virtual machine with name "tyngd-sph-m01".
│ At C:\Users\chudinovas_ia\AppData\Local\Temp\shell-terraform-2GIpTC1lNyb5yBJKI0HgoTQRldi.ps1:4 char:1
│ + Get-VMNetworkAdapter -VmName 'test-sph-m01' | Out-Null
│ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│     + CategoryInfo          : ObjectNotFound: (:) [Get-VMNetworkAdapter], VirtualizationException
│     + FullyQualifiedErrorId : ObjectNotFound,Microsoft.HyperV.PowerShell.Commands.GetVMNetworkAdapter
│
│   with hyperv_machine_instance.tyngd-sph-m01,
│   on test.tf line 36, in resource "hyperv_machine_instance" "test-sph-m01":
│   36: resource "hyperv_machine_instance" "test-sph-m01" {

with debug enabled I could see this just before previous message:

2022-10-18T17:39:16.871+0800 [WARN]  unexpected data: registry.terraform.io/taliesins/hyperv:stdout="At C:\Users\chudinovas_ia\AppData\Local\Temp\shell-terraform-2GIpSSMusUI5Ydz51sN3laF9Zle.ps1:4 char:525
+ ... с ђуђ>ђш‘?‘'ђз‘?ђш","ProcessorCount":2,"SmartPagingFilePath":"E:\\Hyp ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'ђз‘?ђш","ProcessorCount":2,"SmartPagingFilePath":"E:\\Hyper-V","SnapshotFileLocation":"E:\\Hyper-V","
StaticMemory":true}' | ConvertFrom-Json
$automaticCriticalErrorAction = [Microsoft.HyperV.PowerShell.CriticalErrorAction]$vm.AutomaticCriticalErrorAction
$automaticStartAction = [Microsoft.HyperV.PowerShell.StartAction]$vm.AutomaticStartAction
$automaticStopAction = [Microsoft.HyperV.PowerShell.StopAction]$vm.AutomaticStopAction
$checkpointType = [Microsoft.HyperV.PowerShell.CheckpointType]$vm.CheckpointType
$lockOnDisconnect = [Microsoft.HyperV.PowerShell.OnOffState]$vm.LockOnDisconnect
$allowUnverifiedPaths = $true #Not a property set on the vm object, skips validation when changing path
$vmObject = Get-VM -Name"
2022-10-18T17:39:16.873+0800 [WARN]  unexpected data: registry.terraform.io/taliesins/hyperv:stdout=""$($vm.Name)*" | ?{$_.Name -eq $vm.Name}
if ($vmObject){
        throw "VM' in expression or statement.
At C:\Users\chudinovas_ia\AppData\Local\Temp\shell-terraform-2GIpSSMusUI5Ydz51sN3laF9Zle.ps1:15 char:40
+     throw "VM already exists - $($vm.Name)"
+                                           ~
The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken"
2022-10-18T17:39:16.875+0800 [INFO]  provider.terraform-provider-hyperv_1.0.3.exe: 2022/10/18 17:39:16 [DEBUG] Shell execute result: exitCode=0 stdOut=At C:\Users\chudinovas_ia\AppData\Local\Temp\shell-terraform-2GIpSSMusUI5Ydz51sN3laF9Zle.ps1:4 char:525
+ ... с ђуђ>ђш‘?‘'ђз‘?ђш","ProcessorCount":2,"SmartPagingFilePath":"E:\\Hyp ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'ђз‘?ђш","ProcessorCount":2,"SmartPagingFilePath":"E:\\Hyper-V","SnapshotFileLocation":"E:\\Hyper-V","
StaticMemory":true}' | ConvertFrom-Json
$automaticCriticalErrorAction = [Microsoft.HyperV.PowerShell.CriticalErrorAction]$vm.AutomaticCriticalErrorAction
$automaticStartAction = [Microsoft.HyperV.PowerShell.StartAction]$vm.AutomaticStartAction
$automaticStopAction = [Microsoft.HyperV.PowerShell.StopAction]$vm.AutomaticStopAction
$checkpointType = [Microsoft.HyperV.PowerShell.CheckpointType]$vm.CheckpointType
$lockOnDisconnect = [Microsoft.HyperV.PowerShell.OnOffState]$vm.LockOnDisconnect
$allowUnverifiedPaths = $true #Not a property set on the vm object, skips validation when changing path
$vmObject = Get-VM -Name "$($vm.Name)*" | ?{$_.Name -eq $vm.Name}
if ($vmObject){
        throw "VM' in expression or statement.
At C:\Users\chudinovas_ia\AppData\Local\Temp\shell-terraform-2GIpSSMusUI5Ydz51sN3laF9Zle.ps1:15 char:40
+     throw "VM already exists - $($vm.Name)"
+                                           ~
The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken stdErr=: timestamp=2022-10-18T17:39:16.874+0800

The problem can probably be the same for some other properties like paths, but I did not check this.

@taliesins taliesins added the bug label Dec 15, 2022
@taliesins
Copy link
Owner

This might be a hard one to fix. There are a couple of fragile hoops to get powershell snippets generated on the client uploaded to the server (base64 encoding, winrm and task scheduler xml involved) and possible its not handling escaping of single quotes correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants