0
votes

I am trying to create two user using CFT i am very new to cloudformation how do we define multiple users i have tried below but getting cft error.

{
  "Resources": {
    "AWSSCRIPTS": {
      "Type": "AWS::IAM::User"
    },
    "AWSSCRIPTSPolicy": {
      "Type": "AWS::IAM::ManagedPolicy",
      "Properties": {
        "Description" : "This policy allows to run scripts in new account.",
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": "*",
              "Resource": "*"
            }
          ]
        },
        "Users": [{
          "Ref": "AWSSCRIPTS"
        }]
      }
    },
    "AWSSCRIPTSKeys": {
      "Type": "AWS::IAM::AccessKey",
      "Properties": {
        "UserName": {
          "Ref": "AWSSCRIPTS"
        }
      }
    }
  },  
  "ADDUSER": {
    "Type": "AWS::IAM::User"
  },
  "ADDUSERPolicy": {
    "Type": "AWS::IAM::ManagedPolicy",
    "Properties": {
      "Description" : "This policy allows to list IAM Roles for AAD User.",
      "PolicyDocument": {
        "Version": "2012-10-17",
        "Statement": [
          {
            "Effect": "Allow",
            "Action": "*",
            "Resource": "*"
          }
        ]
      },
      "Users": [{
        "Ref": "ADDUSER"
      }]
    }
  },
  "ADDUSERKeys": {
    "Type": "AWS::IAM::AccessKey",
    "Properties": {
      "UserName": {
        "Ref": "ADDUSER"
      }
    }
  },

  "Outputs": {
    "AccessKey": {
      "Value": {
        "Ref": "AWSSCRIPTS"
      },
      "Description": "Access Key ID of AWS Scripts"
    },
    "SecretKey": {
      "Value": {
        "Fn::GetAtt": [
          "AWSSCRIPTSKeys",
          "SecretAccessKey"
        ]
    },
    "Description": "Secret Key of AWS Scripts User"
  },
  "AccessKey2": {
    "Value": {
      "Ref": "ADDUSER"
    },
    "Description": "Access Key ID of ADD USER"
  },
  "SecretKey2": {
    "Value": {
      "Fn::GetAtt": [
        "ADDUSERKeys",
        "SecretAccessKey"
      ]
  },
  "Description": "Secret Key of ADD User"
}
}
}

I am getting below error

Invalid template property or properties [ADDUSERPolicy, ADDUSER, ADDUSERKeys]


Create credentials for the user, depending on the type of access the user requires:

Programmatic access: The IAM user might need to make API calls, use the AWS CLI, or use the Tools for Windows PowerShell. In that case, create an access key (access key ID and a secret access key) for that user.

AWS Management Console access: If the user needs to access the AWS Management Console, create a password for the user.

1
Right before ADDUSER, you have one too many closing braces (it needs to be moved down below the final resource) so that and subsequent resources are at the wrong level. All resources need to be under the Resources key. - jarmod

1 Answers

0
votes

ADDUSER, ADDUSERPolicy and ADDUSERKeys should be in Resources, but they are on the same level:

Formatted CF Template