title: validating a list of input variables in terraform
body: <p>This validation block works for a single input variable.</p>
  
  <pre><code>variable "mytestname" {
  
       validation {
          condition = length(regexall("test$", var.mytestname)) &gt; 0
          error_message = "Should end in test"
       }
  }
  </code></pre>
  
  <p>I need it to work inside a for_each - or have some workaround to accomplish this. The issue is that there is a restriction on the condition statement - the condition HAS to take in the input variable itself (i.e. - it cannot accept an each.value)</p>
  
  <pre><code>variable "mytestnames" {
  
  listnames = split(",",var.mytestnames)     
  
  for_each = var.listnames
  
       validation {
          condition = length(regexall("test$", each.value)) &gt; 0
          error_message = "Should end in test"
        }
  }
  </code></pre>
  
  <p>The above snippet does not work. I need a way I can iterate over a list of values and validate each of them. It looks like the newly introduced 'validation block' does not work on lists of input variables. There must be a way to do this without a validation block...??</p>