title: Terraform check if resource exists before creating it
body: <p>Is there a way in Terraform to check if a resource in Google Cloud exists prior to trying to create it?</p>
  <p>I want to check if the following resources below exist in my CircleCI CI/CD pipeline during a job. I have access to terminal commands, bash, and gcloud commands. If the resources do exist, I want to use them. If they do not exist, I want to create them. I am doing this logic in CircleCI's config.yml as steps where I have access to terminal commands and bash. My goal is to create my necessary infrastructure (resources) in GCP when they are needed, otherwise use them if they are created, without getting Terraform errors in my CI/CD builds.</p>
  <p>If I try to create a resource that already exists, Terraform apply will result in an error saying something like, &quot;you already own this resource,&quot; and now my CI/CD job fails.</p>
  <p>Below is pseudo code describing the resources I am trying to get.</p>
  <pre><code>resource &quot;google_artifact_registry_repository&quot; &quot;main&quot; {
    # this is the repo for hosting my Docker images
    # it does not have a data source afaik because it is beta
  }
  </code></pre>
  <p>For my <strong>google_artifact_registry_repository</strong> resource. One approach I have is to do a Terraform apply using a data source block and see if a value is returned. The problem with this is that the google_artifact_registry_repository does not have a data source block. Therefore, I must create this resource once using a resource block and every CI/CD build thereafter can rely on it being there. Is there a work-around to read that it exists?</p>
  <pre><code>resource &quot;google_storage_bucket&quot; &quot;bucket&quot; {
    # bucket containing the folder below
  }
  
  resource &quot;google_storage_bucket_object&quot; &quot;content_folder&quot; {
    # folder containing Terraform default.tfstate for my Cloud Run Service
  }
  </code></pre>
  <p>For my <strong>google_storage_bucket</strong> and <strong>google_storage_bucket_object</strong> resources. If I do a Terraform apply using a data source block to see if these exist, one issue I run into is when the resources are not found, Terraform takes forever to return that status. It would be great if I could determine if a resource exists within like 10-15 seconds or something, and if not assume these resources do not exist.</p>
  <pre><code>data &quot;google_storage_bucket&quot; &quot;bucket&quot; {
    # bucket containing the folder below
  }
  
  output bucket {
    value = data.google_storage_bucket.bucket
  }
  </code></pre>
  <p>When the resource exists, I can use Terraform output bucket to get that value. If it does not exist, Terraform takes too long to return a response. Any ideas on this?</p>