Adding a new service to AWS ECR, but deployment depends on ECR to exist. Chicken and egg issue

We deploy our app that consists of a few microservices, and our docker images are stored in AWS ECR.

If I want to add a new service, I update my terraform so the service gets built, pushed to ECR and deploys to Fargate etc.

When I deploy to a different environment (DEV, TEST or PROD), the terraform deployment fails because the ECR doesn’t exist (it tries to pull the image for the new service from ECR).

So it is kind of a chicken-and-egg problem, I can’t deploy b/c the ECR doesn’t exist, and the ECR has to exist to publish the image to ECR for the new service.

What options are there to handle this type of situation?

Assuming you’re using Terraform for everything, define a aws_ecr_repository resource that the deployment depends on (ideally implicitly, but you could make it an explicit dependency first).

1 Like