'Terraform: How to add ad group "admin_users "

resource "azurerm_analysis_services_server" "server" {
  name                    = "analysisservicesserver"
  location                = "northeurope"
  resource_group_name     = azurerm_resource_group.rg.name
  sku                     = "S0"
  admin_users             = ["mygroup"]
  enable_power_bi_service = true

when adding AD group I am getting following error. I am able to add manually via azure portal.

'<pii>adgroup_name</pii>' was not found in your organization's Azure Active Directory. Details: '<pii>The object was not found in Azure Active Directory.</pii>'.\r\n\r\n   at Microsoft.AnalysisServices.Core.AnalysisServicesClient.SendExecuteAndReadResponse(ImpactDetailCollection impacts, Boolean expectEmptyResults, Boolean throwIfError)\r\n   at Microsoft.AnalysisServices.Core.AnalysisServicesClient.Alter(IMajorObject obj, ObjectExpansion expansion, ImpactDetailCollection impact, Boolean allowCreate, XmlaWarningCollection warnings, JaXmlSerializer serializer)\r\n   at Microsoft.AnalysisServices.Core.Server.Update(IMajorObject obj, UpdateOptions options, UpdateMode mode, XmlaWarningCollection warnings, ImpactDetailCollection impactResult)\r\n   at Microsoft.AnalysisServices.Core.Server.SendUpdate(IMajorObject obj, UpdateOptions options, UpdateMode mode, XmlaWarningCollection warnings, ImpactDetailCollection impactResult)\r\n   at Microsoft.AnalysisServices.MajorObject.Update(UpdateOptions options, UpdateMode mode, XmlaWarningCollection warnings)\r\n   at Microsoft.ASPaaS.Service.Common.Utilities.ProvisionUtility.<>c__DisplayClass36_1.<<UpdateAsAdministratorsAsync>b__0>d.MoveNext()\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.ASPaaS.Service.Common.Utilities.ProvisionUtility.<>c__DisplayClass36_1.<<UpdateAsAdministratorsAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServicePlatform.Core.Flow.FlowContextBase`1.VoidActionWrapper.<Action>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServicePlatform.Core.Flow.FlowContextBase`1.<ExecuteWithRetry>d__14`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at Microsoft.ServicePlatform.Core.Flow.FlowContextBase`1.<ExecuteWithRetry>d__14`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServicePlatform.Core.Flow.FlowContextBase`1.<ExecuteWithRetry>d__13.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ASPaaS.Service.Common.Utilities.ProvisionUtility.<UpdateAsAdministratorsAsync>d__36.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ASPaaS.Worker.Service.JobHandlers.FinalizeServerProvisionJobHandler.<FinalizeServerProvisionAsync>d__9.MoveNext() in X:\\bt\\1234738\\repo\\src\\Apps\\WorkerService\\src\\service\\ASPaaS.Worker.Service\\JobHandlers\\FinalizeServerProvisionJobHandler.cs:line 186"


Solution 1:[1]

To add Ad groups using terraform try the below snippet:

resource "azuread_group" "server" {
  display_name            = "analysisservicesserver"
  security_enabled        = true
  location                = "northeurope"
  resource_group_name     = azurerm_resource_group.rg.name
  sku                     = "S0"
  admin_users             = ["mygroup"]
  enable_power_bi_service = true
  • Instead of giving "azurerm_analysis_services_server" try replacing with "azuread_group"

  • Try including mail_enabled or security_enabled argument while using azuread_group.

For more information, please refer below links:

Manage Azure Active Directory (Azure AD) Users and Groups | Terraform - HashiCorp Learn

Create Azure Active Directory Groups With Terraform – Learn IT And DevOps Daily (ntweekly.com)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RukminiMr-MT