title: Terraform: What's the point using Both Data Source and Resource on the same type?
body: <p>I'm new to Terraform, and I'm working on a project to use Docker/AWS ECR/ECS infrastructure on AWS. I see <a href="https://medium.com/@hullsean/how-to-setup-an-amazon-ecs-cluster-with-terraform-87952988f239" rel="nofollow noreferrer">in this post</a> where the author specify something like</p>
  
  <pre><code>data "aws_ecs_task_definition" "test" {
   task_definition = "${aws_ecs_task_definition.test.family}"
   depends_on = ["aws_ecs_task_definition.test"]
  }
  
  resource "aws_ecs_task_definition" "test" {
   family = "test-family"
   # ...
  }
  
  </code></pre>
  
  <p>why is he using both data source AND resource on <code>aws_ecs_task_definition</code>? I can't find an explanation or similar example after hours of digging into the official doc as well as googling articles. </p>
  
  <p>I see later on when he's setting up the service, he uses the following code to reference both of them: (again, I'm not sure what's going on here)</p>
  
  <p><code>task_definition = "${aws_ecs_task_definition.test.family}:${max("${aws_ecs_task_definition.test.revision}", "${data.aws_ecs_task_definition.test.revision}")}"
  </code></p>
  
  <p>I am now confused of what is the difference between using both data &amp; resource on the same type, versus just using resource. Is there any difference in terms of lifecycle? </p>
  
  <p>I'm now trying to create a AWS ECR for my docker image and I want terraform to manage it (create/update/destroy), should I use both data source &amp; resource for the type <code>aws_ecr_repository</code> as well?</p>