Skip to content
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

Unable to iterate over resources #1106

Closed
castarco opened this issue Mar 16, 2025 · 1 comment
Closed

Unable to iterate over resources #1106

castarco opened this issue Mar 16, 2025 · 1 comment

Comments

@castarco
Copy link

Hi. I'm opening an issue here because I couldn't find any discussions section.

I recently created a small "cluster" in Hetzner cloud, using Terraform. One problem I'm facing is that I'm being completely unable to iterate over specific resources (such as servers or primary IPs) to generate custom outputs that have an "array shape".

So far, the only thing I managed to do is to generate individual outputs for specific resources, but I couldn't generate outputs that represent a collection of resources.

Any guidance on how to do that? (for example, to list primary ips as a single array?)

Thank you.

@jooola
Copy link
Member

jooola commented Mar 19, 2025

Hey,
You can leverage the data sources to gather a list of resources, for example using https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/data-sources/servers or https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/data-sources/primary_ips

Once you have this data, you can use terraform hcl features to shape your output https://developer.hashicorp.com/terraform/language/expressions/splat

Closing as resolved, let me know if you think I missed something.

@jooola jooola closed this as completed Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants