I am implementing a Terraform provider using the Terraform Plugin Framewok.
I have this resource main_resource
, that can be linked to another resource sub_resource
. On API side, a sub_resource
can only be deleted if it as been unlinked
from any resources.
Let’s say we have the current tfstate
:
resource "main_resource" "dummy" {
sub_resource_id = sub_resource.dummy.id
}
resource "sub_resource" "dummy" {}
And then we try to apply this plan
:
resource "main_resource" "dummy" {}
Here is what I would like Terraform to do :
- Update of
main_resource.dummy
(wheresub_resource.dummy
getsunlinked
) - Delete of
sub_resource.dummy
And here is what Terraform does :
- Delete of
sub_resource.dummy
(Fails because thesub_resource
is stilllinked
to another resource) - Update of
main_resource.dummy
(We never reach this)
How can I make Terraform run this sequence in the wanted order on provider side ?