How do you provision an azure-native managed identity user assigned identity?
TypeScriptBelow is a simple Pulumi program written in TypeScript that provisions a managed identity user assigned identity using the
azure-native.managedidentity.UserAssignedIdentity
resource. This resource is an Identity resource that is assigned to one or more Azure resources to enable role-based access control (RBAC). More details can be found here.This program creates a new Azure user-assigned managed identity in the specified resource group. The result is exported as a dictionary containing the principal ID and client ID of the created identity.
Program
import * as azure from "@pulumi/azure-native"; // Note: The name of the Resource Group where you want to create the user-assigned managed identity is needed const resourceGroupName = "EXAMPLE_RESOURCE_GROUP_NAME"; // Note: Define a unique name for the user-assigned managed identity const identityName = "EXAMPLE_USER_ASSIGNED_IDENTITY_NAME"; // Provision an Azure User-Assigned Managed Identity. const identity = new azure.managedidentity.UserAssignedIdentity(identityName, { resourceGroupName: resourceGroupName, resourceName: identityName, }); // The Principal ID and Client ID for the created user-assigned identity. export const principalId = identity.principalId; export const clientId = identity.clientId;
Please replace "EXAMPLE_RESOURCE_GROUP_NAME" and "EXAMPLE_USER_ASSIGNED_IDENTITY_NAME" with actual values in accordance with your Azure resources names.
The Azure resource group under the name you specify must exist before you run this program, otherwise, it will fail. The identity name does not need to exist before you run this program, as Pulumi will create it.
Rewrite this program in C#
C#Below is the translated program in C# using Pulumi for Azure, which provisions a user-assigned managed identity:
using Pulumi; using Pulumi.AzureNative.ManagedIdentity; class MyStack : Stack { public MyStack() { // The name of the Resource Group where you want to create the user-assigned managed identity var resourceGroupName = "EXAMPLE_RESOURCE_GROUP_NAME"; // Define a unique name for the user-assigned managed identity var identityName = "EXAMPLE_USER_ASSIGNED_IDENTITY_NAME"; // Provision an Azure User-Assigned Managed Identity var identity = new UserAssignedIdentity(identityName, new UserAssignedIdentityArgs { ResourceGroupName = resourceGroupName, ResourceName = identityName }); // The Principal ID and Client ID for the created user-assigned identity this.PrincipalId = identity.PrincipalId; this.ClientId = identity.ClientId; } [Output] public Output<string> PrincipalId { get; set; } [Output] public Output<string> ClientId { get; set; } }