Skip to content

auth_token_update_strategy validation fails with null values due to lower() function call #262

@mran-baig-se

Description

@mran-baig-se

Describe the Bug

The auth_token_update_strategy variable validation in variables.tf line 187 fails when the variable is null because it tries to call the lower() function on a null value.
Current problematic code:
variable "auth_token_update_strategy" { type = string description = "Strategy to use when updating the auth_token. Valid values are SET, ROTATE, and DELETE. Defaults to ROTATE`."
default = "ROTATE"

validation {
condition = contains(["set", "rotate", "delete"], lower(var.auth_token_update_strategy))
error_message = "Valid values for auth_token_update_strategy are SET, ROTATE, and DELETE."
}`. Error: Invalid function argument
on .terraform/modules/redis/variables.tf line 187, in variable "auth_token_update_strategy":
187: condition = contains(["set", "rotate", "delete"], lower(var.auth_token_update_strategy))
├────────────────
│ while calling lower(str)
│ var.auth_token_update_strategy is null

│ Invalid value for "str" parameter: argument must not be null.

Expected Behavior

The validation should handle null values gracefully and allow the module to work when transit encryption is disabled.

Steps to Reproduce

Steps to reproduce:
Use the module with transit_encryption_enabled = false
Don't specify auth_token or auth_token_update_strategy
Run terraform plan

Screenshots

Image

Environment

No response

Additional Context

proposed fix:
variable "auth_token_update_strategy" {
type = string
description = "Strategy to use when updating the auth_token. Valid values are SET, ROTATE, and DELETE. Defaults to null."
default = null

validation {
condition = var.auth_token_update_strategy == null || var.auth_token_update_strategy == "set" || var.auth_token_update_strategy == "rotate" || var.auth_token_update_strategy == "delete" || var.auth_token_update_strategy == "SET" || var.auth_token_update_strategy == "ROTATE" || var.auth_token_update_strategy == "DELETE"
error_message = "Valid values for auth_token_update_strategy are SET, ROTATE, and DELETE, or null."
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🐛 An issue with the system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions