gpt4 book ai didi

azure - 如何通过 Terraform 将虚拟机用户登录角色添加到用户列表?

转载 作者:行者123 更新时间:2023-12-03 01:01:57 25 4
gpt4 key购买 nike

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e3f1e3d3d703d3133" rel="noreferrer noopener nofollow">[email protected]</a> & <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bedcfedddd90ddd1d3" rel="noreferrer noopener nofollow">[email protected]</a>是我们组织的电子邮件地址。这些电子邮件还用作 Azure 登录帐户。我已经设置了 Terraform 代码来使用 AzureAD 访问 Azrue 中的 VM。我的问题是如何将这些帐户授予虚拟机用户登录的角色?

resource "azurerm_role_assignment" "test" {
scope = "${data.azurerm_management_group.primary.id}"
role_definition_id = "Virtual Machine User Login"
principal_id = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0f2e0d0d400d0103" rel="noreferrer noopener nofollow">[email protected]</a>, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d5f7d5e5e135e5250" rel="noreferrer noopener nofollow">[email protected]</a>"
}

official documents表示 principal_id 是要为其分配角色定义的主体(用户、组、服务主体或应用程序)的 ID。电子邮件地址不就是用户的ID吗?

最佳答案

principal_id 应该是用户的对象 ID

1.导航到门户中的 Azure Active Directory -> 用户 -> 按用户主体名称(在您的情况下为电子邮件地址)搜索。

enter image description here

2.点击用户,即可找到Object ID

enter image description here

如果您想添加用户列表作为角色,您可以按如下方式使用。在我的示例中,有两个用户的对象 ID 65c66b3xxxxxxa623338c098bc79xxxxxx58cb26e

data "azurerm_subscription" "primary" {}

data "azurerm_client_config" "test" {}

variable "ids" {
type = list(string)
default = ["65c66b3xxxxxxa623338","c098bc79xxxxxx58cb26e"]
}

resource "azurerm_role_assignment" "test" {
count = "${length(var.ids)}"
scope = "${data.azurerm_management_group.primary.id}"
role_definition_name = "Virtual Machine User Login"
principal_id = "${element(var.ids, count.index)}"
}

关于azure - 如何通过 Terraform 将虚拟机用户登录角色添加到用户列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58916411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com