Attaches a Managed IAM Policy to an IAM user
resource "aws_iam_user" "user" {
name = "test-user"
}
resource "aws_iam_policy" "policy" {
name = "test-policy"
description = "A test policy"
policy = "{ ... policy JSON ... }"
}
resource "aws_iam_user_policy_attachment" "test-attach" {
user = aws_iam_user.user.name
policy_arn = aws_iam_policy.policy.arn
}
This resource supports the following arguments:
user
(Required) - The user the policy should be applied topolicy_arn
(Required) - The ARN of the policy you want to applyThis resource exports no additional attributes.
In Terraform v1.5.0 and later, use an import
block to import IAM user policy attachments using the user name and policy arn separated by /
. For example:
import {
to = aws_iam_user_policy_attachment.test-attach
id = "test-user/arn:aws:iam::xxxxxxxxxxxx:policy/test-policy"
}
Using terraform import
, import IAM user policy attachments using the user name and policy arn separated by /
. For example:
% terraform import aws_iam_user_policy_attachment.test-attach test-user/arn:aws:iam::xxxxxxxxxxxx:policy/test-policy