ALIYUN::RAM::User

ALIYUN::RAM::User类型用于创建RAM用户。

语法

{
  "Type": "ALIYUN::RAM::User",
  "Properties": {
    "UserName": String,
    "DisplayName": String,
    "LoginProfile": Map,
    "Groups": List,
    "MobilePhone": String,
    "Email": String,
    "Comments": String,
    "Policies": List,
    "PolicyAttachments": Map,
    "DeletionForce": Boolean
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

UserName

String

RAM用户的名称。

长度为1~64个字符,可包含英文字母、数字、半角句号(.)、短划线(-)和下划线(_)。

DisplayName

String

RAM用户的显示名称。

长度为1~128个字符。

LoginProfile

Map

RAM用户的登录配置。

更多信息,请参见LoginProfile属性

Groups

List

RAM用户加入的用户组。

MobilePhone

String

RAM用户的手机号码。

Email

String

RAM用户的邮箱。

Comments

String

备注。

长度为1~128个字符。

Policies

List

适用于RAM用户的权限策略。

更多信息,请参见Policies属性

PolicyAttachments

Map

要添加的系统策略和自定义策略名称。

更多信息,请参见PolicyAttachments属性

DeletionForce

Boolean

是否强制解绑RAM用户的权限策略。

取值:

  • true:强制解绑。

  • false(默认值):不强制解绑。

LoginProfile语法

"LoginProfile": {
  "MFABindRequired": Boolean,
  "Password": String,
  "PasswordResetRequired": Boolean
}            

LoginProfile属性

属性名称

类型

必须

允许更新

描述

约束

MFABindRequired

Boolean

是否强制要求RAM用户开启多因素认证。

取值:

  • true:要求开启。RAM用户在下次登录时必须绑定多因素认证设备。

  • false:不要求开启。

Password

String

RAM用户的控制台登录新密码。

密码必须符合密码强度要求,长度为8~32个字符。

PasswordResetRequired

Boolean

RAM用户在下次登录时是否必须重置密码。

取值:

  • true:必须重置密码。

  • false:无需重置密码。

Policies语法

"Policies": [
  {
    "PolicyName": String,
    "PolicyDocument": Map,
    "Description": String,
    "IgnoreExisting": Boolean
  }
]            

Policies属性

属性名称

类型

必须

允许更新

描述

约束

Description

String

描述。

长度为1~1024个字符。

PolicyName

String

权限策略名称。

长度为1~128个字符,可包含英文字母、数字和短划线(-)。

PolicyDocument

Map

权限策略内容。

长度不超过2048个字符。

更多信息,请参见PolicyDocument属性

IgnoreExisting

Boolean

是否忽略现有策略。

取值:

  • true:ROS不会检查唯一性。如果存在相同名称的策略,则忽略策略创建过程。如果策略不是由ROS创建的,它将在更新和删除阶段被忽略。 

  • false:ROS将执行唯一性检查。如果存在具有相同名称的策略,则在创建该策略时将报告错误。

PolicyDocument语法

"PolicyDocument": {
  "Version": String,
  "Statement": List
}

PolicyDocument属性

属性名称

类型

必须

允许更新

描述

约束

Version

String

权限策略版本。

Statement

List

权限策略具体规则。

更多信息,请参见Statement属性

Statement语法

"Statement": [
  {
    "Condition": Map,
    "Action": List,
    "Resource": List,
    "Effect": String
  }
]

Statement属性

属性名称

类型

必须

允许更新

描述

约束

Condition

Map

授权生效的限制条件。

Action

List

权限策略针对的具体操作。

Resource

List

权限策略针对的具体资源。

Effect

String

授权效力。

取值:

  • Allow:允许。

  • Deny:拒绝。

PolicyAttachments语法

"PolicyAttachments": {
  "Custom": List,
  "System": List
}

PolicyAttachments属性

属性名称

类型

必须

允许更新

描述

约束

Custom

List

自定义策略名称列表。

策略数量小于等于5。

System

List

系统策略名称列表。

策略数量小于等于20。

返回值

Fn::GetAtt

  • UserName:RAM用户名称。

  • UserId:RAM用户ID。

  • CreateDate:RAM用户创建时间。

  • LastLoginDate:RAM用户最后登录时间。

示例

场景 1 :创建RAM用户

ROSTemplateFormatVersion: '2015-09-01'
Description: Test RAM User
Parameters: {}
Resources:
  User:
    Type: ALIYUN::RAM::User
    Properties:
      UserName: dev
      Policies:
        - PolicyName:
            Fn::Join:
              - '-'
              - - StackId
                - Ref: ALIYUN::StackId
          PolicyDocument:
            Statement:
              - Action:
                  - oss:*
                Effect: Allow
                Resource:
                  - '*'
            Version: '1'
Outputs: {}
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": "Test RAM User",
  "Parameters": {
  },
  "Resources": {
    "User": {
      "Type": "ALIYUN::RAM::User",
      "Properties": {
        "UserName": "dev",
        "Policies": [
          {
            "PolicyName": {
              "Fn::Join": [
                "-",
                [
                  "StackId",
                  {
                    "Ref": "ALIYUN::StackId"
                  }
                ]
              ]
            },
            "PolicyDocument": {
              "Statement": [
                {
                  "Action": [
                    "oss:*"
                  ],
                  "Effect": "Allow",
                  "Resource": [
                    "*"
                  ]
                }
              ],
              "Version": "1"
            }
          }
        ]
      }
    }
  },
  "Outputs": {
  }
}

场景 2 :创建RAM用户,并创建AccessKey

ROSTemplateFormatVersion: '2015-09-01'
Conditions:
  CreateInstance:
    Fn::Equals:
      - Ref: SelectInstance
      - false
Parameters:
  UserName:
    Type: String
    Description: 自定义RAM用户名称
    Label:
      zh-cn: RAM用户名称
      en: RAM User Name
    Default: test123123123
  RoleName:
    Type: String
    Description: 自定义RAM角色名称
    Label:
      zh-cn: RAM角色名称
      en: RAM Rol Name
    Default: test123123123
  SelectInstance:
    Type: Boolean
    Label:
      en: Whether to select an existing Bucket
      zh-cn: 是否选择已有Bucket
    Default: true
  ExistBucketName:
    Type: String
    Label:
      en: Existing Bucket
      zh-cn: 已有Bucket
    AssociationProperty: ALIYUN::OSS::Bucket::BucketName
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${SelectInstance}
            - true
    Default: ''
  BucketName:
    Type: String
    Label:
      zh-cn: 新建存储空间名称
      en: NewBucketName
    Description:
      zh-cn: Bucket 名称在 OSS 范围内必须全局唯一。长度为3~63个字符。必须以小写英文字母或数字开头和结尾,可包含小写英文字母、数字和短划线(-)。
      en: Bucket names must be globally unique within the scope of OSS. The length is 3~63 characters. Must start and end with a lowercase English letter or number, and can contain lowercase English letters, numbers, and dashes (-).
    AssociationProperty: AutoCompleteInput
    AssociationPropertyMetadata:
      Length: 6
      Prefix: my-bucketname-
      CharacterClasses:
        - Class: lowercase
          min: 1
      Visible:
        Condition:
          Fn::Equals:
            - ${SelectInstance}
            - false
    AllowedPattern: ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$
  AccessControl:
    Type: String
    Label:
      en: Access Control
      zh-cn: 读写权限
    Description:
      en: Set the access permission of the bucket
      zh-cn: 设置Bucket读写权限
    Default: private
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${SelectInstance}
            - false
    AllowedValues:
      - private
      - public-read
      - public-read-write
Resources:
  RamUser:
    Type: ALIYUN::RAM::User
    Properties:
      UserName:
        Ref: UserName
  RamAK:
    Type: ALIYUN::RAM::AccessKey
    Properties:
      UserName:
        Fn::GetAtt:
          - RamUser
          - UserName
    DependsOn: RamUser
  MyBucket:
    Condition: CreateInstance
    Type: ALIYUN::OSS::Bucket
    Properties:
      AccessControl:
        Ref: AccessControl
      BucketName:
        Ref: BucketName
  Role:
    Type: ALIYUN::RAM::Role
    Properties:
      RoleName:
        Ref: RoleName
      AssumeRolePolicyDocument:
        Version: '1'
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              RAM:
                - Fn::Sub: acs:ram::${ALIYUN::TenantId}:root
      Policies:
        - PolicyName:
            Fn::Join:
              - ''
              - - Policy-
                - Ref: ALIYUN::StackId
          PolicyDocument:
            Version: '1'
            Statement:
              - Effect: Allow
                Action:
                  - oss:PutObject
                Resource:
                  - Fn::Sub:
                      - acs:oss:*:*:${BucketName}/*
                      - BucketName:
                          Fn::If:
                            - CreateInstance
                            - Ref: BucketName
                            - Ref: ExistBucketName
Outputs:
  AKSecret:
    Value:
      Fn::GetAtt:
        - RamAK
        - AccessKeySecret
  AKId:
    Value:
      Fn::GetAtt:
        - RamAK
        - AccessKeyId
  UserId:
    Value:
      Fn::GetAtt:
        - RamUser
        - UserId
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - SelectInstance
          - ExistBucketName
          - BucketName
          - AccessControl
        Label:
          default: OSS
      - Parameters:
          - UserName
          - RoleName
        Label:
          default: RAM
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Conditions": {
    "CreateInstance": {
      "Fn::Equals": [
        {
          "Ref": "SelectInstance"
        },
        false
      ]
    }
  },
  "Parameters": {
    "UserName": {
      "Type": "String",
      "Description": "自定义RAM用户名称",
      "Label": {
        "zh-cn": "RAM用户名称",
        "en": "RAM User Name"
      },
      "Default": "test123123123"
    },
    "RoleName": {
      "Type": "String",
      "Description": "自定义RAM角色名称",
      "Label": {
        "zh-cn": "RAM角色名称",
        "en": "RAM Rol Name"
      },
      "Default": "test123123123"
    },
    "SelectInstance": {
      "Type": "Boolean",
      "Label": {
        "en": "Whether to select an existing Bucket",
        "zh-cn": "是否选择已有Bucket"
      },
      "Default": true
    },
    "ExistBucketName": {
      "Type": "String",
      "Label": {
        "en": "Existing Bucket",
        "zh-cn": "已有Bucket"
      },
      "AssociationProperty": "ALIYUN::OSS::Bucket::BucketName",
      "AssociationPropertyMetadata": {
        "Visible": {
          "Condition": {
            "Fn::Equals": [
              "${SelectInstance}",
              true
            ]
          }
        }
      },
      "Default": ""
    },
    "BucketName": {
      "Type": "String",
      "Label": {
        "zh-cn": "新建存储空间名称",
        "en": "NewBucketName"
      },
      "Description": {
        "zh-cn": "Bucket 名称在 OSS 范围内必须全局唯一。长度为3~63个字符。必须以小写英文字母或数字开头和结尾,可包含小写英文字母、数字和短划线(-)。",
        "en": "Bucket names must be globally unique within the scope of OSS. The length is 3~63 characters. Must start and end with a lowercase English letter or number, and can contain lowercase English letters, numbers, and dashes (-)."
      },
      "AssociationProperty": "AutoCompleteInput",
      "AssociationPropertyMetadata": {
        "Length": 6,
        "Prefix": "my-bucketname-",
        "CharacterClasses": [
          {
            "Class": "lowercase",
            "min": 1
          }
        ],
        "Visible": {
          "Condition": {
            "Fn::Equals": [
              "${SelectInstance}",
              false
            ]
          }
        }
      },
      "AllowedPattern": "^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$"
    },
    "AccessControl": {
      "Type": "String",
      "Label": {
        "en": "Access Control",
        "zh-cn": "读写权限"
      },
      "Description": {
        "en": "Set the access permission of the bucket",
        "zh-cn": "设置Bucket读写权限"
      },
      "Default": "private",
      "AssociationPropertyMetadata": {
        "Visible": {
          "Condition": {
            "Fn::Equals": [
              "${SelectInstance}",
              false
            ]
          }
        }
      },
      "AllowedValues": [
        "private",
        "public-read",
        "public-read-write"
      ]
    }
  },
  "Resources": {
    "RamUser": {
      "Type": "ALIYUN::RAM::User",
      "Properties": {
        "UserName": {
          "Ref": "UserName"
        }
      }
    },
    "RamAK": {
      "Type": "ALIYUN::RAM::AccessKey",
      "Properties": {
        "UserName": {
          "Fn::GetAtt": [
            "RamUser",
            "UserName"
          ]
        }
      },
      "DependsOn": "RamUser"
    },
    "MyBucket": {
      "Condition": "CreateInstance",
      "Type": "ALIYUN::OSS::Bucket",
      "Properties": {
        "AccessControl": {
          "Ref": "AccessControl"
        },
        "BucketName": {
          "Ref": "BucketName"
        }
      }
    },
    "Role": {
      "Type": "ALIYUN::RAM::Role",
      "Properties": {
        "RoleName": {
          "Ref": "RoleName"
        },
        "AssumeRolePolicyDocument": {
          "Version": "1",
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "RAM": [
                  {
                    "Fn::Sub": "acs:ram::${ALIYUN::TenantId}:root"
                  }
                ]
              }
            }
          ]
        },
        "Policies": [
          {
            "PolicyName": {
              "Fn::Join": [
                "",
                [
                  "Policy-",
                  {
                    "Ref": "ALIYUN::StackId"
                  }
                ]
              ]
            },
            "PolicyDocument": {
              "Version": "1",
              "Statement": [
                {
                  "Effect": "Allow",
                  "Action": [
                    "oss:PutObject"
                  ],
                  "Resource": [
                    {
                      "Fn::Sub": [
                        "acs:oss:*:*:${BucketName}/*",
                        {
                          "BucketName": {
                            "Fn::If": [
                              "CreateInstance",
                              {
                                "Ref": "BucketName"
                              },
                              {
                                "Ref": "ExistBucketName"
                              }
                            ]
                          }
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          }
        ]
      }
    }
  },
  "Outputs": {
    "AKSecret": {
      "Value": {
        "Fn::GetAtt": [
          "RamAK",
          "AccessKeySecret"
        ]
      }
    },
    "AKId": {
      "Value": {
        "Fn::GetAtt": [
          "RamAK",
          "AccessKeyId"
        ]
      }
    },
    "UserId": {
      "Value": {
        "Fn::GetAtt": [
          "RamUser",
          "UserId"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "SelectInstance",
            "ExistBucketName",
            "BucketName",
            "AccessControl"
          ],
          "Label": {
            "default": "OSS"
          }
        },
        {
          "Parameters": [
            "UserName",
            "RoleName"
          ],
          "Label": {
            "default": "RAM"
          }
        }
      ]
    }
  }
}

场景 3 :创建RAM用户,并创建AccessKey,赋予其对指定 OSS Bucket 的写权限(oss:PutObject)

ROSTemplateFormatVersion: '2015-09-01'
Conditions:
  CreateInstance:
    Fn::Equals:
      - Ref: SelectInstance
      - false
Parameters:
  UserName:
    Type: String
    Description: 自定义RAM用户名称
    Label:
      zh-cn: RAM用户名称
      en: RAM User Name
    Default: test123123123
  RoleName:
    Type: String
    Description: 自定义RAM角色名称
    Label:
      zh-cn: RAM角色名称
      en: RAM Rol Name
    Default: test123123123
  SelectInstance:
    Type: Boolean
    Label:
      en: Whether to select an existing Bucket
      zh-cn: 是否选择已有Bucket
    Default: true
  ExistBucketName:
    Type: String
    Label:
      en: Existing Bucket
      zh-cn: 已有Bucket
    AssociationProperty: ALIYUN::OSS::Bucket::BucketName
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${SelectInstance}
            - true
    Default: ''
  BucketName:
    Type: String
    Label:
      zh-cn: 新建存储空间名称
      en: NewBucketName
    Description:
      zh-cn: Bucket 名称在 OSS 范围内必须全局唯一。长度为3~63个字符。必须以小写英文字母或数字开头和结尾,可包含小写英文字母、数字和短划线(-)。
      en: Bucket names must be globally unique within the scope of OSS. The length is 3~63 characters. Must start and end with a lowercase English letter or number, and can contain lowercase English letters, numbers, and dashes (-).
    AssociationProperty: AutoCompleteInput
    AssociationPropertyMetadata:
      Length: 6
      Prefix: my-bucketname-
      CharacterClasses:
        - Class: lowercase
          min: 1
      Visible:
        Condition:
          Fn::Equals:
            - ${SelectInstance}
            - false
    AllowedPattern: ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$
  AccessControl:
    Type: String
    Label:
      en: Access Control
      zh-cn: 读写权限
    Description:
      en: Set the access permission of the bucket
      zh-cn: 设置Bucket读写权限
    Default: private
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${SelectInstance}
            - false
    AllowedValues:
      - private
      - public-read
      - public-read-write
Resources:
  RamUser:
    Type: ALIYUN::RAM::User
    Properties:
      UserName:
        Ref: UserName
  RamAK:
    Type: ALIYUN::RAM::AccessKey
    Properties:
      UserName:
        Fn::GetAtt:
          - RamUser
          - UserName
    DependsOn: RamUser
  MyBucket:
    Condition: CreateInstance
    Type: ALIYUN::OSS::Bucket
    Properties:
      AccessControl:
        Ref: AccessControl
      BucketName:
        Ref: BucketName
  Role:
    Type: ALIYUN::RAM::Role
    Properties:
      RoleName:
        Ref: RoleName
      AssumeRolePolicyDocument:
        Version: '1'
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              RAM:
                - Fn::Sub: acs:ram::${ALIYUN::TenantId}:root
      Policies:
        - PolicyName:
            Fn::Join:
              - ''
              - - Policy-
                - Ref: ALIYUN::StackId
          PolicyDocument:
            Version: '1'
            Statement:
              - Effect: Allow
                Action:
                  - oss:PutObject
                Resource:
                  - Fn::Sub:
                      - acs:oss:*:*:${BucketName}/*
                      - BucketName:
                          Fn::If:
                            - CreateInstance
                            - Ref: BucketName
                            - Ref: ExistBucketName
Outputs:
  AKSecret:
    Value:
      Fn::GetAtt:
        - RamAK
        - AccessKeySecret
  AKId:
    Value:
      Fn::GetAtt:
        - RamAK
        - AccessKeyId
  UserId:
    Value:
      Fn::GetAtt:
        - RamUser
        - UserId
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - SelectInstance
          - ExistBucketName
          - BucketName
          - AccessControl
        Label:
          default: OSS
      - Parameters:
          - UserName
          - RoleName
        Label:
          default: RAM
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Conditions": {
    "CreateInstance": {
      "Fn::Equals": [
        {
          "Ref": "SelectInstance"
        },
        false
      ]
    }
  },
  "Parameters": {
    "UserName": {
      "Type": "String",
      "Description": "自定义RAM用户名称",
      "Label": {
        "zh-cn": "RAM用户名称",
        "en": "RAM User Name"
      },
      "Default": "test123123123"
    },
    "RoleName": {
      "Type": "String",
      "Description": "自定义RAM角色名称",
      "Label": {
        "zh-cn": "RAM角色名称",
        "en": "RAM Rol Name"
      },
      "Default": "test123123123"
    },
    "SelectInstance": {
      "Type": "Boolean",
      "Label": {
        "en": "Whether to select an existing Bucket",
        "zh-cn": "是否选择已有Bucket"
      },
      "Default": true
    },
    "ExistBucketName": {
      "Type": "String",
      "Label": {
        "en": "Existing Bucket",
        "zh-cn": "已有Bucket"
      },
      "AssociationProperty": "ALIYUN::OSS::Bucket::BucketName",
      "AssociationPropertyMetadata": {
        "Visible": {
          "Condition": {
            "Fn::Equals": [
              "${SelectInstance}",
              true
            ]
          }
        }
      },
      "Default": ""
    },
    "BucketName": {
      "Type": "String",
      "Label": {
        "zh-cn": "新建存储空间名称",
        "en": "NewBucketName"
      },
      "Description": {
        "zh-cn": "Bucket 名称在 OSS 范围内必须全局唯一。长度为3~63个字符。必须以小写英文字母或数字开头和结尾,可包含小写英文字母、数字和短划线(-)。",
        "en": "Bucket names must be globally unique within the scope of OSS. The length is 3~63 characters. Must start and end with a lowercase English letter or number, and can contain lowercase English letters, numbers, and dashes (-)."
      },
      "AssociationProperty": "AutoCompleteInput",
      "AssociationPropertyMetadata": {
        "Length": 6,
        "Prefix": "my-bucketname-",
        "CharacterClasses": [
          {
            "Class": "lowercase",
            "min": 1
          }
        ],
        "Visible": {
          "Condition": {
            "Fn::Equals": [
              "${SelectInstance}",
              false
            ]
          }
        }
      },
      "AllowedPattern": "^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$"
    },
    "AccessControl": {
      "Type": "String",
      "Label": {
        "en": "Access Control",
        "zh-cn": "读写权限"
      },
      "Description": {
        "en": "Set the access permission of the bucket",
        "zh-cn": "设置Bucket读写权限"
      },
      "Default": "private",
      "AssociationPropertyMetadata": {
        "Visible": {
          "Condition": {
            "Fn::Equals": [
              "${SelectInstance}",
              false
            ]
          }
        }
      },
      "AllowedValues": [
        "private",
        "public-read",
        "public-read-write"
      ]
    }
  },
  "Resources": {
    "RamUser": {
      "Type": "ALIYUN::RAM::User",
      "Properties": {
        "UserName": {
          "Ref": "UserName"
        }
      }
    },
    "RamAK": {
      "Type": "ALIYUN::RAM::AccessKey",
      "Properties": {
        "UserName": {
          "Fn::GetAtt": [
            "RamUser",
            "UserName"
          ]
        }
      },
      "DependsOn": "RamUser"
    },
    "MyBucket": {
      "Condition": "CreateInstance",
      "Type": "ALIYUN::OSS::Bucket",
      "Properties": {
        "AccessControl": {
          "Ref": "AccessControl"
        },
        "BucketName": {
          "Ref": "BucketName"
        }
      }
    },
    "Role": {
      "Type": "ALIYUN::RAM::Role",
      "Properties": {
        "RoleName": {
          "Ref": "RoleName"
        },
        "AssumeRolePolicyDocument": {
          "Version": "1",
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "RAM": [
                  {
                    "Fn::Sub": "acs:ram::${ALIYUN::TenantId}:root"
                  }
                ]
              }
            }
          ]
        },
        "Policies": [
          {
            "PolicyName": {
              "Fn::Join": [
                "",
                [
                  "Policy-",
                  {
                    "Ref": "ALIYUN::StackId"
                  }
                ]
              ]
            },
            "PolicyDocument": {
              "Version": "1",
              "Statement": [
                {
                  "Effect": "Allow",
                  "Action": [
                    "oss:PutObject"
                  ],
                  "Resource": [
                    {
                      "Fn::Sub": [
                        "acs:oss:*:*:${BucketName}/*",
                        {
                          "BucketName": {
                            "Fn::If": [
                              "CreateInstance",
                              {
                                "Ref": "BucketName"
                              },
                              {
                                "Ref": "ExistBucketName"
                              }
                            ]
                          }
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          }
        ]
      }
    }
  },
  "Outputs": {
    "AKSecret": {
      "Value": {
        "Fn::GetAtt": [
          "RamAK",
          "AccessKeySecret"
        ]
      }
    },
    "AKId": {
      "Value": {
        "Fn::GetAtt": [
          "RamAK",
          "AccessKeyId"
        ]
      }
    },
    "UserId": {
      "Value": {
        "Fn::GetAtt": [
          "RamUser",
          "UserId"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "SelectInstance",
            "ExistBucketName",
            "BucketName",
            "AccessControl"
          ],
          "Label": {
            "default": "OSS"
          }
        },
        {
          "Parameters": [
            "UserName",
            "RoleName"
          ],
          "Label": {
            "default": "RAM"
          }
        }
      ]
    }
  }
}

场景 4 :创建具有不同策略的用户组的用户

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 创建子账户,分配至用户组与管理员组,启用登录,生成访问密钥,附带读取ECS和OSS权限策略。
  en: Create sub-accounts, allocate them to user groups and administrator groups, enable login functionality, generate access keys, and attach read-only policies for Elastic Compute Service (ECS) and Object Storage Service (OSS).
Parameters:
  GroupName1:
    Type: String
    Label:
      en: Group 1 Name
      zh-cn: 用户组1的名称
    Description:
      en: The name of user group 1, <br>Specifies the group name, containing up to 64 characters,English letters, Numbers, or '-' are allowed.
      zh-cn: 用户组1的名称,指定最多包含64个字符、英文字母、数字或“-”的组名。
    ConstraintDescription:
      en: No more than 64 characters,English letters, Numbers, or '-' are allowed.
      zh-cn: 不得超过 64 个字符、英文字母、数字或'-'。
    Default: UserGroup
    AllowedPattern: ^[a-zA-Z0-9\-]+$
    MinLength: 1
    MaxLength: 64
  GroupName2:
    Type: String
    Label:
      en: Group 2 Name
      zh-cn: 用户组2的名称
    Description:
      en: The name of user group 2, <br>Specifies the group name, containing up to 64 characters,English letters, Numbers, or '-' are allowed.
      zh-cn: 用户组2的名称,指定最多包含64个字符、英文字母、数字或“-”的组名。
    ConstraintDescription:
      en: No more than 64 characters,English letters, Numbers, or '-' are allowed.
      zh-cn: 不得超过 64 个字符、英文字母、数字或'-'。
    Default: AdminGroup
    AllowedPattern: ^[a-zA-Z0-9\-]+$
    MinLength: 1
    MaxLength: 64
  UserName:
    Type: String
    Label:
      en: User Name
      zh-cn: 用户名称
    Description:
      en: The user name cannot already exist,<br>Contains english letters, numbers,'.' , '_' or '-', not more than 64 characters.
      zh-cn: 不能是已经存在的用户名,<br>用户名可包含英文字母,数字,'.', '_'或'-',不超过64个字符。
    ConstraintDescription:
      en: No more than 64 characters,English letters, Numbers, or '-' are allowed.
      zh-cn: 不得超过 64 个字符、英文字母、数字或'-'。
    Default: test-user
    AllowedPattern: '[a-zA-Z0-9\.\-\_]+$'
    MinLength: 1
    MaxLength: 64
  UserPassword:
    Type: String
    Label:
      en: User Password
      zh-cn: 用户密码
    Description:
      en: Specify a password, which must meet the password strength requirements;<br>About password strength policy, Please refer to the <a href='https://help.aliyun.com/document_detail/28740.html' target='_blank'><b><font color='blue'>GetPasswordPolicy</font></b><font color='blue'></a>.
      zh-cn: 指定密码,必须满足密码强度要求;关于密码强度策略,请参阅<a href='https://help.aliyun.com/document_detail/28740.html' target='_blank'><b><font color='blue'>GetPasswordPolicy</font></b><font color='blue'></a>。
    NoEcho: true
Resources:
  RamGroup1:
    Type: ALIYUN::RAM::Group
    Properties:
      GroupName:
        Ref: GroupName1
  RamGroup2:
    Type: ALIYUN::RAM::Group
    Properties:
      GroupName:
        Ref: GroupName2
  RamUser:
    Type: ALIYUN::RAM::User
    Properties:
      Groups:
        - Ref: RamGroup1
        - Ref: RamGroup2
      LoginProfile:
        Password:
          Ref: UserPassword
        PasswordResetRequired: false
      UserName:
        Ref: UserName
  RamAK:
    Type: ALIYUN::RAM::AccessKey
    Properties:
      UserName:
        Fn::GetAtt:
          - RamUser
          - UserName
  RamManagedPolicy1:
    Type: ALIYUN::RAM::ManagedPolicy
    Properties:
      Groups:
        - Ref: RamGroup1
      PolicyDocument:
        Statement:
          - Action:
              - ecs:Describe*
            Effect: Allow
            Resource:
              - '*'
          - Action:
              - ecs:List*
            Effect: Allow
            Resource:
              - '*'
          - Action:
              - vpc:DescribeVpcs
              - vpc:DescribeVSwitches
            Effect: Allow
            Resource:
              - '*'
        Version: '1'
      PolicyName:
        Fn::Join:
          - '-'
          - - ECSReadOnly
            - StackId
            - Ref: ALIYUN::StackId
  RamManagedPolicy2:
    Type: ALIYUN::RAM::ManagedPolicy
    Properties:
      Groups:
        - Ref: RamGroup2
      PolicyDocument:
        Statement:
          - Action:
              - oss:*
            Effect: Allow
            Resource:
              - '*'
        Version: '1'
      PolicyName:
        Fn::Join:
          - '-'
          - - OSSReadOnly
            - StackId
            - Ref: ALIYUN::StackId
Outputs:
  RamAccessKeyId:
    Value:
      Fn::GetAtt:
        - RamAK
        - AccessKeyId
  RamUserId:
    Value:
      Fn::GetAtt:
        - RamUser
        - UserId
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - GroupName1
          - GroupName2
          - UserName
          - UserPassword
        Label:
          default: RAM
    TemplateTags:
      - acs:example:弹性计算:创建具有不同策略的用户组的用户
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "创建子账户,分配至用户组与管理员组,启用登录,生成访问密钥,附带读取ECS和OSS权限策略。",
    "en": "Create sub-accounts, allocate them to user groups and administrator groups, enable login functionality, generate access keys, and attach read-only policies for Elastic Compute Service (ECS) and Object Storage Service (OSS)."
  },
  "Parameters": {
    "GroupName1": {
      "Type": "String",
      "Label": {
        "en": "Group 1 Name",
        "zh-cn": "用户组1的名称"
      },
      "Description": {
        "en": "The name of user group 1, <br>Specifies the group name, containing up to 64 characters,English letters, Numbers, or '-' are allowed.",
        "zh-cn": "用户组1的名称,指定最多包含64个字符、英文字母、数字或“-”的组名。"
      },
      "ConstraintDescription": {
        "en": "No more than 64 characters,English letters, Numbers, or '-' are allowed.",
        "zh-cn": "不得超过 64 个字符、英文字母、数字或'-'。"
      },
      "Default": "UserGroup",
      "AllowedPattern": "^[a-zA-Z0-9\\-]+$",
      "MinLength": 1,
      "MaxLength": 64
    },
    "GroupName2": {
      "Type": "String",
      "Label": {
        "en": "Group 2 Name",
        "zh-cn": "用户组2的名称"
      },
      "Description": {
        "en": "The name of user group 2, <br>Specifies the group name, containing up to 64 characters,English letters, Numbers, or '-' are allowed.",
        "zh-cn": "用户组2的名称,指定最多包含64个字符、英文字母、数字或“-”的组名。"
      },
      "ConstraintDescription": {
        "en": "No more than 64 characters,English letters, Numbers, or '-' are allowed.",
        "zh-cn": "不得超过 64 个字符、英文字母、数字或'-'。"
      },
      "Default": "AdminGroup",
      "AllowedPattern": "^[a-zA-Z0-9\\-]+$",
      "MinLength": 1,
      "MaxLength": 64
    },
    "UserName": {
      "Type": "String",
      "Label": {
        "en": "User Name",
        "zh-cn": "用户名称"
      },
      "Description": {
        "en": "The user name cannot already exist,<br>Contains english letters, numbers,'.' , '_' or '-', not more than 64 characters.",
        "zh-cn": "不能是已经存在的用户名,<br>用户名可包含英文字母,数字,'.', '_'或'-',不超过64个字符。"
      },
      "ConstraintDescription": {
        "en": "No more than 64 characters,English letters, Numbers, or '-' are allowed.",
        "zh-cn": "不得超过 64 个字符、英文字母、数字或'-'。"
      },
      "Default": "test-user",
      "AllowedPattern": "[a-zA-Z0-9\\.\\-\\_]+$",
      "MinLength": 1,
      "MaxLength": 64
    },
    "UserPassword": {
      "Type": "String",
      "Label": {
        "en": "User Password",
        "zh-cn": "用户密码"
      },
      "Description": {
        "en": "Specify a password, which must meet the password strength requirements;<br>About password strength policy, Please refer to the <a href='https://help.aliyun.com/document_detail/28740.html' target='_blank'><b><font color='blue'>GetPasswordPolicy</font></b><font color='blue'></a>.",
        "zh-cn": "指定密码,必须满足密码强度要求;关于密码强度策略,请参阅<a href='https://help.aliyun.com/document_detail/28740.html' target='_blank'><b><font color='blue'>GetPasswordPolicy</font></b><font color='blue'></a>。"
      },
      "NoEcho": true
    }
  },
  "Resources": {
    "RamGroup1": {
      "Type": "ALIYUN::RAM::Group",
      "Properties": {
        "GroupName": {
          "Ref": "GroupName1"
        }
      }
    },
    "RamGroup2": {
      "Type": "ALIYUN::RAM::Group",
      "Properties": {
        "GroupName": {
          "Ref": "GroupName2"
        }
      }
    },
    "RamUser": {
      "Type": "ALIYUN::RAM::User",
      "Properties": {
        "Groups": [
          {
            "Ref": "RamGroup1"
          },
          {
            "Ref": "RamGroup2"
          }
        ],
        "LoginProfile": {
          "Password": {
            "Ref": "UserPassword"
          },
          "PasswordResetRequired": false
        },
        "UserName": {
          "Ref": "UserName"
        }
      }
    },
    "RamAK": {
      "Type": "ALIYUN::RAM::AccessKey",
      "Properties": {
        "UserName": {
          "Fn::GetAtt": [
            "RamUser",
            "UserName"
          ]
        }
      }
    },
    "RamManagedPolicy1": {
      "Type": "ALIYUN::RAM::ManagedPolicy",
      "Properties": {
        "Groups": [
          {
            "Ref": "RamGroup1"
          }
        ],
        "PolicyDocument": {
          "Statement": [
            {
              "Action": [
                "ecs:Describe*"
              ],
              "Effect": "Allow",
              "Resource": [
                "*"
              ]
            },
            {
              "Action": [
                "ecs:List*"
              ],
              "Effect": "Allow",
              "Resource": [
                "*"
              ]
            },
            {
              "Action": [
                "vpc:DescribeVpcs",
                "vpc:DescribeVSwitches"
              ],
              "Effect": "Allow",
              "Resource": [
                "*"
              ]
            }
          ],
          "Version": "1"
        },
        "PolicyName": {
          "Fn::Join": [
            "-",
            [
              "ECSReadOnly",
              "StackId",
              {
                "Ref": "ALIYUN::StackId"
              }
            ]
          ]
        }
      }
    },
    "RamManagedPolicy2": {
      "Type": "ALIYUN::RAM::ManagedPolicy",
      "Properties": {
        "Groups": [
          {
            "Ref": "RamGroup2"
          }
        ],
        "PolicyDocument": {
          "Statement": [
            {
              "Action": [
                "oss:*"
              ],
              "Effect": "Allow",
              "Resource": [
                "*"
              ]
            }
          ],
          "Version": "1"
        },
        "PolicyName": {
          "Fn::Join": [
            "-",
            [
              "OSSReadOnly",
              "StackId",
              {
                "Ref": "ALIYUN::StackId"
              }
            ]
          ]
        }
      }
    }
  },
  "Outputs": {
    "RamAccessKeyId": {
      "Value": {
        "Fn::GetAtt": [
          "RamAK",
          "AccessKeyId"
        ]
      }
    },
    "RamUserId": {
      "Value": {
        "Fn::GetAtt": [
          "RamUser",
          "UserId"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "GroupName1",
            "GroupName2",
            "UserName",
            "UserPassword"
          ],
          "Label": {
            "default": "RAM"
          }
        }
      ],
      "TemplateTags": [
        "acs:example:弹性计算:创建具有不同策略的用户组的用户"
      ]
    }
  }
}