Snabbstart: Skapa och distribuera en distributionsstack med Bicep från mallspecifikationer
Den här snabbstarten beskriver hur du skapar en distributionsstack från en mallspecifikation.
Förutsättningar
- Ett Azure-konto med en aktiv prenumeration. Skapa ett konto utan kostnad.
- Azure PowerShell version 12.0.0 eller senare eller Azure CLI version 2.61.0 eller senare.
- Visual Studio Code med Bicep-tillägget.
Skapa en Bicep-fil
Skapa en Bicep-fil för att skapa ett lagringskonto och ett virtuellt nätverk.
param resourceGroupLocation string = resourceGroup().location
param storageAccountName string = 'store${uniqueString(resourceGroup().id)}'
param vnetName string = 'vnet${uniqueString(resourceGroup().id)}'
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-04-01' = {
name: storageAccountName
location: resourceGroupLocation
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2023-11-01' = {
name: vnetName
location: resourceGroupLocation
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: 'Subnet-1'
properties: {
addressPrefix: '10.0.0.0/24'
}
}
{
name: 'Subnet-2'
properties: {
addressPrefix: '10.0.1.0/24'
}
}
]
}
}
Spara Bicep-filen som main.bicep.
Skapa mallspecifikation
Skapa en mallspecifikation med följande kommando.
az group create \
--name 'templateSpecRG' \
--location 'centralus'
az ts create \
--name 'stackSpec' \
--version '1.0' \
--resource-group 'templateSpecRG' \
--location 'centralus' \
--template-file 'main.bicep'
Formatet för mallspecifikations-ID:t är /subscriptions/<subscription-id>/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/stackSpec/versions/1.0
.
Skapa en distributionsstack
Skapa en distributionsstack från mallspecifikationen.
az group create \
--name 'demoRg' \
--location 'centralus'
id=$(az ts show --name 'stackSpec' --resource-group 'templateSpecRG' --version '1.0' --query 'id')
az stack group create \
--name demoStack \
--resource-group 'demoRg' \
--template-spec $id \
--action-on-unmanage 'detachAll' \
--deny-settings-mode 'none'
Mer information om action-on-unmanage
och finns i Distributionsstackardeny-setting-mode
.
Verifiera distributionen
Så här listar du de distribuerade distributionsstackarna på prenumerationsnivå:
az stack group show \
--resource-group 'demoRg' \
--name 'demoStack'
Utdata visar två hanterade resurser – ett lagringskonto och ett virtuellt nätverk:
{
"actionOnUnmanage": {
"managementGroups": "detach",
"resourceGroups": "detach",
"resources": "detach"
},
"debugSetting": null,
"deletedResources": [],
"denySettings": {
"applyToChildScopes": false,
"excludedActions": null,
"excludedPrincipals": null,
"mode": "none"
},
"deploymentId": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/demoRg/providers/Microsoft.Resources/deployments/demoStack-240517162aqmf",
"deploymentScope": null,
"description": null,
"detachedResources": [],
"duration": "PT30.5642429S",
"error": null,
"failedResources": [],
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/demoRg/providers/Microsoft.Resources/deploymentStacks/demoStack",
"location": null,
"name": "demoStack",
"outputs": null,
"parameters": {},
"parametersLink": null,
"provisioningState": "succeeded",
"resourceGroup": "demoRg",
"resources": [
{
"denyStatus": "none",
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/demoRg/providers/Microsoft.Network/virtualNetworks/vnetthmimleef5fwk",
"resourceGroup": "demoRg",
"status": "managed"
},
{
"denyStatus": "none",
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/demoRg/providers/Microsoft.Storage/storageAccounts/storethmimleef5fwk",
"resourceGroup": "demoRg",
"status": "managed"
}
],
"systemData": {
"createdAt": "2024-05-17T16:07:51.172012+00:00",
"createdBy": "johndoe@contoso.com",
"createdByType": "User",
"lastModifiedAt": "2024-05-17T16:07:51.172012+00:00",
"lastModifiedBy": "johndoe@contoso.com",
"lastModifiedByType": "User"
},
"tags": {},
"template": null,
"templateLink": {
"contentVersion": null,
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/stackSpec/versions/1.0",
"queryString": null,
"relativePath": null,
"resourceGroup": "templateSpecRG",
"uri": null
},
"type": "Microsoft.Resources/deploymentStacks"
}
Du kan också verifiera distributionen genom att lista de hanterade resurserna i distributionsstacken:
az stack group show \
--name 'demoStack' \
--resource-group 'demoRg' \
--output 'json'
Utdatan liknar följande:
{
"actionOnUnmanage": {
"managementGroups": "detach",
"resourceGroups": "detach",
"resources": "detach"
},
"debugSetting": null,
"deletedResources": [],
"denySettings": {
"applyToChildScopes": false,
"excludedActions": null,
"excludedPrincipals": null,
"mode": "none"
},
"deploymentId": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/demoRg/providers/Microsoft.Resources/deployments/demoStack-240517162aqmf",
"deploymentScope": null,
"description": null,
"detachedResources": [],
"duration": "PT30.5642429S",
"error": null,
"failedResources": [],
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/demoRg/providers/Microsoft.Resources/deploymentStacks/demoStack",
"location": null,
"name": "demoStack",
"outputs": null,
"parameters": {},
"parametersLink": null,
"provisioningState": "succeeded",
"resourceGroup": "demoRg",
"resources": [
{
"denyStatus": "none",
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/demoRg/providers/Microsoft.Network/virtualNetworks/vnetthmimleef5fwk",
"resourceGroup": "demoRg",
"status": "managed"
},
{
"denyStatus": "none",
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/demoRg/providers/Microsoft.Storage/storageAccounts/storethmimleef5fwk",
"resourceGroup": "demoRg",
"status": "managed"
}
],
"systemData": {
"createdAt": "2024-05-17T16:07:51.172012+00:00",
"createdBy": "johndoe@contoso.com",
"createdByType": "User",
"lastModifiedAt": "2024-05-17T16:07:51.172012+00:00",
"lastModifiedBy": "johndoe@contoso.com",
"lastModifiedByType": "User"
},
"tags": {},
"template": null,
"templateLink": {
"contentVersion": null,
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/stackSpec/versions/1.0",
"queryString": null,
"relativePath": null,
"resourceGroup": "templateSpecRG",
"uri": null
},
"type": "Microsoft.Resources/deploymentStacks"
}
Ta bort distributionsstacken
Så här tar du bort distributionsstacken och de hanterade resurserna:
az stack group delete \
--name 'demoStack' \
--resource-group 'demoRg' \
--action-on-unmanage 'deleteAll'
Ta bort distributionsstacken, men koppla från de hanterade resurserna. Till exempel:
az stack group delete \
--name 'demoStack' \
--resource-group 'demoRg' \
--action-on-unmanage 'detachAll'
Mer information finns i Ta bort distributionsstackar.
Rensa resurser
Kommandot ta bort tar bara bort hanterade resurser och hanterade resursgrupper. Du måste fortfarande ta bort resursgruppen.
az group delete \
--name 'demoRg'
Så här tar du bort mallspecifikationen och resursgruppen:
az group delete \
--name 'templateSpecRG'