Is there a nice way to log the values used when evaluating a for_each loop?

I’m trying to filter some rather complicated maps of maps of maps. Setting TF_LOG=TRACE doesn’t log out the value being set. And since it hasn’t been applied I can’t use terraform show to view the structure.

You can use the terraform console CLI command to test the evaluation of expressions interactively.

It may help to assign your complex for_each expression to a local variable, so you can ask the console to show you the value just by referencing the variable, rather than needing to copy/paste the whole expression.

1 Like

in your outputs, you can use a “for” expression: For Expressions - Configuration Language | Terraform by HashiCorp


output "vault_roles" {
  description = "Vault Roles"
  value = { for db, role in vault_approle_auth_backend_role.roles : db => {
    auth_path = role.backend
    role_path =
    role_id   = role.role_id
  } }

… that is assuming you only want specific fields and not the whole object… otherwise you can just output the whole thing.

output "vault_roles"  {
  description = "Vault Roles"
  value = vault_approle_auth_backend_role.roles