title: In Terraform 0.12, how to skip creation of resource, if resource name already exists?
body: <p>I am using Terraform version 0.12. I have a requirement to skip resource creation if resource with the same name already exists. </p>
  
  <p>I did the following for this :</p>
  
  <p>Read the list of custom images, </p>
  
  <pre><code>data "ibm_is_images" "custom_images" {
  }
  </code></pre>
  
  <p>Check if image already exists, </p>
  
  <pre><code>locals {
   custom_vsi_image = contains([for x in data.ibm_is_images.custom_images.images: "true" if x.visibility == "private" &amp;&amp; x.name == var.vnf_vpc_image_name], "true")
  }
  
  output "abc" {
  value="${local.custom_vsi_image}"
  }
  </code></pre>
  
  <p>Create only if image exists is false. </p>
  
  <pre><code>resource "ibm_is_image" "custom_image" {
    count            = "${local.custom_vsi_image == true ? 0 : 1}"
    depends_on       = ["data.ibm_is_images.custom_images"]
    href             = "${local.image_url}"
    name             = "${var.vnf_vpc_image_name}"
    operating_system = "centos-7-amd64"
  
    timeouts {
      create = "30m"
      delete = "10m"
    }
  }
  </code></pre>
  
  <p>This works fine for the first time with "terraform apply". It finds that the image did not exists, so it creates image. </p>
  
  <p>When I run "terraform apply" for the second time. It is deleting the resource "custom_image" that is created above. Any idea why it is deleting the resource, when it is run for the 2nd time ?</p>
  
  <p>Also, how to create a resource based on some condition(like only when it does not exists) ?</p>