title: Terraform: depends_on for module not working as expected in AWS
body: <p>I am new to terraform. I was working with terraform v0.12 previously and since I wanted to bring in a dependency between modules, I started using terraform v0.13 recently. I am trying to create an IAM role and attach a few policies to the created role. But the issue arises in policy attachment to the role. Few policies are getting attached to the role but some policies throw an error saying no such role exists while the other policies are attached to the role properly. Is there anything wrong in my implementation?</p>
  <p>module.tf</p>
  <pre><code>provider &quot;aws&quot; {
    region = &quot;ap-southeast-1&quot;
  }
  
  #Control Plane role and policies
  
  module &quot;ControlPlane_Role&quot; {
  
    source = &quot;../../templates/IAM/roles&quot;
    role_name = var.EKS-master-role
  }
  
  module &quot;ControlPlane_Policy1&quot; {
  
    source = &quot;../../templates/IAM/aws_policy&quot;
    role_name = var.EKS-master-role
    policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSClusterPolicy&quot;
    depends_on = [module.ControlPlane_Role.role_create]
  }
  
  module &quot;ControlPlane_Policy2&quot; {
  
    source = &quot;../../templates/IAM/aws_policy&quot;
    role_name = var.EKS-master-role
    policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSServicePolicy&quot;
    depends_on = [module.ControlPlane_Role.role_create]
  }
  </code></pre>
  <p>templates/IAM/roles/role.tf</p>
  <pre><code>resource &quot;aws_iam_role&quot; &quot;role_create&quot; {
    assume_role_policy = data.aws_iam_policy_document.trusted_entity.json
    name               = var.role_name
  }
  </code></pre>
  <p>aws_policy.tf</p>
  <pre><code>resource &quot;aws_iam_role_policy_attachment&quot; &quot;aws_policy&quot; {
    role       = var.role_name
    policy_arn = var.policy_arn
  }
  </code></pre>
  <p>I'll be passing the variable files separately and there are no issues with that.</p>
  <p>Error:</p>
  <pre><code>Error: Error attaching policy arn:aws:iam::aws:policy/AmazonEKSClusterPolicy to IAM Role EKS-master: NoSuchEntity: The role with name EKS-master cannot be found.
  
  Error attaching policy arn:aws:iam::aws:policy/AmazonEKSServicePolicy to IAM Role EKS-master: NoSuchEntity: The role with name EKS-master cannot be found.
  </code></pre>
  <p>If I re-run the command terraform apply again on the same resources without any change, the policies are getting attached.</p>