this hostnames.yml file corresponds to the following content:
hostnames:
- "shiloh"
- "cato"
When I run my terraform plan, I get the following error:
│ Error: Missing newline after argument
│
│ on variables.tf line 6, in variable "pm_target_node":
│ 6: default = "$yamldecode(file("hostnames.yml"))["hostnames"]"
│
│ An argument definition must end with a newline.
Following the instructions from the Terraform Docs for yamldecode, I dont see an option to present data as content from an array, which is what I want. In the end, I want the data shown in that variable to be injected into a vm generating resource for proxmox, like so:
It’s a weird error, but the first thing to do is to fix your incorrect syntax which might be causing it. You have a random extra "$ at the start and " at the end.
Hey @maxb, thank you for that input! You actually kinda solved my problem. Once I made the changes you recommended, it started throwing new and exciting errors at me, saying I can’t use functions within variables. What I did then is thrown those yamldecode functions directly into my terraform resources, and everything started working (with a bit of formatting). Id love to know why I can’t obfuscate it by keeping those yamldecode functions inside of variables, but I’m reasonably happy with the solution.
For those looking to solve a similar problem, here’s what my code looks like now within my resource file:
Input variables are for passing in data from outside rather than for specifying data inside your module. Terraform does allow specifying a default value but it must be a literal value because it exists primarily to tell the user of your module what value will be used if they don’t provide one.
If you want to factor out a complex expression and refer to its results in many places, that is what Local Values are for.