Skip to content

Question about Invalid value for variable because of a validation rule. #718

@dmattoninnovtech

Description

@dmattoninnovtech

Hello everyone,

I test the pre-commit hook for Terraform with terraform_validate. And I have this error Error: Invalid value for variable because of This was checked by the validation rule for var.publisher_name.

The files are in a directory that will be used as a Terraform module.

Error message

╷
│ Error: Invalid value for variable
│
│   on variables.tf line 81:
│   81: variable "publisher_name" {
│     ├────────────────
│     │ var.publisher_name is a string
│
│ Publisher name can't be empty. The length is between 3 and 65 characters.

│ This was checked by the validation rule at variables.tf:85,3-13.

In the main.tf

resource "azurerm_api_management" "az_apim" {
  name                = local.resource_name
  location            = var.location
  resource_group_name = var.resource_group_name
  publisher_name      = var.publisher_name
  ...
}

And in the variables.tf

variable "publisher_name" {
  type        = string
  description = "The name of publisher/company."

  validation {
    condition     = can(regex("^(?!\\s*$).{3,65}$", var.publisher_name))
    error_message = "Publisher name can't be empty. The length is between 3 and 65 characters."
  }
}

The resource will be used later as a module and the variable publisher_name will be required.

So is it possible to use mock data or may be there is another processs or method to avoid this kind of error ?

Thanks for your help.
David

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions