# For\_each depends\_on

**URL:** <https://discuss.hashicorp.com/t/for-each-depends-on/6004>\
**Category:** Terraform\
**Created:** [February 17, 2020, 3:37pm UTC](https://discuss.hashicorp.com/t/for-each-depends-on/6004 "2020-02-17T15:37:22Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [February 18, 2020, 11:00pm UTC](https://discuss.hashicorp.com/t/for-each-depends-on/6004/6 "2020-02-18T23:00:37Z")

</div>

In the log we can see that the repository creation is completing before Terraform tries to create the lifecycle policy:

```auto
module.ecr.aws_ecr_repository.ecr["foobaar"]: Creation complete after 0s [id=foobaar]
module.ecr.aws_ecr_lifecycle_policy.lifecycle_policy["foobaar"]: Creating...

```

So it looks like the dependencies in the configuration are correct, but that the `aws_ecr_repository` implementation in the AWS provider is returning success before the repository has fully committed. If that is true, unfortunately I don’t think there’s any way to strengthen that dependency from within the Terraform language: the provider would need to make sure the repository is ready to use before indicating that the creation has completed successfully.

Although the error message is not exactly the same, the overall behavior here seems similar to the following issue in the AWS provider:

> <https://github.com/terraform-providers/terraform-provider-aws/issues/545>
>
> This issue was originally opened by @vikas027 as hashicorp/terraform#12108. It was migrated here as part of the provider split. The original...

Since that was originally opened in 2017, I think it’s plausible that the exact error message text returned from the remote API could’ve changed in the meantime, because both your message and the one reported there both seem to be saying (in different words) that the policy refers to a non-existing repository.

---

_[View the full topic](https://discuss.hashicorp.com/t/for-each-depends-on/6004)._
