[英]Terraform azurerm read current signed in user?
Looking at the documentation I am unable to find a data source which gives me the current user (preferably the email) logged in to az
when using the azurerm provider in terraform.查看文档,我无法找到在 terraform 中使用 azurerm 提供程序时为我提供登录到
az
的当前用户(最好是电子邮件)的数据源。
This information is available when I run az ad signed-in-user
and I would like to use it to tag the resources created by terraform in azure.当我运行
az ad signed-in-user
时可以使用此信息,我想用它来标记 azure 中 terraform 创建的资源。
Is this not possible right now?现在这不可能吗?
You can use azurerm_client_config to get the AD object ID for the current user and then look up the returned object id with azuread_user to get the user principal name (UPN).您可以使用 azurerm_client_config 获取当前用户的 AD object ID,然后使用 azuread_user 查找返回的 object id 以获取用户主体名称 (UPN)。 Then, the UPN can be assigned to a tag.
然后,可以将 UPN 分配给标签。 In the code below, outputs are not necessary but are helpful for validation because their values appear in the plan.
在下面的代码中,输出不是必需的,但有助于验证,因为它们的值出现在计划中。
data "azurerm_client_config" "current" { }
data "azuread_user" "current_user" {
object_id = data.azurerm_client_config.current.object_id
}
resource "azurerm_resource_group" "example-rg" {
name = "example-rg"
location = "westus"
tags = {
userCreated = data.azuread_user.current_user.user_principal_name
}
}
output "object_id" {
value = data.azurerm_client_config.current.object_id
}
output "user_principal_name" {
value = data.azuread_user.current_user.user_principal_name
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.