Author : MD TAREQ HASSAN | Updated : 2021/10/29
Get Tenant Id from Environment Variable
- To create KeyVault, TenantId is needed
- TenantId is set as environment variable (local machine & Azure DevOps pipeline agent VM)
// // EnvironmentVariableTarget: // Use .Process // .Machine is only for Windows // .User might not work // var tenantId = Environment.GetEnvironmentVariable("AZURE_TENANT_ID", EnvironmentVariableTarget.Process);
Create KeyVault
First, Create Resource Group
//
// Get TenantId
//
var tenantId = Environment.GetEnvironmentVariable("AZURE_TENANT_ID", EnvironmentVariableTarget.Process);
//
// Create KeyVault
//
var vault = new AzureNative.KeyVault.Vault("DemoKeyVault", new AzureNative.KeyVault.VaultArgs
{
ResourceGroupName = resourceGroup.Name,
VaultName = "DemoKv",
Location = "japaneast",
Properties = new AzureNative.KeyVault.Inputs.VaultPropertiesArgs
{
Sku = new AzureNative.KeyVault.Inputs.SkuArgs
{
Name = AzureNative.KeyVault.SkuName.Standard,
Family = AzureNative.KeyVault.SkuFamily.A
},
EnableRbacAuthorization = true,
EnableSoftDelete = true,
SoftDeleteRetentionInDays = 7,
CreateMode = AzureNative.KeyVault.CreateMode.Default,
EnabledForDeployment = true,
EnabledForDiskEncryption = true,
EnabledForTemplateDeployment = true,
TenantId = tenantId
}
});