Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach more than one IAM inline policy from cloudformation to the same role

I am checking to see if we could attach more than one IAM policy with cloud formation. I am already attaching an Managed Policy and i am able to attach and inline policy but wanted to check if i could attach more than one inline policy.

I would want to attach to the same role

1) Managed Policy 2) Inline Policy - 1 3) Inline Policy - 2

Thanks Nataraj

like image 826
Nataraj Avatar asked Aug 06 '18 14:08

Nataraj


People also ask

How many IAM policies can you attach to a role?

IAM groups You can attach up to 20 managed policies to IAM roles and users.

Can a IAM role have multiple policies?

You can attach multiple policies to an identity, and each policy can contain multiple permissions. Consult these resources for details: For more information about the different types of IAM policies, see Policies and permissions in IAM.

How can I attach an IAM managed policy to an IAM role in AWS Cloudformation?

To add an existing or new IAM managed policy to a new IAM role resource, use the ManagedPolicyArns property of resource type AWS::IAM::Role. To add a new IAM managed policy to an existing IAM role resource, use the Roles property of resource type AWS::IAM::ManagedPolicy.


1 Answers

This is completely possible. The relevant fields will be ManagedPolicyArns and Policies.

Resources: 
  RootRole: 
    Type: "AWS::IAM::Role"
    Properties: 
      AssumeRolePolicyDocument: 
        Version: "2012-10-17"
        Statement: 
          - Effect: "Allow"
            Principal: 
              Service: 
                - "ec2.amazonaws.com"
            Action: 
              - "sts:AssumeRole"
      Path: "/"
      ManagedPolicyArns:
        - 'arn:aws:iam::ACCOUNT_ID:policy/myname/ManagedPolicy'
      Policies: 
        - PolicyName: "Inline Policy 1"
          PolicyDocument: 
            Version: "2012-10-17"
            Statement: 
              - Effect: "Allow"
                Action: "*"
                Resource: "*"
        - PolicyName: "Inline Policy 2"
          PolicyDocument: 
            Version: "2012-10-17"
            Statement: 
              - Effect: "Allow"
                Action: "*"
                Resource: "*"

For more details/callouts check out the documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html

like image 97
Cheruvian Avatar answered Sep 22 '22 14:09

Cheruvian