Provider scoped depends_on


I have a provider that needs to trigger replication on the backend server if any of its resource types change.

I have been looking at performing this with a specific resource, however it would need to be daisy-chained to all the other resources declared by the provider (this could potentially be hundreds) and as such maintaining this depends_on list is error prone.

resource "example_a" "a" {}
resource "example_b" "b" {}
resource "example_c" "c" {}

resource "example_replicate" "replicate" {
  depends_on = [

Is there a better way of doing this with the sdkv2?

I was also wondering if this would be something that would be sensible to add to the (StopProvider) flow of a hybrid sdkv2/plugin-go provider? Also is the StopProvider called when both muxed servers are stopped (i.e all resources have been processed by both)?

Does anyone have any ideas on how to solve this?

I think hashicorp/terraform#2430 is tracking this feature request. I’m pretty sure StopProvider isn’t really meant for this. It’s called when Terraform would like the provider to stop whatever it is that the provider is doing. This does not necessarily mean completion, or successful completion, of the resources in question.

In your case, it may make sense to make replication triggering a field on every resource, and trigger replication after every create/update/delete. It may make sense to make the replication configuration a provider-level field and trigger replication after each change, treating each change as atomic (as Terraform does).