Would like to set a conditional statement where if true it sets the value from a variable. However, receiving the following error and not sure what I am doing wrong. Any suggestions are greatly appreciated.
Error:
terraform validate -var-file=variables.tfvars
Warning: The -var and -var-file flags are not used in validate. Setting them has no effect.
These flags will be removed in a future version of Terraform.
Warning: Interpolation-only expressions are deprecated
on resource.tf line 23, in resource "vsphere_folder" "vm_folder":
23: datacenter_id = "${data.vsphere_datacenter.dc.id}"
Terraform 0.11 and earlier required all non-constant expressions to be
provided via interpolation syntax, but this pattern is now deprecated. To
silence this warning, remove the "${ sequence from the start and the }"
sequence from the end of this expression, leaving just the inner expression.
Template interpolation syntax is still used to construct strings from
expressions when the template includes multiple interpolation sequences or a
mixture of literal strings and interpolations. This deprecation applies only
to templates that consist entirely of a single interpolation sequence.
(and 4 more similar warnings elsewhere)
Error: Invalid block definition
on resource.tf line 36, in resource "vsphere_virtual_machine" "vm":
36: if var.control {
Either a quoted string block label or an opening brace ("{") is expected here.
Resource configuration
resource "vsphere_virtual_machine" "vm" {
name = var.vmname
folder = "${vsphere_folder.vm_folder.path}"
resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = var.cpu
memory = var.memory
guest_id = var.guestid
if var.control {
ignition_config = var.control_ign
} else {
ignition_config = var.compute_ign
}
extra_config = {
"guestinfo.ignition.config.data" = "${var.ignition_config}"
"guestinfo.ignition.config.data.encoding" = "base64"
"disk.EnableUUID" = "True"
}
network_interface {
network_id = "${data.vsphere_network.network.id}"
}
disk {
label = "disk0"
size = var.disk_size
}
}