title: How can I declare and reference an ECR repository in Terraform without jeopardizing its contents?
body: <p>I am building a Terraform configuration to deploy some containers to AWS ECS. Obviously, I must push the Docker images to ECR. I created a repository in ECR and pushed the images.</p>
  
  <p>Now I'm automating. If I declare the <code>aws_ecr_repository</code> like so:</p>
  
  <pre><code>data "aws_ecr_repository" "service" {
    name = "myrepository"
  }
  </code></pre>
  
  <p>then Terraform will manage it. I can eventually reference it with something like</p>
  
  <pre><code>image = "${aws_ecr_repository.myrepository.repository_url}"
  </code></pre>
  
  <p>in the process of building the ECS task definition.</p>
  
  <p>I am under the impression that Terraform will delete this repository – or fail when it has images – when I run <code>terraform destroy</code> as a part of my development cycle. This would be bad, because then <code>terraform destroy</code> would either never complete or I would have to clear out the ECR repository for that command to complete successfully.</p>
  
  <p>How can I best reference an ECR repository that already exists but I seemingly don't want Terraform to manage because Terraform may destroy data that lives outside of Terraform, i.e. the Docker images uploaded by release CI jobs?</p>