title: Terraform: Conditional creation of a resource based on a variable in .tfvars
body: <p>I have resources defined in <code>.tf</code> files that are generic to several applications. I populate many of the fields via a <code>.tfvars</code> file. I need to omit some of the resources entirely based on variables in the <code>.tfvars</code>. </p>
  
  <p>For example if I have a resource like:</p>
  
  <pre><code>resource "cloudflare_record" "record" {
    zone_id = "${data.cloudflare_zones.domain.zones[0].id}"
    name    = "${var.subdomain}"
    value   = "${var.origin_server}"
    type    = "CNAME"
    ttl     = 1
    proxied = true
  }
  </code></pre>
  
  <p>But then I declare something like <code>cloudflare = false</code> in my <code>.tfvars</code> file I'd like to be able to do something like this:</p>
  
  <pre><code>if var.cloudflare {
    resource "cloudflare_record" "record" {
      zone_id = "${data.cloudflare_zones.domain.zones[0].id}"
      name    = "${var.subdomain}"
      value   = "${var.origin_server}"
      type    = "CNAME"
      ttl     = 1
      proxied = true
   }
  }
  </code></pre>
  
  <p>I've looked at dynamic blocks but that looks like you can only use those to edit fields and blocks within a resource. I need to be able to ignore an entire resource.</p>