UNPKG

@pulumi/azuread

Version:

A Pulumi package for creating and managing Azure Active Directory (Azure AD) cloud resources.

164 lines 7.68 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.AppRoleAssignment = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("./utilities"); /** * 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 * * *App role assignment for accessing Microsoft Graph* * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as azuread from "@pulumi/azuread"; * * const wellKnown = azuread.getApplicationPublishedAppIds({}); * const msgraph = new azuread.ServicePrincipal("msgraph", { * clientId: wellKnown.then(wellKnown => wellKnown.result?.microsoftGraph), * useExisting: true, * }); * const example = new azuread.Application("example", { * 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("example", {clientId: example.clientId}); * const exampleAppRoleAssignment = new azuread.AppRoleAssignment("example", { * appRoleId: msgraph.appRoleIds["User.Read.All"], * principalObjectId: exampleServicePrincipal.objectId, * resourceObjectId: msgraph.objectId, * }); * ``` * * *App role assignment for internal application* * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as azuread from "@pulumi/azuread"; * * const internal = new azuread.Application("internal", { * displayName: "internal", * appRoles: [{ * allowedMemberTypes: ["Application"], * description: "Apps can query the database", * displayName: "Query", * enabled: true, * id: "00000000-0000-0000-0000-111111111111", * value: "Query.All", * }], * }); * const internalServicePrincipal = new azuread.ServicePrincipal("internal", {clientId: internal.clientId}); * const example = new azuread.Application("example", { * displayName: "example", * requiredResourceAccesses: [{ * resourceAppId: internal.clientId, * resourceAccesses: [{ * id: internalServicePrincipal.appRoleIds["Query.All"], * type: "Role", * }], * }], * }); * const exampleServicePrincipal = new azuread.ServicePrincipal("example", {clientId: example.clientId}); * const exampleAppRoleAssignment = new azuread.AppRoleAssignment("example", { * appRoleId: internalServicePrincipal.appRoleIds["Query.All"], * principalObjectId: exampleServicePrincipal.objectId, * resourceObjectId: internalServicePrincipal.objectId, * }); * ``` * * *Assign a user and group to an internal application* * * ## 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. * * ```sh * $ pulumi import azuread:index/appRoleAssignment:AppRoleAssignment example /servicePrincipals/00000000-0000-0000-0000-000000000000/appRoleAssignedTo/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 `/servicePrincipals/{ResourcePrincipalID}/appRoleAssignedTo/{AppRoleAssignmentID}`. */ class AppRoleAssignment extends pulumi.CustomResource { /** * Get an existing AppRoleAssignment resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, state, opts) { return new AppRoleAssignment(name, state, Object.assign(Object.assign({}, opts), { id: id })); } /** * Returns true if the given object is an instance of AppRoleAssignment. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === AppRoleAssignment.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["appRoleId"] = state ? state.appRoleId : undefined; resourceInputs["principalDisplayName"] = state ? state.principalDisplayName : undefined; resourceInputs["principalObjectId"] = state ? state.principalObjectId : undefined; resourceInputs["principalType"] = state ? state.principalType : undefined; resourceInputs["resourceDisplayName"] = state ? state.resourceDisplayName : undefined; resourceInputs["resourceObjectId"] = state ? state.resourceObjectId : undefined; } else { const args = argsOrState; if ((!args || args.appRoleId === undefined) && !opts.urn) { throw new Error("Missing required property 'appRoleId'"); } if ((!args || args.principalObjectId === undefined) && !opts.urn) { throw new Error("Missing required property 'principalObjectId'"); } if ((!args || args.resourceObjectId === undefined) && !opts.urn) { throw new Error("Missing required property 'resourceObjectId'"); } resourceInputs["appRoleId"] = args ? args.appRoleId : undefined; resourceInputs["principalObjectId"] = args ? args.principalObjectId : undefined; resourceInputs["resourceObjectId"] = args ? args.resourceObjectId : undefined; resourceInputs["principalDisplayName"] = undefined /*out*/; resourceInputs["principalType"] = undefined /*out*/; resourceInputs["resourceDisplayName"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(AppRoleAssignment.__pulumiType, name, resourceInputs, opts); } } exports.AppRoleAssignment = AppRoleAssignment; /** @internal */ AppRoleAssignment.__pulumiType = 'azuread:index/appRoleAssignment:AppRoleAssignment'; //# sourceMappingURL=appRoleAssignment.js.map