-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ansible_host vars dictionary can't handle arrays #13
Comments
After some further thought, it occurs to me that supporting arrays still doesn't allow for complex objects, and lists of complex objects. It might make more sense to have a mechanism whereby the dynamic inventory script will read the String field as raw YAML. |
Terraform has a native
This is a good idea as well - doing the opposite of the above and pushing the complexity back to the user. If you go this route, it would make sense to also consider a There's a lot of precedence for embedding JSON into Terraform resources. It's an acceptable method, but it's looked as a last resort. The Terraform team is working on HCL 2 which might resolve this issue. Personally I like the individual resources. Several small resources allow for greater flexibility in the long run. Larger individual resources with lots of functionality always become complicated to manage. Another benefit of the individual resources is that if this issue is natively fixed upstream in the future, the individual resources can be slowly deprecated and removed. |
Whatever the solution is, the inventory script/plugin will need to understand that the value it is passing needs to be encoded as json/yaml structures and not a string. I'm not an expert Go programmer by any means, and there could be tricks to work around Terraform's type contract limitations... but I think embedding JSON/YAML as a string or Heredoc is probably the most flexible way to complete this task. Validation might be a bit of an issue. It might be worth the time to find a JSON/YAML validator library in Go to ensure the value is valid before adding it to the tfstate file. That would avoid complex downstream errors, especially for anyone running in a operations pipeline configuration. |
Yes, true. My interpretation of using multiple resources (
This is a hard limitation with Terraform's current HCL implementation. Having the resource support a JSON-body-as-a-string is the common workaround at this time. I haven't yet seen a YAML implementation, but I think everything discussed about JSON can just as well be applied to YAML.
Yes, it is. From a data-modeling point of view, it's not the best solution since it treats a collection of data as a single unit. What I mean by this is that allowing free-form JSON/YAML would allow someone to also include This is why I like the multiple resource solution better, but I'm not opposed to the JSON/YAML input, either. I fully appreciate the simplicity of the free-form JSON solution and any other solution is to satisfy data structure nit-pickers 😄
This is actually pretty easy. I had to do this a few months ago with the Note how the schema definition of If you go this route, I think it would be best to have the argument named something like |
Thanks for the input! If I have time during the evening this week, I plan to tackle this. |
This one's an interesting edge case.
I wanted to pass an array of hostnames to a variable...
This received an error like this:
This might be one of those cases where the intersection of the Go and Terraform type systems are not going to do what I want.
I'm thinking about adding a resource along the lines of what I proposed in #4, but specifically to handle the array case. Maybe something like:
The text was updated successfully, but these errors were encountered: