You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to Iterate Through A List of Objects with Terraform's for_each function - sheldonhull.com #84
@rtanner-tableau my apologies. I had my email notifications missing so didn't see this until now. Change users to user per the yaml above. I think that was a typo in my code example. See if that works if you still are experimenting with it.
Also for noting, I'll be trying this out soon when I have my next config project as I'm betting it's a lot more robust. Check this out from one of my all-time favorite terraform module creators.
Thanks Sheldon! for_each = {for ... trick is definitely an elegant solution to iterate over lists. Helped me to answer this SO question as well. Cheers!
@maximivanov stoked to hear that. I write to help myself remember these things that took so much effort and were hard to find clear answers on. I'm always cheered to know some else found it helpful! Thanks for the follow-up. 👍
There are a lot more advanced ways to manipulate input with flatten and others, but for my use case I've not needed that yet.
I'm also excited by terraform-yaml-config. There's a lot of potential to support some really great simple yaml config based solutions with a lot less effort. It leverages a deep merge feature as well so you can do some pretty creative solutions with it. I'll probably start relying on that a lot more over my own yaml manipulation. Good luck!
One of the things I've needed was more programmer level understanding of the syntax. Well the docs provide some help I find them too high level. When you get into this type of object manipulation it's hard to figure out without more of a spec.
I'm pinning this link here as well since it actually explains in detail the structure of those clauses. reading through this will probably help me understand it a lot better too.
Didn't know about the yaml config plugin. Looks useful! A topic for another blog post for you 😉
Yep HCL spec can be useful. Till not long ago I didn't even realize myself both { a = b } and { a: b } are valid syntax. I'd just use whichever I copied from docs or other files in the project. Sometimes I wish there was a stricter version of tflint to enforce uniform code style.
@kabirgreferenced this in k8 project noticed this when researching webmentions. I haven't tackled EKS but once with Cloudposse module and gitpod. Good luck! Hopefully you survive all the yaml :-)
changed the title [-]How to Iterate Through A List of Objects with Terraform's for_each function[/-][+]How to Iterate Through A List of Objects with Terraform's for_each function - sheldonhull.com[/+]on Jun 5, 2021
Repository owner locked and limited conversation to collaborators on Aug 5, 2021
Activity
rtanner-tableau commentedon Dec 9, 2020
local.users_config.users seems to reference a "users" object that I don't see defined anywhere.
sheldonhull commentedon Jan 8, 2021
@rtanner-tableau my apologies. I had my email notifications missing so didn't see this until now. Change
userstouserper the yaml above. I think that was a typo in my code example. See if that works if you still are experimenting with it.Also for noting, I'll be trying this out soon when I have my next config project as I'm betting it's a lot more robust. Check this out from one of my all-time favorite terraform module creators.
https://github.com/cloudposse/terraform-yaml-config
cheers
maximivanov commentedon Feb 21, 2021
Thanks Sheldon!
for_each = {for ...trick is definitely an elegant solution to iterate over lists. Helped me to answer this SO question as well. Cheers!sheldonhull commentedon Feb 21, 2021
@maximivanov stoked to hear that. I write to help myself remember these things that took so much effort and were hard to find clear answers on. I'm always cheered to know some else found it helpful! Thanks for the follow-up. 👍
There are a lot more advanced ways to manipulate input with flatten and others, but for my use case I've not needed that yet.
I'm also excited by terraform-yaml-config. There's a lot of potential to support some really great simple yaml config based solutions with a lot less effort. It leverages a deep merge feature as well so you can do some pretty creative solutions with it. I'll probably start relying on that a lot more over my own yaml manipulation. Good luck!
sheldonhull commentedon Feb 21, 2021
Also thanks to @maximivanov answer I have a new resource.
https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md#for-expressions
One of the things I've needed was more programmer level understanding of the syntax. Well the docs provide some help I find them too high level. When you get into this type of object manipulation it's hard to figure out without more of a spec.
I'm pinning this link here as well since it actually explains in detail the structure of those clauses. reading through this will probably help me understand it a lot better too.
maximivanov commentedon Feb 21, 2021
Didn't know about the yaml config plugin. Looks useful! A topic for another blog post for you 😉
Yep HCL spec can be useful. Till not long ago I didn't even realize myself both
{ a = b }and{ a: b }are valid syntax. I'd just use whichever I copied from docs or other files in the project. Sometimes I wish there was a stricter version of tflint to enforce uniform code style.sheldonhull commentedon May 19, 2021
@kabirg referenced this in k8 project noticed this when researching webmentions. I haven't tackled EKS but once with Cloudposse module and gitpod. Good luck! Hopefully you survive all the yaml :-)
kabirg commentedon May 22, 2021
@sheldonhull lol appreciate it! Enjoyed your article too :)
[-]How to Iterate Through A List of Objects with Terraform's for_each function[/-][+]How to Iterate Through A List of Objects with Terraform's for_each function - sheldonhull.com[/+]