Another case when you may want to use a data source is if you are migrating existing infrastructure to Terraform and want to reference a resource that is not part of your Terraform project yet. As previously stated, it is always better to use a data source rather than compute the value yourself. You want Terraform to know that there is a dependency on the resource so that your terraform apply will fail if the resource cannot be found or if the attribute it returns changes. Terraform will realise this when you run “apply” and update your project with the new value.