我正在尝试修改 terraform 的 PIM 角色分配设置,Azure 的 terraform 模块仅提供简单分配 - azurerm_pim_eligible_role_assignment,我尝试使用
powershell中的
Update-MgPolicyRoleManagementPolicyRule
但这仅提供对 Azure Entra 角色的更改
我想修改 Azure RBAC 分配的设置
我尝试使用 Update-MgPolicyRoleManagementPolicyRule,但它不涵盖 Azure RBAC,我还能使用 tf 的 powershell 修改 PIM azurerm_pim_eligible_role_assignment 的设置吗
当我这样做时
Get-MgPolicyRoleManagementPolicyAssignment
我只能看到分配的 Azure Entra 角色
还有哪些其他可能性?
TF 本身并不支持您所要求的内容。这是一个 PowerShell 文件:
param(
[string]$principalId,
[string]$roleId,
[string]$resourceId
)
# Connect to Azure. Use -identity switch if connecting using a preauthenticated context, such as running from a DevOps pipeline
Connect-AzAccount
# Update PIM role assignment
Set-AzRoleAssignment -ObjectId $principalId -RoleDefinitionId $roleId -Scope $resourceId -ResourceName "" -ResourceType "" -EligibleTimeInMinutes 15 -ExpiresInMinutes 60 -Justification "Updating permissions" -MfaRequired $true -ForceApproval "Manual"
然后创建 main.tf 文件,如下所示:
resource "null_resource" "update_pim_role_assignment" {
triggers = {
principal_id = var.principal_id
role_id = var.role_id
resource_id = var.resource_id
}
provisioner "local-exec" {
command = "powershell.exe -File ./update_pim_role_assignment.ps1 -principalId '${var.principal_id}' -roleId '${var.role_id}' -resourceId '${var.resource_id}'"
}
}
不要忘记添加变量。tf:
variable "principal_id" {
description = "Azure AD Object ID of the user or group"
type = string
}
variable "role_id" {
description = "Role Definition ID"
type = string
}
variable "resource_id" {
description = "Resource ID"
type = string
}