Terraform 提供程序的文档说我可以通过这种方式从容器中获取值.identity[0]
,但在某些情况下identity
为空。如果容器中至少有一个元素,我该如何获取第一个元素(否则null
例如)。
实际情况下由于此原因而遇到的一个错误(以及错误的线路):
Error: Invalid index
on .../outputs.tf line 21, in output "container_registry_primary_identity_principal_id":
21: value = azurerm_container_registry.***.identity[0].principal_id
├────────────────
│ azurerm_container_registry.***.identity is empty list of object
The given key does not identify an element in this collection value: the
collection has no elements.
您也许可以通过使用内置函数来实现您想要的
try
功能。由于您尚未添加整个输出块,因此它应该看起来像以下内容: