Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
Last active April 10, 2024 00:41
Show Gist options
  • Save MatthewJDavis/a6e91b79538f5e2e7c566449f2d3d957 to your computer and use it in GitHub Desktop.
Save MatthewJDavis/a6e91b79538f5e2e7c566449f2d3d957 to your computer and use it in GitHub Desktop.
Example Terraform to show how you can retrieve the MS Graph permissions with Terraform.
terraform {
required_providers {
azuread = {
source = "hashicorp/azuread"
}
}
}
# Authenticated via the Azure CLI
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
}
output "user_read_all" {
value = data.azuread_service_principal.msgraph.app_role_ids["User.Read.All"]
}
output "mail_readbasic_all" {
value = data.azuread_service_principal.msgraph.app_role_ids["Mail.ReadBasic.All"]
}
# Example how to create an app with the requried MS Graph Permission.
resource "azuread_application" "directory_role_app" {
display_name = "exampleApp"
identifier_uris = ["api://example-app"]
sign_in_audience = "AzureADMyOrg"
required_resource_access {
resource_app_id = "00000003-0000-0000-c000-000000000000" # MS Graph app id.
resource_access {
id = data.azuread_service_principal.msgraph.app_role_ids["User.Read.All"] # User.Read.All id.
type = "Role"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment