AzureAD

Pulumi Official
Package maintained by Pulumi
v5.26.1 published on Monday, Jul 11, 2022 by Pulumi

AppRoleAssignment

Manages an app role assignment for a group, user or service principal. Can be used to grant admin consent for application permissions.

API Permissions

The following API permissions are required in order to use this resource.

When authenticated with a service principal, this resource requires one of the following application roles: AppRoleAssignment.ReadWrite.All and Application.Read.All, or AppRoleAssignment.ReadWrite.All and Directory.Read.All, or Application.ReadWrite.All, or Directory.ReadWrite.All

When authenticated with a user principal, this resource requires one of the following directory roles: Application Administrator or Global Administrator

Example Usage

using Pulumi;
using AzureAD = Pulumi.AzureAD;

class MyStack : Stack
{
    public MyStack()
    {
        var wellKnown = Output.Create(AzureAD.GetApplicationPublishedAppIds.InvokeAsync());
        var msgraph = new AzureAD.ServicePrincipal("msgraph", new AzureAD.ServicePrincipalArgs
        {
            ApplicationId = wellKnown.Apply(wellKnown => wellKnown.Result?.MicrosoftGraph),
            UseExisting = true,
        });
        var exampleApplication = new AzureAD.Application("exampleApplication", new AzureAD.ApplicationArgs
        {
            DisplayName = "example",
            RequiredResourceAccesses = 
            {
                new AzureAD.Inputs.ApplicationRequiredResourceAccessArgs
                {
                    ResourceAppId = wellKnown.Apply(wellKnown => wellKnown.Result?.MicrosoftGraph),
                    ResourceAccesses = 
                    {
                        new AzureAD.Inputs.ApplicationRequiredResourceAccessResourceAccessArgs
                        {
                            Id = msgraph.AppRoleIds.Apply(appRoleIds => appRoleIds.User_Read_All),
                            Type = "Role",
                        },
                        new AzureAD.Inputs.ApplicationRequiredResourceAccessResourceAccessArgs
                        {
                            Id = msgraph.Oauth2PermissionScopeIds.Apply(oauth2PermissionScopeIds => oauth2PermissionScopeIds.User_ReadWrite),
                            Type = "Scope",
                        },
                    },
                },
            },
        });
        var exampleServicePrincipal = new AzureAD.ServicePrincipal("exampleServicePrincipal", new AzureAD.ServicePrincipalArgs
        {
            ApplicationId = exampleApplication.ApplicationId,
        });
        var exampleAppRoleAssignment = new AzureAD.AppRoleAssignment("exampleAppRoleAssignment", new AzureAD.AppRoleAssignmentArgs
        {
            AppRoleId = msgraph.AppRoleIds.Apply(appRoleIds => appRoleIds.User_Read_All),
            PrincipalObjectId = exampleServicePrincipal.ObjectId,
            ResourceObjectId = msgraph.ObjectId,
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-azuread/sdk/v5/go/azuread"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		wellKnown, err := azuread.GetApplicationPublishedAppIds(ctx, nil, nil)
		if err != nil {
			return err
		}
		msgraph, err := azuread.NewServicePrincipal(ctx, "msgraph", &azuread.ServicePrincipalArgs{
			ApplicationId: pulumi.String(wellKnown.Result.MicrosoftGraph),
			UseExisting:   pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		exampleApplication, err := azuread.NewApplication(ctx, "exampleApplication", &azuread.ApplicationArgs{
			DisplayName: pulumi.String("example"),
			RequiredResourceAccesses: ApplicationRequiredResourceAccessArray{
				&ApplicationRequiredResourceAccessArgs{
					ResourceAppId: pulumi.String(wellKnown.Result.MicrosoftGraph),
					ResourceAccesses: ApplicationRequiredResourceAccessResourceAccessArray{
						&ApplicationRequiredResourceAccessResourceAccessArgs{
							Id: msgraph.AppRoleIds.ApplyT(func(appRoleIds map[string]string) (string, error) {
								return appRoleIds.User.Read.All, nil
							}).(pulumi.StringOutput),
							Type: pulumi.String("Role"),
						},
						&ApplicationRequiredResourceAccessResourceAccessArgs{
							Id: msgraph.Oauth2PermissionScopeIds.ApplyT(func(oauth2PermissionScopeIds map[string]string) (string, error) {
								return oauth2PermissionScopeIds.User.ReadWrite, nil
							}).(pulumi.StringOutput),
							Type: pulumi.String("Scope"),
						},
					},
				},
			},
		})
		if err != nil {
			return err
		}
		exampleServicePrincipal, err := azuread.NewServicePrincipal(ctx, "exampleServicePrincipal", &azuread.ServicePrincipalArgs{
			ApplicationId: exampleApplication.ApplicationId,
		})
		if err != nil {
			return err
		}
		_, err = azuread.NewAppRoleAssignment(ctx, "exampleAppRoleAssignment", &azuread.AppRoleAssignmentArgs{
			AppRoleId: msgraph.AppRoleIds.ApplyT(func(appRoleIds map[string]string) (string, error) {
				return appRoleIds.User.Read.All, nil
			}).(pulumi.StringOutput),
			PrincipalObjectId: exampleServicePrincipal.ObjectId,
			ResourceObjectId:  msgraph.ObjectId,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var wellKnown = Output.of(AzureadFunctions.getApplicationPublishedAppIds());

        var msgraph = new ServicePrincipal("msgraph", ServicePrincipalArgs.builder()        
            .applicationId(wellKnown.apply(getApplicationPublishedAppIdsResult -> getApplicationPublishedAppIdsResult.getResult().getMicrosoftGraph()))
            .useExisting(true)
            .build());

        var exampleApplication = new Application("exampleApplication", ApplicationArgs.builder()        
            .displayName("example")
            .requiredResourceAccesses(ApplicationRequiredResourceAccess.builder()
                .resourceAppId(wellKnown.apply(getApplicationPublishedAppIdsResult -> getApplicationPublishedAppIdsResult.getResult().getMicrosoftGraph()))
                .resourceAccesses(                
                    ApplicationRequiredResourceAccessResourceAccess.builder()
                        .id(msgraph.getAppRoleIds().apply(appRoleIds -> appRoleIds.getUser.Read.All()))
                        .type("Role")
                        .build(),
                    ApplicationRequiredResourceAccessResourceAccess.builder()
                        .id(msgraph.getOauth2PermissionScopeIds().apply(oauth2PermissionScopeIds -> oauth2PermissionScopeIds.getUser.ReadWrite()))
                        .type("Scope")
                        .build())
                .build())
            .build());

        var exampleServicePrincipal = new ServicePrincipal("exampleServicePrincipal", ServicePrincipalArgs.builder()        
            .applicationId(exampleApplication.getApplicationId())
            .build());

        var exampleAppRoleAssignment = new AppRoleAssignment("exampleAppRoleAssignment", AppRoleAssignmentArgs.builder()        
            .appRoleId(msgraph.getAppRoleIds().apply(appRoleIds -> appRoleIds.getUser.Read.All()))
            .principalObjectId(exampleServicePrincipal.getObjectId())
            .resourceObjectId(msgraph.getObjectId())
            .build());

        }
}
import pulumi
import pulumi_azuread as azuread

well_known = azuread.get_application_published_app_ids()
msgraph = azuread.ServicePrincipal("msgraph",
    application_id=well_known.result["MicrosoftGraph"],
    use_existing=True)
example_application = azuread.Application("exampleApplication",
    display_name="example",
    required_resource_accesses=[azuread.ApplicationRequiredResourceAccessArgs(
        resource_app_id=well_known.result["MicrosoftGraph"],
        resource_accesses=[
            azuread.ApplicationRequiredResourceAccessResourceAccessArgs(
                id=msgraph.app_role_ids["User.Read.All"],
                type="Role",
            ),
            azuread.ApplicationRequiredResourceAccessResourceAccessArgs(
                id=msgraph.oauth2_permission_scope_ids["User.ReadWrite"],
                type="Scope",
            ),
        ],
    )])
example_service_principal = azuread.ServicePrincipal("exampleServicePrincipal", application_id=example_application.application_id)
example_app_role_assignment = azuread.AppRoleAssignment("exampleAppRoleAssignment",
    app_role_id=msgraph.app_role_ids["User.Read.All"],
    principal_object_id=example_service_principal.object_id,
    resource_object_id=msgraph.object_id)
import * as pulumi from "@pulumi/pulumi";
import * as azuread from "@pulumi/azuread";

const wellKnown = azuread.getApplicationPublishedAppIds({});
const msgraph = new azuread.ServicePrincipal("msgraph", {
    applicationId: wellKnown.then(wellKnown => wellKnown.result?.MicrosoftGraph),
    useExisting: true,
});
const exampleApplication = new azuread.Application("exampleApplication", {
    displayName: "example",
    requiredResourceAccesses: [{
        resourceAppId: wellKnown.then(wellKnown => wellKnown.result?.MicrosoftGraph),
        resourceAccesses: [
            {
                id: msgraph.appRoleIds["User.Read.All"],
                type: "Role",
            },
            {
                id: msgraph.oauth2PermissionScopeIds["User.ReadWrite"],
                type: "Scope",
            },
        ],
    }],
});
const exampleServicePrincipal = new azuread.ServicePrincipal("exampleServicePrincipal", {applicationId: exampleApplication.applicationId});
const exampleAppRoleAssignment = new azuread.AppRoleAssignment("exampleAppRoleAssignment", {
    appRoleId: msgraph.appRoleIds["User.Read.All"],
    principalObjectId: exampleServicePrincipal.objectId,
    resourceObjectId: msgraph.objectId,
});
resources:
  msgraph:
    type: azuread:ServicePrincipal
    properties:
      applicationId: ${wellKnown.result.MicrosoftGraph}
      useExisting: true
  exampleApplication:
    type: azuread:Application
    properties:
      displayName: example
      requiredResourceAccesses:
        - resourceAppId: ${wellKnown.result.MicrosoftGraph}
          resourceAccesses:
            - id: ${msgraph.appRoleIds"User.Read.All"[%!s(MISSING)]}
              type: Role
            - id: ${msgraph.oauth2PermissionScopeIds"User.ReadWrite"[%!s(MISSING)]}
              type: Scope
  exampleServicePrincipal:
    type: azuread:ServicePrincipal
    properties:
      applicationId: ${exampleApplication.applicationId}
  exampleAppRoleAssignment:
    type: azuread:AppRoleAssignment
    properties:
      appRoleId: ${msgraph.appRoleIds"User.Read.All"[%!s(MISSING)]}
      principalObjectId: ${exampleServicePrincipal.objectId}
      resourceObjectId: ${msgraph.objectId}
variables:
  wellKnown:
    Fn::Invoke:
      Function: azuread:getApplicationPublishedAppIds
      Arguments: {}

Create a AppRoleAssignment Resource

new AppRoleAssignment(name: string, args: AppRoleAssignmentArgs, opts?: CustomResourceOptions);
@overload
def AppRoleAssignment(resource_name: str,
                      opts: Optional[ResourceOptions] = None,
                      app_role_id: Optional[str] = None,
                      principal_object_id: Optional[str] = None,
                      resource_object_id: Optional[str] = None)
@overload
def AppRoleAssignment(resource_name: str,
                      args: AppRoleAssignmentArgs,
                      opts: Optional[ResourceOptions] = None)
func NewAppRoleAssignment(ctx *Context, name string, args AppRoleAssignmentArgs, opts ...ResourceOption) (*AppRoleAssignment, error)
public AppRoleAssignment(string name, AppRoleAssignmentArgs args, CustomResourceOptions? opts = null)
public AppRoleAssignment(String name, AppRoleAssignmentArgs args)
public AppRoleAssignment(String name, AppRoleAssignmentArgs args, CustomResourceOptions options)
type: azuread:AppRoleAssignment
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args AppRoleAssignmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args AppRoleAssignmentArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args AppRoleAssignmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args AppRoleAssignmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args AppRoleAssignmentArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

AppRoleAssignment Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The AppRoleAssignment resource accepts the following input properties:

AppRoleId string

The ID of the app role to be assigned. Changing this forces a new resource to be created.

PrincipalObjectId string

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

ResourceObjectId string

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

AppRoleId string

The ID of the app role to be assigned. Changing this forces a new resource to be created.

PrincipalObjectId string

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

ResourceObjectId string

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

appRoleId String

The ID of the app role to be assigned. Changing this forces a new resource to be created.

principalObjectId String

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

resourceObjectId String

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

appRoleId string

The ID of the app role to be assigned. Changing this forces a new resource to be created.

principalObjectId string

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

resourceObjectId string

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

app_role_id str

The ID of the app role to be assigned. Changing this forces a new resource to be created.

principal_object_id str

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

resource_object_id str

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

appRoleId String

The ID of the app role to be assigned. Changing this forces a new resource to be created.

principalObjectId String

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

resourceObjectId String

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

Outputs

All input properties are implicitly available as output properties. Additionally, the AppRoleAssignment resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

PrincipalDisplayName string

The display name of the principal to which the app role is assigned.

PrincipalType string

The object type of the principal to which the app role is assigned.

ResourceDisplayName string

The display name of the application representing the resource.

Id string

The provider-assigned unique ID for this managed resource.

PrincipalDisplayName string

The display name of the principal to which the app role is assigned.

PrincipalType string

The object type of the principal to which the app role is assigned.

ResourceDisplayName string

The display name of the application representing the resource.

id String

The provider-assigned unique ID for this managed resource.

principalDisplayName String

The display name of the principal to which the app role is assigned.

principalType String

The object type of the principal to which the app role is assigned.

resourceDisplayName String

The display name of the application representing the resource.

id string

The provider-assigned unique ID for this managed resource.

principalDisplayName string

The display name of the principal to which the app role is assigned.

principalType string

The object type of the principal to which the app role is assigned.

resourceDisplayName string

The display name of the application representing the resource.

id str

The provider-assigned unique ID for this managed resource.

principal_display_name str

The display name of the principal to which the app role is assigned.

principal_type str

The object type of the principal to which the app role is assigned.

resource_display_name str

The display name of the application representing the resource.

id String

The provider-assigned unique ID for this managed resource.

principalDisplayName String

The display name of the principal to which the app role is assigned.

principalType String

The object type of the principal to which the app role is assigned.

resourceDisplayName String

The display name of the application representing the resource.

Look up an Existing AppRoleAssignment Resource

Get an existing AppRoleAssignment resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: AppRoleAssignmentState, opts?: CustomResourceOptions): AppRoleAssignment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        app_role_id: Optional[str] = None,
        principal_display_name: Optional[str] = None,
        principal_object_id: Optional[str] = None,
        principal_type: Optional[str] = None,
        resource_display_name: Optional[str] = None,
        resource_object_id: Optional[str] = None) -> AppRoleAssignment
func GetAppRoleAssignment(ctx *Context, name string, id IDInput, state *AppRoleAssignmentState, opts ...ResourceOption) (*AppRoleAssignment, error)
public static AppRoleAssignment Get(string name, Input<string> id, AppRoleAssignmentState? state, CustomResourceOptions? opts = null)
public static AppRoleAssignment get(String name, Output<String> id, AppRoleAssignmentState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AppRoleId string

The ID of the app role to be assigned. Changing this forces a new resource to be created.

PrincipalDisplayName string

The display name of the principal to which the app role is assigned.

PrincipalObjectId string

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

PrincipalType string

The object type of the principal to which the app role is assigned.

ResourceDisplayName string

The display name of the application representing the resource.

ResourceObjectId string

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

AppRoleId string

The ID of the app role to be assigned. Changing this forces a new resource to be created.

PrincipalDisplayName string

The display name of the principal to which the app role is assigned.

PrincipalObjectId string

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

PrincipalType string

The object type of the principal to which the app role is assigned.

ResourceDisplayName string

The display name of the application representing the resource.

ResourceObjectId string

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

appRoleId String

The ID of the app role to be assigned. Changing this forces a new resource to be created.

principalDisplayName String

The display name of the principal to which the app role is assigned.

principalObjectId String

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

principalType String

The object type of the principal to which the app role is assigned.

resourceDisplayName String

The display name of the application representing the resource.

resourceObjectId String

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

appRoleId string

The ID of the app role to be assigned. Changing this forces a new resource to be created.

principalDisplayName string

The display name of the principal to which the app role is assigned.

principalObjectId string

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

principalType string

The object type of the principal to which the app role is assigned.

resourceDisplayName string

The display name of the application representing the resource.

resourceObjectId string

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

app_role_id str

The ID of the app role to be assigned. Changing this forces a new resource to be created.

principal_display_name str

The display name of the principal to which the app role is assigned.

principal_object_id str

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

principal_type str

The object type of the principal to which the app role is assigned.

resource_display_name str

The display name of the application representing the resource.

resource_object_id str

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

appRoleId String

The ID of the app role to be assigned. Changing this forces a new resource to be created.

principalDisplayName String

The display name of the principal to which the app role is assigned.

principalObjectId String

The object ID of the user, group or service principal to be assigned this app role. Supported object types are Users, Groups or Service Principals. Changing this forces a new resource to be created.

principalType String

The object type of the principal to which the app role is assigned.

resourceDisplayName String

The display name of the application representing the resource.

resourceObjectId String

The object ID of the service principal representing the resource. Changing this forces a new resource to be created.

Import

App role assignments can be imported using the object ID of the service principal representing the resource and the ID of the app role assignment (note_not_ the ID of the app role), e.g.

 $ pulumi import azuread:index/appRoleAssignment:AppRoleAssignment example 00000000-0000-0000-0000-000000000000/appRoleAssignment/aaBBcDDeFG6h5JKLMN2PQrrssTTUUvWWxxxxxyyyzzz

-> This ID format is unique to Terraform and is composed of the Resource Service Principal Object ID and the ID of the App Role Assignment in the format {ResourcePrincipalID}/appRoleAssignment/{AppRoleAssignmentID}.

Package Details

Repository
https://github.com/pulumi/pulumi-azuread
License
Apache-2.0
Notes

This Pulumi package is based on the azuread Terraform Provider.