Identity and Access Management (IAM) policies can be configured to allow access to the entire ECR service. This differs from specific repository policies and is often used to restrict access for the ECR service as a whole rather than individual services within the repository. For more information, see the AWS ECR documentation.
References:
https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policies.html
To create IAM policies and attach them to the ECR resource, follow the direction in the user guide (below).
In Terraform -
References:
https://docs.aws.amazon.com/AmazonECR/latest/userguide/security-iam-awsmanpol.html
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository_policy