Terraform错误: 添加组成员到组中

huangapple go评论61阅读模式
英文:

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 .

Terraform错误: 添加组成员到组中

Please check the below code .
Or you should have owner role to the group and application .

Terraform错误: 添加组成员到组中

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.
Terraform错误: 添加组成员到组中

Terraform错误: 添加组成员到组中

Reference: azuread_group_member | Resources | hashicorp/azuread | Terraform Registry

huangapple
  • 本文由 发表于 2023年2月24日 00:25:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定