hashicorp / terraform-provider-azuread

Terraform provider for Azure Active Directory
https://registry.terraform.io/providers/hashicorp/azuread/latest/docs
Mozilla Public License 2.0
432 stars 300 forks source link

Add new resource azuread_group_owner for add owner to group #1314

Open abtris opened 9 months ago

abtris commented 9 months ago

Community Note

Description

Add equivalent for az ad group owner add as azuread_group_owner.

I think we need way how to modify owners not just members of groups. API exists and used by AZ CLI.

New or Affected Resource(s)

Potential Terraform Configuration

resource "azuread_group_owner" "example" {
  group_object_id  = azuread_group.example.id
  owner_object_id = data.azuread_user.example.id
}

or

resource "azuread_group_member" "example" {
  group_object_id  = azuread_group.example.id
  owner_object_id = data.azuread_user.example.id
}

References

dszakallas commented 6 months ago

A workaround for the time being:

resource "terraform_data" "owner" {
  triggers_replace = [
    data.azuread_group.the_group.id,
    data.azuread_service_principal.the_user.id
  ]
  input = {
    group_id = data.azuread_group.the_group.id
    owner_id = data.azuread_service_principal.the_user.id
  }
  provisioner "local-exec" {
    command = "az ad group owner add --group ${self.input.group_id} --owner-object-id ${self.input.owner_id}"
  }
  provisioner "local-exec" {
    when    = destroy
    command = "az ad group owner remove --group ${self.input.group_id} --owner-object-id ${self.input.owner_id}"
  }
}