Resource: aws_iam_user_policy

Provides an IAM policy attached to a user.

Example Usage

resource "aws_iam_user_policy" "lb_ro" {
  name = "test"
  user = aws_iam_user.lb.name

  # Terraform's "jsonencode" function converts a
  # Terraform expression result to valid JSON syntax.
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = [
          "ec2:Describe*",
        ]
        Effect   = "Allow"
        Resource = "*"
      },
    ]
  })
}

resource "aws_iam_user" "lb" {
  name = "loadbalancer"
  path = "/system/"
}

resource "aws_iam_access_key" "lb" {
  user = aws_iam_user.lb.name
}

Argument Reference

This resource supports the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import IAM User Policies using the user_name:user_policy_name. For example:

import {
  to = aws_iam_user_policy.mypolicy
  id = "user_of_mypolicy_name:mypolicy_name"
}

Using terraform import, import IAM User Policies using the user_name:user_policy_name. For example:

% terraform import aws_iam_user_policy.mypolicy user_of_mypolicy_name:mypolicy_name