@@ -77,12 +77,19 @@ data "azuread_service_principal" "msgraph" {
7777// ---------------------------------------------------------------------------
7878// Create New application in Microsoft Entra ID
7979// ---------------------------------------------------------------------------
80+ data "azuread_application_template" "enterprise_app" {
81+ # will create the application based on this template ID to have features like Provisioning
82+ # available in the enterprise application
83+ template_id = " 8adf8e6e-67b2-4cf2-a259-e3dc5476c621"
84+ }
8085resource "azuread_application" "meshcloud_replicator" {
8186 display_name = " replicator.${ var . service_principal_name_suffix } "
82-
87+ template_id = data . azuread_application_template . enterprise_app . template_id
8388 feature_tags {
8489 enterprise = true
8590 }
91+
92+
8693 web {
8794 implicit_grant {
8895 access_token_issuance_enabled = false
@@ -152,21 +159,16 @@ resource "azuread_application_password" "application_pw" {
152159// ---------------------------------------------------------------------------
153160resource "azuread_service_principal" "meshcloud_replicator" {
154161 application_id = azuread_application. meshcloud_replicator . application_id
155- # The following tags are needed to create an Enterprise Application
156- # See https://github.com/hashicorp/terraform-provider-azuread/issues/7#issuecomment-529597534
157- # tags = [
158- # "WindowsAzureActiveDirectoryIntegratedApp",
159- # ]
162+ feature_tags {
163+ enterprise = true
164+ }
165+ # creating an application base on the template, makes a enterprise application being created
166+ # to use that enterprise application we have to include use_existing line.
167+ # there is caveat here, if an error happens during destorying this enterprise app, Terraform
168+ # might not display it https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/service_principal#use_existing
169+ use_existing = true
160170}
161171
162- # //---------------------------------------------------------------------------
163- # // Generate new password for the service principal
164- # //---------------------------------------------------------------------------
165- # resource "azuread_service_principal_password" "service_principal_pw" {
166- # service_principal_id = azuread_service_principal.meshcloud_replicator.id
167- # end_date = "2999-01-01T01:02:03Z" # no expiry
168- # }
169-
170172// ---------------------------------------------------------------------------
171173// Assign the created ARM role to the Enterprise application
172174// ---------------------------------------------------------------------------
@@ -236,15 +238,3 @@ resource "azurerm_management_group_policy_assignment" "privilege-escalation-prev
236238 policy_definition_id = azurerm_policy_definition. privilege_escalation_prevention . id
237239 management_group_id = var. scope
238240}
239-
240- # Terraform does not find the blueprint service principal, even though I find it with
241- # ` az ad sp list --filter "appId eq 'f71766dc-90d9-4b7d-bd9d-4499c4331c3f'"`
242- # data "azuread_application" "blueprint_service_principal" {
243- # application_id = "f71766dc-90d9-4b7d-bd9d-4499c4331c3f"
244- # }
245-
246- # facilitate migration from v0.1.0 of the module
247- # moved {
248- # from = azuread_application_password.spp_pw
249- # to = azuread_application_password.service_principal_pw
250- # }
0 commit comments