Samouczek: tworzenie formularzy witryny Azure Portal dla specyfikacji szablonu
Możesz utworzyć formularz wyświetlany w witrynie Azure Portal, aby ułatwić użytkownikom wdrażanie specyfikacji szablonu. Formularz umożliwia użytkownikom wprowadzanie wartości przekazywanych jako parametry do specyfikacji szablonu.
Podczas tworzenia specyfikacji szablonu należy spakować formularz i szablon usługi Azure Resource Manager (szablon usługi ARM). Wdrożenie specyfikacji szablonu za pośrednictwem portalu powoduje automatyczne uruchomienie formularza.
Poniższy zrzut ekranu przedstawia formularz otwarty w witrynie Azure Portal.
Wymagania wstępne
Konto platformy Azure z aktywną subskrypcją. Utwórz konto bezpłatnie.
W przypadku programu Azure PowerShell użyj wersji 6.0.0 lub nowszej. W przypadku interfejsu wiersza polecenia platformy Azure użyj wersji 2.24.0 lub nowszej.
Tworzenie szablonu
Aby wyświetlić różne elementy portalu dostępne w formularzu, użyj szablonu usługi ARM z kilkoma parametrami. Poniższy szablon tworzy magazyn kluczy, konfiguruje uprawnienia do magazynu kluczy dla użytkownika i dodaje wpis tajny.
Skopiuj ten plik i zapisz go lokalnie. W tym samouczku założono, że nazwa została nazwana keyvault.json , ale możesz nadać jej dowolną nazwę.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"keyVaultName": {
"type": "string",
"metadata": {
"description": "Specifies the name of the key vault."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specifies the Azure location where the key vault should be created."
}
},
"enabledForDeployment": {
"type": "bool",
"defaultValue": false,
"allowedValues": [
true,
false
],
"metadata": {
"description": "Specifies whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault."
}
},
"enabledForDiskEncryption": {
"type": "bool",
"defaultValue": false,
"allowedValues": [
true,
false
],
"metadata": {
"description": "Specifies whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys."
}
},
"enabledForTemplateDeployment": {
"type": "bool",
"defaultValue": false,
"allowedValues": [
true,
false
],
"metadata": {
"description": "Specifies whether Azure Resource Manager is permitted to retrieve secrets from the key vault."
}
},
"tenantId": {
"type": "string",
"defaultValue": "[subscription().tenantId]",
"metadata": {
"description": "Specifies the Azure Active Directory tenant ID that should be used for authenticating requests to the key vault. Get it by using Get-AzSubscription cmdlet."
}
},
"objectId": {
"type": "string",
"metadata": {
"description": "Specifies the object ID of a user, service principal or security group in the Azure Active Directory tenant for the vault. The object ID must be unique for the list of access policies. Get it by using Get-AzADUser or Get-AzADServicePrincipal cmdlets."
}
},
"keysPermissions": {
"type": "array",
"defaultValue": [
"list"
],
"metadata": {
"description": "Specifies the permissions to keys in the vault. Valid values are: all, encrypt, decrypt, wrapKey, unwrapKey, sign, verify, get, list, create, update, import, delete, backup, restore, recover, and purge."
}
},
"secretsPermissions": {
"type": "array",
"defaultValue": [
"list"
],
"metadata": {
"description": "Specifies the permissions to secrets in the vault. Valid values are: all, get, list, set, delete, backup, restore, recover, and purge."
}
},
"skuName": {
"type": "string",
"defaultValue": "standard",
"allowedValues": [
"standard",
"premium"
],
"metadata": {
"description": "Specifies whether the key vault is a standard vault or a premium vault."
}
},
"secretName": {
"type": "string",
"metadata": {
"description": "Specifies the name of the secret that you want to create."
}
},
"secretValue": {
"type": "secureString",
"metadata": {
"description": "Specifies the value of the secret that you want to create."
}
}
},
"resources": [
{
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2022-07-01",
"name": "[parameters('keyVaultName')]",
"location": "[parameters('location')]",
"properties": {
"enabledForDeployment": "[parameters('enabledForDeployment')]",
"enabledForDiskEncryption": "[parameters('enabledForDiskEncryption')]",
"enabledForTemplateDeployment": "[parameters('enabledForTemplateDeployment')]",
"tenantId": "[parameters('tenantId')]",
"accessPolicies": [
{
"objectId": "[parameters('objectId')]",
"tenantId": "[parameters('tenantId')]",
"permissions": {
"keys": "[parameters('keysPermissions')]",
"secrets": "[parameters('secretsPermissions')]"
}
}
],
"sku": {
"name": "[parameters('skuName')]",
"family": "A"
},
"networkAcls": {
"defaultAction": "Allow",
"bypass": "AzureServices"
}
}
},
{
"type": "Microsoft.KeyVault/vaults/secrets",
"apiVersion": "2022-07-01",
"name": "[format('{0}/{1}', parameters('keyVaultName'), parameters('secretName'))]",
"dependsOn": [
"[resourceId('Microsoft.KeyVault/vaults', parameters('keyVaultName'))]"
],
"properties": {
"value": "[parameters('secretValue')]"
}
}
]
}
Tworzenie formularza domyślnego
Witryna Azure Portal udostępnia piaskownicę do tworzenia i wyświetlania podglądu formularzy. Ta piaskownica może renderować formularz z istniejącego szablonu usługi ARM. Użyj tego formularza domyślnego, aby rozpocząć tworzenie formularza dla specyfikacji szablonu. Aby uzyskać więcej informacji na temat struktury formularza, zobacz FormViewType.
Otwórz piaskownicę widoku formularza.
W polu Typ pakietu wybierz pozycję CustomTemplate. Przed określeniem szablonu wdrożenia upewnij się, że wybrano typ pakietu.
W obszarze Szablon wdrożenia (opcjonalnie) wybierz zapisany lokalnie szablon magazynu kluczy. Po wyświetleniu monitu, jeśli chcesz zastąpić bieżące zmiany, wybierz pozycję Tak. Automatycznie wygenerowany formularz jest wyświetlany w oknie kodu. Formularz można edytować w portalu. Aby dostosować formularz, zobacz dostosowywanie formularza. Jeśli przyjrzysz się bliżej formularzowi wygenerowanego automatycznie, domyślny tytuł to Widok formularza testowego. Istnieje tylko jeden krok nazywany zdefiniowanymi podstawami .
{ "$schema": "https://schema.management.azure.com/schemas/2021-09-09/uiFormDefinition.schema.json", "view": { "kind": "Form", "properties": { "title": "Test Form View", "steps": [ { "name": "basics", "label": "Basics", "elements": [ ... ] } ] }, "outputs": { ... } } }
Aby zobaczyć, że działa bez żadnych modyfikacji, wybierz pozycję Wersja zapoznawcza.
W piaskownicy zostanie wyświetlony formularz. Zawiera pola do wybierania subskrypcji, grupy zasobów i regionu. Zawiera również pola dla wszystkich parametrów z szablonu.
Większość pól to pola tekstowe, ale niektóre pola są specyficzne dla typu parametru. Gdy szablon zawiera dozwolone wartości dla parametru, automatycznie wygenerowany formularz używa elementu listy rozwijanej. Element listy rozwijanej jest wstępnie wypełniany dozwolonymi wartościami.
Między tytułem i szczegółami projektu nie ma kart, ponieważ formularz domyślny ma zdefiniowany tylko jeden krok. W sekcji Dostosowywanie formularza należy podzielić parametry na wiele kart.
Ostrzeżenie
Nie wybieraj pozycji Utwórz , ponieważ uruchamia rzeczywiste wdrożenie. W dalszej części tego samouczka masz szansę wdrożyć specyfikację szablonu.
Aby zakończyć pracę z wersji zapoznawczej, wybierz pozycję Anuluj.
Dostosowywanie formularza
Domyślny formularz to dobry punkt wyjścia do zrozumienia formularzy, ale zwykle chcesz go dostosować. Można go edytować w piaskownicy lub w programie Visual Studio Code. Opcja podglądu jest dostępna tylko w piaskownicy.
Nadaj formularzowi tytuł opisujący jego użycie.
{ "$schema": "https://schema.management.azure.com/schemas/2021-09-09/uiFormDefinition.schema.json#", "view": { "kind": "Form", "properties": { "title": "Key Vault and secret",
Domyślny formularz miał wszystkie pola szablonu połączone w jeden krok o nazwie Podstawy. Aby ułatwić użytkownikom zrozumienie podanych wartości, podziel formularz na kroki. Każdy krok zawiera pola związane z logiczną częścią rozwiązania do wdrożenia.
Znajdź krok z etykietą Podstawy. Zachowaj ten krok, ale dodaj kroki, które koncentrują się na konfigurowaniu magazynu kluczy, ustawianiu uprawnień użytkownika i określaniu wpisu tajnego. Dodaj przecinek po kroku podstaw.
{ "$schema": "https://schema.management.azure.com/schemas/2021-09-09/uiFormDefinition.schema.json#", "view": { "kind": "Form", "properties": { "title": "Key Vault and secret", "steps": [ { "name": "basics", "label": "Basics", "elements": [ ... ] }, { "name": "keyvault", "label": "Key Vault", "elements": [ ] }, { "name": "permissions", "label": "Permissions", "elements": [ ] }, { "name": "secret", "label": "Secret", "elements": [ ] } ] }, "outputs": { ... } } }
Ważne
Właściwości w formularzu są uwzględniane wielkości liter. Upewnij się, że użyto wielkości liter pokazanych w przykładach.
Wybierz Podgląd. Zobaczysz kroki, ale większość z nich nie ma żadnych elementów.
Przenieś elementy do odpowiednich kroków. Zacznij od elementów oznaczonych etykietą Nazwa wpisu tajnego i Wartość wpisu tajnego. Usuń te elementy z kroku Podstawy i dodaj je do kroku Wpis tajny .
{ "name": "secret", "label": "Secret", "elements": [ { "name": "secretName", "type": "Microsoft.Common.TextBox", "label": "Secret Name", "defaultValue": "", "toolTip": "Specifies the name of the secret that you want to create.", "constraints": { "required": true, "regex": "", "validationMessage": "" }, "visible": true }, { "name": "secretValue", "type": "Microsoft.Common.PasswordBox", "label": { "password": "Secret Value", "confirmPassword": "Confirm password" }, "toolTip": "Specifies the value of the secret that you want to create.", "constraints": { "required": true, "regex": "", "validationMessage": "" }, "options": { "hideConfirmation": true }, "visible": true } ] }
Podczas przenoszenia elementów napraw sekcję
outputs
. Obecnie sekcja danych wyjściowych odwołuje się do tych elementów tak, jakby nadal znajdowała się w kroku podstaw. Napraw składnię tak, aby odwoływali się do elementów wsecret
kroku."outputs": { "parameters": { ... "secretName": "[steps('secret').secretName]", "secretValue": "[steps('secret').secretValue]" }
Kontynuuj przenoszenie elementów do odpowiednich kroków. Zamiast przechodzić przez każdy z nich, przyjrzyj się zaktualizowanemu formularzowi.
{ "$schema": "https://schema.management.azure.com/schemas/2021-09-09/uiFormDefinition.schema.json#", "view": { "kind": "Form", "properties": { "title": "Key Vault and secret", "steps": [ { "name": "basics", "label": "Basics", "elements": [ { "name": "resourceScope", "type": "Microsoft.Common.ResourceScope", "location": { "resourceTypes": [ "microsoft.resources/resourcegroups" ] } } ] }, { "name": "keyvault", "label": "Key Vault", "elements": [ { "name": "keyVaultName", "type": "Microsoft.Common.TextBox", "label": "Key Vault Name", "defaultValue": "", "toolTip": "Specifies the name of the key vault.", "constraints": { "required": true, "regex": "", "validationMessage": "" }, "visible": true }, { "name": "skuName", "type": "Microsoft.Common.DropDown", "label": "Sku Name", "defaultValue": "Standard", "toolTip": "Specifies whether the key vault is a standard vault or a premium vault.", "constraints": { "required": false, "allowedValues": [ { "label": "Standard", "value": "Standard" }, { "label": "Premium", "value": "Premium" } ] }, "visible": true }, { "name": "location", "type": "Microsoft.Common.TextBox", "label": "Location", "defaultValue": "[[resourceGroup().location]", "toolTip": "Specifies the Azure location where the key vault should be created.", "constraints": { "required": false, "regex": "", "validationMessage": "" }, "visible": true }, { "name": "enabledForDeployment", "type": "Microsoft.Common.DropDown", "label": "Enabled For Deployment", "defaultValue": "false", "toolTip": "Specifies whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault.", "constraints": { "required": false, "allowedValues": [ { "label": "true", "value": true }, { "label": "false", "value": false } ] }, "visible": true }, { "name": "enabledForDiskEncryption", "type": "Microsoft.Common.DropDown", "label": "Enabled For Disk Encryption", "defaultValue": "false", "toolTip": "Specifies whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys.", "constraints": { "required": false, "allowedValues": [ { "label": "true", "value": true }, { "label": "false", "value": false } ] }, "visible": true }, { "name": "enabledForTemplateDeployment", "type": "Microsoft.Common.DropDown", "label": "Enabled For Template Deployment", "defaultValue": "false", "toolTip": "Specifies whether Azure Resource Manager is permitted to retrieve secrets from the key vault.", "constraints": { "required": false, "allowedValues": [ { "label": "true", "value": true }, { "label": "false", "value": false } ] }, "visible": true } ] }, { "name": "permissions", "label": "Permissions", "elements": [ { "name": "tenantId", "type": "Microsoft.Common.TextBox", "label": "Tenant Id", "defaultValue": "[[subscription().tenantId]", "toolTip": "Specifies the Azure Active Directory tenant ID that should be used for authenticating requests to the key vault. Get it by using Get-AzSubscription cmdlet.", "constraints": { "required": false, "regex": "", "validationMessage": "" }, "visible": true }, { "name": "objectId", "type": "Microsoft.Common.TextBox", "label": "Object Id", "defaultValue": "", "toolTip": "Specifies the object ID of a user, service principal or security group in the Azure Active Directory tenant for the vault. The object ID must be unique for the list of access policies. Get it by using Get-AzADUser or Get-AzADServicePrincipal cmdlets.", "constraints": { "required": true, "regex": "", "validationMessage": "" }, "visible": true }, { "name": "keysPermissions", "type": "Microsoft.Common.TextBox", "label": "Keys Permissions", "defaultValue": "[[\"list\"]", "toolTip": "Specifies the permissions to keys in the vault. Valid values are: all, encrypt, decrypt, wrapKey, unwrapKey, sign, verify, get, list, create, update, import, delete, backup, restore, recover, and purge.", "constraints": { "required": false, "regex": "", "validationMessage": "" }, "visible": true }, { "name": "secretsPermissions", "type": "Microsoft.Common.TextBox", "label": "Secrets Permissions", "defaultValue": "[[\"list\"]", "toolTip": "Specifies the permissions to secrets in the vault. Valid values are: all, get, list, set, delete, backup, restore, recover, and purge.", "constraints": { "required": false, "regex": "", "validationMessage": "" }, "visible": true } ] }, { "name": "secret", "label": "Secret", "elements": [ { "name": "secretName", "type": "Microsoft.Common.TextBox", "label": "Secret Name", "defaultValue": "", "toolTip": "Specifies the name of the secret that you want to create.", "constraints": { "required": true, "regex": "", "validationMessage": "" }, "visible": true }, { "name": "secretValue", "type": "Microsoft.Common.PasswordBox", "label": { "password": "Secret Value", "confirmPassword": "Confirm password" }, "toolTip": "Specifies the value of the secret that you want to create.", "constraints": { "required": true, "regex": "", "validationMessage": "" }, "options": { "hideConfirmation": true }, "visible": true } ] } ] }, "outputs": { "parameters": { "keyVaultName": "[steps('keyvault').keyVaultName]", "location": "[steps('keyvault').location]", "enabledForDeployment": "[steps('keyvault').enabledForDeployment]", "enabledForDiskEncryption": "[steps('keyvault').enabledForDiskEncryption]", "enabledForTemplateDeployment": "[steps('keyvault').enabledForTemplateDeployment]", "tenantId": "[steps('permissions').tenantId]", "objectId": "[steps('permissions').objectId]", "keysPermissions": "[steps('permissions').keysPermissions]", "secretsPermissions": "[steps('permissions').secretsPermissions]", "skuName": "[steps('keyvault').skuName]", "secretName": "[steps('secret').secretName]", "secretValue": "[steps('secret').secretValue]" }, "kind": "ResourceGroup", "location": "[steps('basics').resourceScope.location.name]", "resourceGroupId": "[steps('basics').resourceScope.resourceGroup.id]" } } }
Zapisz ten plik lokalnie przy użyciu nazwy keyvaultform.json.
Tworzenie specyfikacji szablonu
Podczas tworzenia specyfikacji szablonu podaj oba pliki.
W przypadku programu PowerShell użyj polecenia New-AzTemplateSpec i podaj formularz w parametrze -UIFormDefinitionFile
.
New-AzTemplateSpec `
-name keyvaultspec `
-version 1 `
-ResourceGroupName templateSpecRG `
-location westus2 `
-templatefile keyvault.json `
-UIFormDefinitionFile keyvaultform.json
W przypadku interfejsu wiersza polecenia platformy Azure użyj polecenia az ts create i podaj formularz w parametrze --ui-form-definition
.
az ts create \
--name keyvaultspec \
--version 1 \
--resource-group templatespecRG \
--location westus2 \
--template-file keyvault.json \
--ui-form-definition keyvaultform.json
Wdrażanie za pośrednictwem portalu
Aby przetestować formularz, przejdź do portalu i przejdź do specyfikacji szablonu. Wybierz pozycję Wdróż.
Zostanie wyświetlony utworzony formularz. Zapoznaj się z krokami i podaj wartości pól.
W kroku Podstawy zostanie wyświetlone pole Region. To pole dotyczy lokalizacji grupy zasobów. W kroku Key Vault zostanie wyświetlone pole Lokalizacja. To pole dotyczy lokalizacji magazynu kluczy.
W kroku Uprawnienia podaj identyfikator użytkownika dla identyfikatora obiektu. Użyj wartości domyślnej (["list"]
) dla uprawnień klucza i wpisu tajnego. Ulepszysz tę opcję w następnej sekcji.
Po zakończeniu podawania wartości wybierz pozycję Utwórz , aby wdrożyć specyfikację szablonu.
Ulepszanie formularza
W poprzedniej sekcji dodano kroki i przeniesiono elementy, ale nie zmieniono żadnych zachowań domyślnych. W tej sekcji wprowadzisz zmiany, które usprawniają środowisko użytkowników specyfikacji szablonu.
Wcześniej dwa pola uprawnień były polami tekstowymi. Teraz użyjesz listy rozwijanej. Ustaw typ na Microsoft.Common.DropDown
.
Aktualizacja keysPermissions
:
{
"name": "keysPermissions",
"type": "Microsoft.Common.DropDown",
I secretsPermissions
:
{
"name": "secretsPermissions",
"type": "Microsoft.Common.DropDown",
Te pola muszą przekazać tablicę do szablonu. Zwykła lista rozwijana nie działa, ponieważ pozwala wybrać tylko jedną wartość. Aby wybrać więcej niż jedną wartość i przekazać je jako tablicę, dodaj multiselect
pole i ustaw je na true
.
{
"name": "keysPermissions",
"type": "Microsoft.Common.DropDown",
"label": "Keys Permissions",
"multiselect": true,
{
"name": "secretsPermissions",
"type": "Microsoft.Common.DropDown",
"label": "Secrets Permissions",
"multiselect": true,
Na koniec określ dozwolone wartości listy rozwijanej i wartość domyślną.
{
"name": "keysPermissions",
"type": "Microsoft.Common.DropDown",
"label": "Keys Permissions",
"multiselect": true,
"defaultValue":{
"value": "list"
},
"toolTip": "Specifies the permissions to keys in the vault. Valid values are: all, encrypt, decrypt, wrapKey, unwrapKey, sign, verify, get, list, create, update, import, delete, backup, restore, recover, and purge.",
"constraints": {
"required": false,
"allowedValues":[
{
"label": "all",
"value": "all"
},
{
"label": "encrypt",
"value": "encrypt"
},
{
"label": "decrypt",
"value": "decrypt"
},
{
"label": "list",
"value": "list"
},
{
"label": "delete",
"value": "delete"
},
{
"label": "backup",
"value": "backup"
},
{
"label": "restore",
"value": "restore"
},
{
"label": "recover",
"value": "recover"
},
{
"label": "purge",
"value": "purge"
},
{
"label": "wrapKey",
"value": "wrapKey"
},
{
"label": "unwrapKey",
"value": "unwrapKey"
},
{
"label": "sign",
"value": "sign"
},
{
"label": "verify",
"value": "verify"
},
{
"label": "get",
"value": "get"
},
{
"label": "create",
"value": "create"
},
{
"label": "update",
"value": "update"
},
{
"label": "import",
"value": "import"
}
]
},
"visible": true
},
{
"name": "secretsPermissions",
"type": "Microsoft.Common.DropDown",
"label": "Secrets Permissions",
"multiselect": true,
"defaultValue":{
"value": "list"
},
"toolTip": "Specifies the permissions to secrets in the vault. Valid values are: all, get, list, set, delete, backup, restore, recover, and purge.",
"constraints": {
"required": false,
"allowedValues":[
{
"label": "all",
"value": "all"
},
{
"label": "get",
"value": "get"
},
{
"label": "list",
"value": "list"
},
{
"label": "set",
"value": "set"
},
{
"label": "delete",
"value": "delete"
},
{
"label": "backup",
"value": "backup"
},
{
"label": "restore",
"value": "restore"
},
{
"label": "recover",
"value": "recover"
},
{
"label": "purge",
"value": "purge"
}
]
},
"visible": true
}
Utwórz nową wersję specyfikacji szablonu.
Za pomocą programu PowerShell:
New-AzTemplateSpec `
-name keyvaultspec `
-version 2 `
-ResourceGroupName templateSpecRG `
-location westus2 `
-templatefile keyvault.json `
-UIFormDefinitionFile keyvaultform.json
Lub interfejs wiersza polecenia platformy Azure:
az ts create \
--name keyvaultspec \
--version 2 \
--resource-group templatespecRG \
--location westus2 \
--template-file keyvault.json \
--ui-form-definition keyvaultform.json
Ponownie wdróż specyfikację szablonu przy użyciu ulepszonego formularza portalu.
Zwróć uwagę, że pola uprawnień są teraz listami rozwijanymi, które zezwalają na wiele wartości.
Następne kroki
Aby dowiedzieć się więcej o wdrażaniu specyfikacji szablonu jako szablonu połączonego, zobacz Samouczek: wdrażanie specyfikacji szablonu jako szablonu połączonego.