Validate giá trị input các biến Terraform object

### Variable tags
variable "tags" {
  description = "Tags for all resources"
  type = object({
    env                 = string
    owner               = string
  })

  validation {
    condition     = length(var.tags.env) > 0 && contains(["dev", "stg", "prd"], var.tags.env)
    error_message = "env: Can not be null. Environment variable. Valid value: dev| stg| prd"
  }

  validation {
    condition     = length(var.tags.owner) > 0
    error_message = "owner: Can not be null. Owner of the app. This is a free text tags. Example value: finance department"
  }
}

Bạn có thể sử dụng cách trên để validate dữ liệu người dùng truyền vào. Chúng ta nên dùng object như trên để validate, tránh dùng hàm lookup nếu có yêu cầu chặt chẽ về những gì người dùng có thể truyền vào.