英文:
Terraform Error: Adding Group Member to the Group
问题
抱歉,由于您的请求,我将仅提供代码部分的翻译,如下所示:
We have a Terraform script that creates a new azuread_service_principal and adds it to the existing group.
resource "azuread_application" "workspace_manager" {
display_name = var.workspace_manager_appregistration_name
sign_in_audience = "AzureADMyOrg"
owners = [
data.azurerm_client_config.this.object_id,
var.master_account_id
]
}
resource "azuread_service_principal" "workspace_manager" {
application_id = azuread_application.workspace_manager.application_id
app_role_assignment_required = false
owners = [
data.azurerm_client_config.this.object_id,
var.master_account_id
]
}
resource "azuread_group_member" "workspace_manager" { \\ the error occurs here
group_object_id = var.security_group_id \\ existing azure ad group id
member_object_id = azuread_service_principal.workspace_manager.object_id \\ created one
}
请注意,这部分是您提供的代码的翻译,没有其他内容。如果您需要进一步的信息或帮助,可以随时提出具体问题。
英文:
We have a Terraform script that creates a new azuread_service_principal and adds it to the existing group.
resource "azuread_application" "workspace_manager" {
display_name = var.workspace_manager_appregistration_name
sign_in_audience = "AzureADMyOrg"
owners = [
data.azurerm_client_config.this.object_id,
var.master_account_id
]
}
resource "azuread_service_principal" "workspace_manager" {
application_id = azuread_application.workspace_manager.application_id
app_role_assignment_required = false
owners = [
data.azurerm_client_config.this.object_id,
var.master_account_id
]
}
resource "azuread_group_member" "workspace_manager" { \\ the error occurs here
group_object_id = var.security_group_id \\ existing azure ad group id
member_object_id = azuread_service_principal.workspace_manager.object_id \\ created one
}
This script throws the following error:
╷
│ Error: Adding group member "xxx-xxx-xxx" to group "xxx-xxx-xxx"
│
│ with module.pbi.azuread_group_member.workspace_manager,
│ on pbi\main.tf line 52, in resource "azuread_group_member" "workspace_manager":
│ 52: resource "azuread_group_member" "workspace_manager" {
│
│ GroupsClient.BaseClient.Post(): unexpected status 403 with OData error: Authorization_RequestDenied: Insufficient privileges to complete the operation.
╵
Referring to the documentation article, added Group.ReadWrite.All (application) permission to the Service Principal that runs the script.
Terraform docs article: https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/group_member
Why can I get this error and what are the solutions? What can I try to do?
答案1
得分: 1
除了将**"Group.ReadWrite.All"
应用程序权限添加到服务主体中,还需为服务主体添加"Directory.AccessAsUser.All"
**应用程序权限,以便服务主体可以像用户一样访问目录以添加成员到一个组中。
注意:在添加权限之后,需要由管理员授予应用程序的管理员同意。
请检查下面的代码。
或者您应该对该组和应用程序拥有所有者角色。
代码:
resource "azuread_application" "workspace_manager" {
display_name = "wrkmanapp"
sign_in_audience = "AzureADMyOrg"
owners = [
data.azurerm_client_config.current.object_id,
]
}
resource "azuread_service_principal" "workspace_manager" {
application_id = azuread_application.workspace_manager.application_id
app_role_assignment_required = false
owners = [
data.azurerm_client_config.current.object_id
]
}
data "azuread_user" "example" {
user_principal_name = "xxx@xx.onmicrosoft.com"
}
data "azuread_group" "example" {
display_name = "kavyaMyGroup"
owners = [data.azuread_client_config.current.object_id]
security_enabled = true
members = [
data.azuread_user.example.object_id
# more users
]
}
resource "azuread_group_member" "workspace_manager" {
group_object_id = azuread_group.example.object_id
member_object_id = azuread_service_principal.workspace_manager.object_id
}
成功将服务主体添加到现有组中。
英文:
In addition to addingthe "Group.ReadWrite.All"
application permission to the service principal, also add "Directory.AccessAsUser.All" app permission for service principal to access the directory as a user for adding a member to a group.
Note: After adding permissions note that the admin consent need to be granted for the app by the admin .
Please check the below code .
Or you should have owner role to the group and application .
Code:
resource "azuread_application" "workspace_manager" {
display_name = "wrkmanapp"
sign_in_audience = "AzureADMyOrg"
owners = [
data.azurerm_client_config.current.object_id,
]
}
resource "azuread_service_principal" "workspace_manager" {
application_id = azuread_application.workspace_manager.application_id
app_role_assignment_required = false
owners = [
data.azurerm_client_config.current.object_id
]
}
data "azuread_user" "example" {
//display_name = "userone"
// owners = [data.azuread_client_config.current.object_id]
// password = "notSecure123"
user_principal_name = "xxx@xx.onmicrosoft.com"
}
data "azuread_group" "example" {
display_name = "kavyaMyGroup"
owners = [data.azuread_client_config.current.object_id]
security_enabled = true
members = [
data.azuread_user.example.object_id
# more users
]
}
resource "azuread_group_member" "workspace_manager" {
group_object_id = azuread_group.example.object_id
// group_object_id = "5xxxf318"
member_object_id = azuread_service_principal.workspace_manager.object_id
}
Could add the serviceprincipal to the existing group successfully.
Reference: azuread_group_member | Resources | hashicorp/azuread | Terraform Registry
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论