concept

References, indexing and evaluation errors

Use zero-based sequence indexes, string keys, fixed attributes and splats to access values. Guard nullable objects before accessing their attributes.

Formal Syntax & Structure

terraform syntaxterraform
References, indexing and evaluation errors

Working Example

Example Snippetterraform
variable "service" {  type = object({    port = optional(number)  })  default = null}
locals {  port = var.service == null ? 8080 : (var.service.port == null ? 8080 : var.service.port)}
output "port" {  value = local.port}
Terraform Reference