AWS IAM User Policy

This page shows how to write Terraform and CloudFormation for IAM User Policy and write them securely.

aws_iam_user_policy (Terraform)

The User Policy in IAM can be configured in Terraform with the resource name aws_iam_user_policy. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

iam_user_policy.tf#L1
resource "aws_iam_user_policy" "nperevozchikov_EKS-FullAccess" {
  name = "EKS-FullAccess"

  policy = <<POLICY
{
  "Statement": [
iam_user_policy.tf#L1
resource "aws_iam_user_policy" "nperevozchikov_EKS-FullAccess" {
  name = "EKS-FullAccess"

  policy = <<POLICY
{
  "Statement": [
iamuserpolicy.tf#L6
resource "aws_iam_user_policy" "rootUserNotContainMfaTypeVirtual" {
  name = "test"
  user = "root"

  policy = <<EOF
{
iam.tf#L15
resource "aws_iam_user_policy" "vpc_user_policy" {
  name = "vpc-user-policy"
  user = aws_iam_user.vpc.name

  policy = <<EOF
{
main.tf#L9
resource "aws_iam_user_policy" "app_cognito" {
  name   = "cognito"
  policy = data.aws_iam_policy_document.cognito.json
  user   = aws_iam_user.app.name
}

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an IAM policy attached to a user.

Tips: Best Practices for The Other AWS IAM Resources

In addition to the aws_iam_account_password_policy, AWS IAM has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_iam_account_password_policy

Ensure AWS IAM account password policies requires long passwords

It's better to enforce the use of long and complex passwords to reduce the risk of bruteforce attacks.

Review your AWS IAM settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::IAM::User (CloudFormation)

The User in IAM can be configured in CloudFormation with the resource name AWS::IAM::User. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

TigerProject3_Template1_Users.yml#L31
    Type: AWS::IAM::User
    Properties:
      UserName: Charlotte1
      LoginProfile:
        Password: !Ref 'CloudspaceEngPassword'
  TigerUser2:
training-prime.yml#L3
    Type: "AWS::IAM::User"
    Properties:
      Groups:
        - DevUsers
        - ProdUsers
        - PrimeUsers
training-prime.yml#L3
    Type: "AWS::IAM::User"
    Properties:
      Groups:
        - DevUsers
        - ProdUsers
        - PrimeUsers
training-prime.yml#L3
    Type: "AWS::IAM::User"
    Properties:
      Groups:
        - DevUsers
        - ProdUsers
        - PrimeUsers
training-prime.yml#L3
    Type: "AWS::IAM::User"
    Properties:
      Groups:
        - Devusers
        - Produsers
        - PrimeUsers
Identity-CustomUsers.json#L73
      "Type" : "AWS::IAM::User",
      "Properties" : {
        "UserName" : "applicationadministrator",
        "Path" : "/",
        "Groups" : [
          { "Fn::ImportValue" : { "Fn::Sub" : "${CustomGroupsStackName}-ApplicationAdministratorsGroup" }}
Identity-CustomUsers.json#L73
      "Type" : "AWS::IAM::User",
      "Properties" : {
        "UserName" : "applicationadministrator",
        "Path" : "/",
        "Groups" : [
          { "Fn::ImportValue" : { "Fn::Sub" : "${CustomGroupsStackName}-ApplicationAdministratorsGroup" }}
Scout2-Master-004-IAMUsers-Global-Wait.json#L6
            "Type": "AWS::IAM::User",
            "Properties": {
                "UserName": "Scout2User001",
                "Groups": [
                    "BlockedUsers"
                ]
cf-example-100.json#L6
            "Type": "AWS::IAM::User",
            "Properties": {
                "UserName": "TestUser1",
                "Path": "/"
            }
        },
Identity-CustomUsers.json#L46
      "Type" : "AWS::IAM::User",
      "Properties" : {
        "UserName" : "mcrawford",
        "Path" : "/",
        "Groups" : [{ "Fn::ImportValue" : { "Fn::Sub" : "${StandardGroupsStackName}-AdministratorsGroup" }}]
      }

Parameters

Explanation in CloudFormation Registry

Creates a new IAM user for your AWS account. For information about quotas for the number of IAM users you can create, see IAM and AWS STS quotas in the IAM User Guide.

Frequently asked questions

What is AWS IAM User Policy?

AWS IAM User Policy is a resource for IAM of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS IAM User Policy?

For Terraform, the mortyre/misc, mortyre/misc and storebot/pr_demo_flat source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the hortensehouendji/Tigers_CloudProject3, ServerlessOpsIO/infrastructure and ServerlessOpsIO/infrastructure source code examples are useful. See the CloudFormation Example section for further details.