日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

使用Terraform創建角色并綁定自定義權限策略

本文介紹如何使用Terraform創建角色并綁定權限策略。

說明

本教程所含示例代碼支持一鍵運行,您可以直接運行代碼。一鍵運行

前提條件

在開始之前,請您確保完成以下操作:

操作步驟

  1. 創建RAM角色。

    1. 創建terraform.tf文件,輸入以下內容,并保存在當前的執行目錄中。

      resource "alicloud_ram_role" "role" {
        name = "testRole"
        document = <<EOF
          {
            "Statement": [
              {
                "Action": "sts:AssumeRole",
                "Effect": "Allow",
                "Principal": {
                  "Service": [
                    "apigateway.aliyuncs.com",
                    "ecs.aliyuncs.com"
                  ]
                }
              }
            ],
            "Version": "1"
          }
      EOF
        description = "this is a role test."
        force       = true
      }
    2. 運行terraform apply開始創建。

    3. 運行terraform show查看創建的角色。

  2. 創建自定義權限策略。

    1. terraform.tf文件中增加以下內容。

      resource "alicloud_ram_policy" "policy" {
        policy_name     = "testPolicy"
        policy_document = <<EOF
          {
            "Statement": [
              {
                "Action": [
                  "oss:ListObjects",
                  "oss:GetObject"
                ],
                "Effect": "Deny",
                "Resource": [
                  "acs:oss:*:*:mybucket",
                  "acs:oss:*:*:mybucket/*"
                ]
              }
            ],
              "Version": "1"
          }
      EOF
        description     = "this is a policy test"
        force           = true
      }
    2. 運行terraform apply開始創建。

    3. 運行terraform show查看創建的自定義權限策略。

  3. 為角色綁定權限策略。

    1. terraform.tf文件中增加以下內容。

      resource "alicloud_ram_role_policy_attachment" "attach" {
        policy_name = alicloud_ram_policy.policy.policy_name
        role_name   = alicloud_ram_role.role.name
        policy_type = alicloud_ram_policy.policy.type
      }
    2. 運行terraform apply開始創建。

    3. 運行terraform show查看角色擁有的自定義權限。

操作樣例

說明

當前示例代碼支持一鍵運行,您可以直接運行代碼。一鍵運行

resource "alicloud_ram_role" "role" {
  name        = "testRole"
  document    = <<EOF
    {
      "Statement": [
        {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": [
              "apigateway.aliyuncs.com",
              "ecs.aliyuncs.com"
            ]
          }
        }
      ],
      "Version": "1"
    }
EOF
  description = "this is a role test."
  force       = true
}

resource "alicloud_ram_policy" "policy" {
  policy_name     = "testPolicy"
  policy_document = <<EOF
    {
      "Statement": [
        {
          "Action": [
            "oss:ListObjects",
            "oss:GetObject"
          ],
          "Effect": "Deny",
          "Resource": [
            "acs:oss:*:*:mybucket",
            "acs:oss:*:*:mybucket/*"
          ]
        }
      ],
        "Version": "1"
    }
EOF
  description     = "this is a policy test"
  force           = true
}

resource "alicloud_ram_role_policy_attachment" "attach" {
  policy_name = alicloud_ram_policy.policy.policy_name
  role_name   = alicloud_ram_role.role.name
  policy_type = alicloud_ram_policy.policy.type
}