How to check for null/length og object in terraform output.tf

51 views Asked by At

I have follwoing output.tf file, in some case

output "health_check_ids_app" {
  description = "Autogenerated health check ids."
  value = module.ilb_app[*].health_check_ids.healthcheck
  value =  try( module.ilb_app[*].health_check_ids.healthcheck)

In some case healthcheck is empty, so cannot assign directly , and neither it work with try block to check for empty before assging value. It throw below error

Error in function call
│ 
│   on outputs.tf line 30, in output "health_check_ids_app":
│   30:   value       =  try( module.ilb_app[*].health_check_ids.healthcheck)
│     ├────────────────
│     │ while calling try(expressions...)
│     │ module.ilb_app is object with 10 attributes
│ 
│ Call to function "try" failed: no expression succeeded:
│ - Unsupported attribute (at outputs.tf:30,57-69)
│   This object does not have an attribute named "healthcheck".

How I can check for empty vlues of health_check_ids and healthcheck from module.ilb_app[*].health_check_ids.healthcheck thanks AJit

0

There are 0 answers