-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add user assigned identity resource * bicep
- Loading branch information
1 parent
62df432
commit 3e72dcb
Showing
10 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
sdk/provisioning/Azure.Provisioning/src/managedidentities/UserAssignedIdentity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Azure.Core; | ||
using Azure.Provisioning.ResourceManager; | ||
using Azure.ResourceManager.ManagedServiceIdentities; | ||
using Azure.ResourceManager.ManagedServiceIdentities.Models; | ||
|
||
namespace Azure.Provisioning.ManagedServiceIdentities | ||
{ | ||
/// <summary> | ||
/// Represents a user assigned identity. | ||
/// </summary> | ||
public class UserAssignedIdentity : Resource<UserAssignedIdentityData> | ||
{ | ||
// https://learn.microsoft.com/azure/templates/microsoft.insights/2020-02-02/components?pivots=deployment-language-bicep | ||
private const string ResourceTypeName = "Microsoft.ManagedIdentity/userAssignedIdentities"; | ||
// https://learn.microsoft.com/azure/templates/microsoft.managedidentity/2023-01-31/userassignedidentities?pivots=deployment-language-bicep | ||
internal const string DefaultVersion = "2023-01-31"; | ||
|
||
private static UserAssignedIdentityData Empty(string name) => ArmManagedServiceIdentitiesModelFactory.UserAssignedIdentityData(); | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="UserAssignedIdentity"/> class. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="parent">The parent.</param> | ||
/// <param name="name">The name.</param> | ||
/// <param name="version">The version.</param> | ||
/// <param name="location">The location.</param> | ||
public UserAssignedIdentity( | ||
IConstruct scope, | ||
ResourceGroup? parent = default, | ||
string name = "useridentity", | ||
string version = DefaultVersion, | ||
AzureLocation? location = default) | ||
: this(scope, parent, name, version, location, false, (name) => ArmManagedServiceIdentitiesModelFactory.UserAssignedIdentityData( | ||
name: name, | ||
location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS)) | ||
{ | ||
AssignProperty(data => data.Name, GetAzureName(scope, name)); | ||
} | ||
|
||
private UserAssignedIdentity( | ||
IConstruct scope, | ||
ResourceGroup? parent, | ||
string name, | ||
string version = DefaultVersion, | ||
AzureLocation? location = default, | ||
bool isExisting = false, | ||
Func<string, UserAssignedIdentityData>? creator = null) | ||
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="UserAssignedIdentity"/> class referencing an existing instance. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="name">The resource name.</param> | ||
/// <param name="parent">The resource group.</param> | ||
/// <returns>The UserAssignedIdentity instance.</returns> | ||
public static UserAssignedIdentity FromExisting(IConstruct scope, string name, ResourceGroup? parent = null) | ||
=> new UserAssignedIdentity(scope, parent: parent, name: name, isExisting: true); | ||
|
||
/// <inheritdoc/> | ||
protected override string GetAzureName(IConstruct scope, string resourceName) => GetGloballyUniqueName(resourceName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
sdk/provisioning/Azure.Provisioning/tests/Infrastructure/UserAssignedIdentities/main.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
targetScope = 'resourceGroup' | ||
|
||
@description('') | ||
param location string = resourceGroup().location | ||
|
||
|
||
resource userAssignedIdentity_aEVqJOqFO 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = { | ||
name: toLower(take(concat('useridentity', uniqueString(resourceGroup().id)), 24)) | ||
location: location | ||
properties: { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters