title: Terraform: Set optional resource attribute if condition is met, otherwise don't declare it
body: <p>Some resources on Terraform support optional attributes. I'm interested in declaring and setting a value for the optional attribute only if a condition is met. Otherwise, don't declare it at all.</p>
  
  <p>All of the suggestions I found was based on declaring the attribute and setting its value to <code>null</code> if the condition isn't satisfied, instead of not declaring the attribute at all.</p>
  
  <p>Is there a way for me to do something like the following? In pseudo-code:</p>
  
  <pre><code>resource "some_resource" "this" {
    name = var.name
  
    if var.name == "some_name":
      some_optional_attribute = "some_value"
    else:
      pass  # do nothing, don't even declare the optional attribute
  }
  </code></pre>
  
  <p>Let me know, thanks in advance!</p>