Module dependancies

Hello I have an issue with modules dependencies, here’s what I am doing

I have 2 modules, one for the creation of IAM custom policies and the other for creation user with attaching these custom policies (this is done via cloud formation)

module “global-iam-policies” {
source = “…/modules/global-iam-policies”
}

module “service-accounts” {
source = “…/modules/service-accounts”
svcNames = var.svcNames
default_custom_policies = module.global-iam-policies.default_custom_policies
}

I have no issues during the creation, so the policies get first created then the USER with the policies attachment is done.

The problem is when I try to destroy one policy, I get this error : DeleteConflict: Cannot delete a policy attached to entities

So it tries to destroy the IAM policy before applying the changes to the cloudfromation template which should first detach the policy.

Any idea how to solve this?

Thanks a lot