Skip to main content
strlen(str) returns the number of grapheme clusters in str.

Signature

strlen(str string) number

Example

Validate that a required token variable has a minimum length before attempting a deployment:
variable "deploy_token" {
  description = "API token for the deployment service"
  type        = string
}

task "deploy" {
  description = "Deploy the application"
  condition   = strlen(var.deploy_token) >= 32
  commands    = ["./bin/deploy --token ${var.deploy_token}"]
}
When deploy_token is shorter than 32 characters, the task is skipped with a condition note instead of failing with an authentication error downstream.

Notes

  • strlen counts grapheme clusters, not bytes or code points. A multi-byte character or combined character sequence counts as one.
  • For byte length, there is no dedicated function. Most use cases care about character count.