Skip to content

Functions lower() & upper()

📝 Description

  • lower: Converts all uppercase letters in a given string to lowercase.

  • upper: Converts all lowercase letters in a given string to uppercase.

Use Case: Standardizing resource names, tags, or environment variables to avoid case-sensitivity issues in cloud providers.


💻 Syntax

lower(string)
upper(string)

💡 Examples

1. Standardizing S3 Bucket Names (lower):

S3 buckets must be lowercase. If a user enters My-Company-Bucket, lower will fix it.

variable "bucket_name" {
  default = "My-Awesome-Bucket"
}

resource "aws_s3_bucket" "example" {
  # Result: "my-awesome-bucket"
  bucket = lower(var.bucket_name)
}

2. Formatting Tags or Metadata (upper):

Sometimes you want environment tags to stand out in the console.

variable "env" {
  default = "prod"
}

locals {
  # Result: "PROD"
  env_tag = upper(var.env)
}

3. Comparison (Real-world scenario):

Use these functions when you need to compare strings regardless of how the user typed them:

# This check will work even if var.os is "Linux", "LINUX", or "linux"
is_linux = lower(var.os) == "linux"

⚠️ Key Details

  • Non-alphabetic characters (numbers, symbols like - or _) are not affected.

  • They work with Unicode characters (e.g., Cyrillic), but keep in mind that some cloud resources only support ASCII.


  • [[title]] — Capitalizes only the first letter of each word.

  • [[replace]] — Search and replace specific characters.

  • Official HashiCorp Docs: lower