How do I create an Azure User Assigned Identity?
In this guide, we will create an Azure User Assigned Identity using Pulumi. User Assigned Managed Identities allow you to create an identity that can be assigned to one or more Azure resources. This identity can be used to authenticate and authorize access to Azure services and resources.
We will use the azure-native
Pulumi provider to define and deploy the User Assigned Identity. Let’s get started.
import * as pulumi from "@pulumi/pulumi";
import * as azureNative from "@pulumi/azure-native";
// Define the resource group
const resourceGroup = new azureNative.resources.ResourceGroup("exampleResourceGroup", {
location: "WestEurope",
});
// Create a User Assigned Identity
const userAssignedIdentity = new azureNative.managedidentity.UserAssignedIdentity("exampleUserAssignedIdentity", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
});
export const identityId = userAssignedIdentity.id;
export const identityClientId = userAssignedIdentity.clientId;
export const identityPrincipalId = userAssignedIdentity.principalId;
// Output the resource group name
export const resourceGroupName = resourceGroup.name;
Key Points
- Resource Group: We first create a resource group where our User Assigned Identity will reside.
- User Assigned Identity: We then create the User Assigned Identity within the resource group.
- Outputs: We export the identity ID, client ID, and principal ID as stack outputs for reference.
Summary
We have successfully created an Azure User Assigned Identity using Pulumi. This identity can now be assigned to other Azure resources to manage access and authentication.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.