Terraform – Argument names must not be quoted

terraform

I am using Terraform v0.12.6 and have run into an issue deploying OpenShift 4.1 on vSphere 6.5. When I run ./terraform apply, validate, or plan, I get the same response:

Error: Invalid argument name

  on machine/main.tf line 47, in resource "vsphere_virtual_machine" "vm":
  47:       "guestinfo.ignition.config.data"          = "${base64encode(data.ignition_config.ign.*.rendered[count.index])}"

Argument names must not be quoted.

I have tried to remove the quotes from line 47, but the error changes to something else. Assistance is greatly appreciated.

I am using the main.tf file from the following URL:
https://github.com/openshift/installer/blob/master/upi/vsphere/machine/main.tf

Best Answer

The root problem here is that this configuration is not using the correct syntax for the properties argument. It's an argument expecting a map value rather than a nested block, so it must be written this way:

  vapp {
    properties = {
      "guestinfo.ignition.config.data"          = "${base64encode(data.ignition_config.ign.*.rendered[count.index])}"
      "guestinfo.ignition.config.data.encoding" = "base64"
    }
  }

By assigning properties a map value, rather than using it as a nested block, Terraform can see that this is a map expression and thus know that quoted map keys are valid here. Inside nested blocks Terraform instead expects argument names, which are always required to be valid identifiers (letters, digits, underscores, and dashes only).

The file you referred to seems to be written for Terraform 0.11, and so it may have other situations where some changes are required for Terraform 0.12. If it's your module, consider running through the automatic upgrade process to update the syntax for Terraform 0.12 idiom and automatically fix many of the small differences in the new Terraform 0.12 language syntax. In particular, the automatic tool should automatically detect and fix the problem you encountered for this question.