Site icon JD Bots

How to Use the lower Function in OpenTofu

Card titled The lower Function, labelled OpenTofu Functions, showing lower(HELLO World) and the result hello world.

Turn an OpenTofu string into lowercase with lower, and use it to compare two names without caring about case

lower turns every letter of a string into lowercase. Comparing two values after lower treats Tea and TEA as the same name.

Syntax

Syntax

lower(<STRING>)

The docs say it converts all cased letters: lower Function.

Prerequisites

Step 1: Try It in tofu console

Open a terminal in any empty folder and start tofu console, which evaluates expressions as you type them:

Terminal

tofu console

Type each expression to see the result:

tofu console

> lower("HELLO World")
"hello world"
> lower("ÉCOLE")
"école"
> lower("Tea") == lower("TEA")
true
> exit

Clean Up

Type exit to leave the console. The example creates nothing, so there’s nothing else to remove.

Common Mistakes

MistakeWhat happensDo this instead
Expecting it to change the variableIt returns a new string; the original value is unchanged.Use the result where you need it.
Comparing names without it"Tea" == "TEA" is false.Compare lower(a) == lower(b).

FAQ

Is there an uppercase version?

Yes, the upper function does the opposite.

Does lower change accented letters?

Yes: lower("ÉCOLE") returned "école" above.

Conclusion

lower(<STRING>) returns the string in lowercase, which makes comparisons ignore case.

Additional Resources

OpenTofu® is a registered trademark of LF Projects, LLC. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by the OpenTofu project.

Exit mobile version