Skip to content

KeyVaultSecret

SYNOPSIS

A Key Vault secret passed to a DeployIfNotExists template parameter, e.g. a password.

SYNTAX

KeyVaultSecret [-VaultId] <Object> [-SecretName] <Object> [[-SecretVersion] <Object>] [<CommonParameters>]

DESCRIPTION

Azure Resource Manager reads the secret from the vault when it runs the deployment, so the secret is never in the policy. Use it only as a value in Deployment -Parameters. -VaultId is the vault's resource ID, and -SecretName the secret's name; each is a string, Param or Arm. -SecretVersion selects a version of the secret; without it, the deployment uses the current one.

Whoever deploys needs access to the secret: the vault must allow template deployment, and the policy assignment's managed identity needs permission to read it.

USED IN

Deployment -Parameters, as a value

EXAMPLES

Example 1

Deployment -TemplateFile ./templates/domain-join.json -Parameters @{
    vmName         = (Arm "[field('name')]")
    domainPassword = (KeyVaultSecret -VaultId (Param KeyVaultResourceId) -SecretName (Param DomainPasswordSecret))
}

Example 2

KeyVaultSecret -VaultId '/subscriptions/.../providers/Microsoft.KeyVault/vaults/contoso' -SecretName 'domain-password' -SecretVersion (Param SecretVersion)

PARAMETERS

-VaultId

The vault's resource ID: a string, Param or Arm.

Type: Object
Required: true
Position: 1
Accept pipeline input: false

-SecretName

The secret's name: a string, Param or Arm.

Type: Object
Required: true
Position: 2
Accept pipeline input: false

-SecretVersion

The secret's version: a string, Param or Arm. Without it, the current version.

Type: Object
Required: false
Position: 3
Accept pipeline input: false