Cross module dependency in data block

Hello,
This is my scenario:

  1. I have one repository creating IAM Roles and IAM Policies
  2. Repository is using two separated modules each for Roles and Policies
  3. In Role module I have data block, which is getting IAM Policy ARN, created by Policy module.
  4. Terraform plan finish with data error because checked Policy doesn’t exist yet - It will be created by separated module but it doesn’t work as Policy creation and data block works on the same run.

Currently to workaround the issue I need to create the Policy and then put it into attachment list to Role to make it available in advance for data block.

Do you have any idea how enable dependency between the modules to avoid data block issue with not existing yet Policy?

Best Regards

Hi @revaner,

The problem you are describing is because you are using data sources for resources which are managed within the same configuration. The solution here is to output the necessary attributes from the policy resources and use those as inputs to the Role modules. This will ensure the dependencies are defined so the resources are created in the correct order.