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 "data" to extrapolate the role ARN from AWS
resource "aws_iam_role" "CloudWatchAgentServerRole" {
name = "CloudWatchAgentServerRole"
description = "Role created to allow Memory metrics to CloudWatch "
assume_role_policy = file("role.json")
}
#Create Policy - Not Required as its an AWS Managed Policy
/*resource "aws_iam_policy" "CloudWatchAgentServerPolicy" {
name = "CloudWatchAgentServerPolicy"
description = "Permissions required to use AmazonCloudWatchAgent on servers"
policy = file("policy.json")
}*/
# Attach Policy
resource "aws_iam_role_policy_attachment" "CloudWatchAgentServer" {
role = aws_iam_role.CloudWatchAgentServerRole.name
policy_arn = aws_iam_policy.CloudWatchAgentServerPolicy.arn
}
Thanks