title: Attaching AWS Managed Policy to a Custom Role via Terraform
body: <p>I am writing a tf script to create a role and attach an AWS Managed Policy to the Role. If my policy is a custom policy this works, If i need to use a an AWS managed policy, how do i attach my policy to the role. is there a way to use &quot;data&quot; to extrapolate the role ARN from AWS</p>
  <pre><code>resource &quot;aws_iam_role&quot; &quot;CloudWatchAgentServerRole&quot; {
    name               = &quot;CloudWatchAgentServerRole&quot;
    description        = &quot;Role created to allow Memory metrics to CloudWatch &quot;
    assume_role_policy = file(&quot;role.json&quot;)
  }
  
  #Create Policy - Not Required as its an AWS Managed Policy
  /*resource &quot;aws_iam_policy&quot; &quot;CloudWatchAgentServerPolicy&quot; {
    name        = &quot;CloudWatchAgentServerPolicy&quot;
    description = &quot;Permissions required to use AmazonCloudWatchAgent on servers&quot;
    policy      = file(&quot;policy.json&quot;)
  }*/
  
  # Attach Policy 
  resource &quot;aws_iam_role_policy_attachment&quot; &quot;CloudWatchAgentServer&quot; {
    role       = aws_iam_role.CloudWatchAgentServerRole.name
    policy_arn = aws_iam_policy.CloudWatchAgentServerPolicy.arn  
  }
  </code></pre>
  <p>Thanks</p>