title: Terraform custom validation for variable that can be null
body: <p>I'm trying to use Terraform 0.13's <a href="https://www.hashicorp.com/blog/custom-variable-validation-in-terraform-0-13" rel="nofollow noreferrer">custom variable validation</a> to ensure that the value is either <code>null</code> or between a specified range. I've tried every combination I can think of (using <code>can</code>, <code>try</code>, etc) but can't get it working for every case.</p>
  <p>Here is the full non-working example:</p>
  <pre><code>variable &quot;target_group_stickiness_duration&quot; {
    default = null
    type    = number
   
    validation {
      condition = ( 
        var.target_group_stickiness_duration == null ||
        ( var.target_group_stickiness_duration &gt;= 1 &amp;&amp; var.target_group_stickiness_duration &lt;= 604800 )
      )   
   
      error_message = &quot;Target group stickiness duration must be &gt;= 1 and &lt;= 604800.&quot;
    }
  }
  </code></pre>
  <p>This will fail if the value is <code>null</code> with the following error:</p>
  <blockquote>
  <p>Error during operation: argument must not be null.</p>
  </blockquote>
  <p>I believe this is due to eager evaluation of the conditional expression. Am I missing something obvious? Or any clever workarounds for this?</p>