-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add create_service_principal scenario
- Loading branch information
Showing
9 changed files
with
162 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Create Service Principal | ||
|
||
This is a scenario for creating a service principal in Microsoft Entra ID. | ||
|
||
## Deploy resources | ||
|
||
```shell | ||
# Go to the infra directory | ||
cd infra | ||
|
||
# Set scenario name | ||
SCENARIO="create_service_principal" | ||
|
||
# Log in to Azure | ||
az login | ||
|
||
# (Optional) Confirm the details for the currently logged-in user | ||
az ad signed-in-user show | ||
|
||
# Set environment variables | ||
export ARM_SUBSCRIPTION_ID=$(az account show --query id --output tsv) | ||
export TF_VAR_service_principal_name="baseline-environment-on-azure-terraform_tf" | ||
|
||
# Deploy infrastructure | ||
make deploy SCENARIO=$SCENARIO | ||
|
||
# Get output variables | ||
cd scenarios/$SCENARIO | ||
application_object_id=$(terraform output -raw application_object_id) | ||
|
||
# Grant permissions to the application | ||
az ad app permission admin-consent --id $application_object_id | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
terraform { | ||
required_version = ">= 1.6.0" | ||
required_providers { | ||
azuread = { | ||
source = "hashicorp/azuread" | ||
version = "~> 3.0.2" | ||
} | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "~> 4.5.0" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
data "azurerm_subscription" "primary" { | ||
} | ||
|
||
data "azuread_client_config" "client_config" { | ||
} | ||
|
||
data "azuread_application_published_app_ids" "well_known" { | ||
} | ||
|
||
data "azuread_service_principal" "msgraph" { | ||
client_id = data.azuread_application_published_app_ids.well_known.result["MicrosoftGraph"] | ||
} | ||
|
||
resource "azuread_application" "application" { | ||
display_name = var.service_principal_name | ||
owners = [ | ||
data.azuread_client_config.client_config.object_id, | ||
] | ||
required_resource_access { | ||
resource_app_id = data.azuread_application_published_app_ids.well_known.result["MicrosoftGraph"] | ||
resource_access { | ||
id = data.azuread_service_principal.msgraph.app_role_ids["Domain.Read.All"] | ||
type = "Role" | ||
} | ||
resource_access { | ||
id = data.azuread_service_principal.msgraph.app_role_ids["Group.ReadWrite.All"] | ||
type = "Role" | ||
} | ||
resource_access { | ||
id = data.azuread_service_principal.msgraph.app_role_ids["GroupMember.ReadWrite.All"] | ||
type = "Role" | ||
} | ||
resource_access { | ||
id = data.azuread_service_principal.msgraph.app_role_ids["User.ReadWrite.All"] | ||
type = "Role" | ||
} | ||
resource_access { | ||
id = data.azuread_service_principal.msgraph.app_role_ids["Application.ReadWrite.All"] | ||
type = "Role" | ||
} | ||
} | ||
} | ||
|
||
resource "azuread_service_principal" "service_principal" { | ||
client_id = azuread_application.application.client_id | ||
app_role_assignment_required = false | ||
owners = [ | ||
data.azuread_client_config.client_config.object_id, | ||
] | ||
} | ||
|
||
resource "azurerm_role_assignment" "role_assignment_service_principal" { | ||
scope = data.azurerm_subscription.primary.id | ||
role_definition_name = var.role_definition_name | ||
principal_id = azuread_service_principal.service_principal.object_id | ||
} | ||
|
||
resource "azuread_service_principal_password" "service_principal_password" { | ||
service_principal_id = azuread_service_principal.service_principal.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "service_principal_client_id" { | ||
value = azuread_service_principal.service_principal.client_id | ||
description = "Service Principal Client ID" | ||
} | ||
|
||
output "application_object_id" { | ||
value = azuread_application.application.object_id | ||
description = "Application Object ID" | ||
} | ||
|
||
output "tenant_id" { | ||
value = data.azuread_client_config.client_config.tenant_id | ||
description = "Tenant ID" | ||
} | ||
|
||
output "service_principal_password" { | ||
value = azuread_service_principal_password.service_principal_password.value | ||
sensitive = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "service_principal_name" { | ||
description = "Specifies the service principal name" | ||
type = string | ||
default = "baseline-environment-on-azure-terraform_ci" | ||
} | ||
|
||
variable "role_definition_name" { | ||
description = "Specifies the role definition name" | ||
type = string | ||
default = "Contributor" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters