Conditionals in Terraform

A conditional expression uses the value of a boolean expression to select one of two values.

For the main.tf, we will take the example of this EC2 instance provisioner and the modification Simple usage of variables in Terraform main.tf. Modify line:

interpreter = ["bash", "-c"]
to the:
interpreter = var.host_os == "windows" ? ["Powershell", "-Command"] : ["bash", "-c"]
To understand the expression, we will invoke the console with host_os=windows: if the host os is Windows, Powershell will be executed:
$ terraform console -var="host_os=windows"
> var.host_os == "windows" ? ["Powershell", "-Command"] : ["bash", "-c"]
[
  "Powershell",
  "-Command",
]
Otherwise (if linux)- bash:
$ terraform console -var="host_os=linux"
> var.host_os == "windows" ? ["Powershell", "-Command"] : ["bash", "-c"]
[
  "bash",
  "-c",
]
Test by running plan and apply. In my case I checked if the .ssh/config was created with the new ip