'How to retrieve IAM Policies attached to an IAM Role with Terraform?

I'm trying to get the attached Policies from an existing IAM Role, I want to reuse existing Policies by just referencing an IAM Role ARN or Name.

So far I can only see a Data Source resource in Terraform called "aws_iam_role" which has an attribute "assume_role_policy" which I don't think its what I'm looking for.

I also see this data source "aws_iam_policy" but that just pulls an individual iam policy, not based on any IAM Role attribute (name, arn, etc).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source