Terraform state mv commands in powershell fail using names with spaces

We have an issue where when we try to move items using tf state mv with spaces it wil parse incorrectly in powershell.

As you can see below, the CLI interpets the space as a new item and fails the state mv call

If we run the command in command prompt with modified escaping it will work, we can’t find a good way to make it work in powershell.

Command in PS (fails)
terraform state mv ‘local_file.file[“b c”]’ ‘local_file.file[“e f”]’

Command in CMD
terraform state mv “local_file.file[“b c”]” “local_file.file[“e f”]”

Output

2020/06/14 23:59:22 [INFO] Terraform version: 0.12.23
2020/06/14 23:59:22 [INFO] Go runtime version: go1.12.13
2020/06/14 23:59:22 [INFO] CLI args: string{“C:\Windows\terraform.exe”, “state”, “mv”, “local_file.file[“b”, “c”]”, “local_file.file[“e”, “f”]”}
2020/06/14 23:59:22 [DEBUG] Attempting to open CLI config file: C:\Users\p120b60.CORPADDS\AppData\Roaming\terraform.rc
2020/06/14 23:59:22 [DEBUG] File doesn’t exist, but doesn’t need to. Ignoring.
2020/06/14 23:59:22 [INFO] CLI command args: string{“state”, “mv”, “local_file.file[“b”, “c”]”, “local_file.file[“e”, “f”]”}
Exactly two arguments expected.

main.tf
provider “azurerm” {

version = “=2.13.0”

skip_provider_registration = “true”

features {}

}

locals {

filenames = toset([“a”, “b c”])

}

terraform {

backend “local” {

path = "./terraformconfig.tfstate"

}

}

resource “local_file” “file” {

for_each = local.filenames

filename = each.value

}

TF version
Terraform v0.12.23

  • provider.azurerm v2.13.0
  • provider.local v1.4.0