Delen via


Quickstart: Een implementatiestack maken en implementeren met Bicep op basis van sjabloonspecificaties

In deze quickstart wordt beschreven hoe u een implementatiestack maakt op basis van een sjabloonspecificatie.

Vereisten

Een Bicep-bestand maken

Maak een Bicep-bestand om een opslagaccount en een virtueel netwerk te maken.

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'
        }
      }
    ]
  }
}

Sla het Bicep-bestand op als main.bicep.

Sjabloonspecificatie maken

Maak een sjabloonspecificatie met de volgende opdracht.

az group create \
  --name 'templateSpecRG' \
  --location 'centralus'

az ts create \
  --name 'stackSpec' \
  --version '1.0' \
  --resource-group 'templateSpecRG' \
  --location 'centralus' \
  --template-file 'main.bicep'

De indeling van de sjabloonspecificatie-id is /subscriptions/<subscription-id>/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/stackSpec/versions/1.0.

Een implementatiestack maken

Maak een implementatiestack op basis van de sjabloonspecificatie.

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'

Zie Implementatiestacks voor meer informatie over action-on-unmanage endeny-setting-mode.

De implementatie controleren

De geïmplementeerde implementatiestacks weergeven op abonnementsniveau:

az stack group show \
  --resource-group 'demoRg' \
  --name 'demoStack'

De uitvoer toont twee beheerde resources: één opslagaccount en één virtueel netwerk:

{
  "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"
}

U kunt de implementatie ook controleren door de beheerde resources in de implementatiestack weer te verlenen:

az stack group show \
  --name 'demoStack' \
  --resource-group 'demoRg' \
  --output 'json'

De uitvoer is vergelijkbaar met:

{
  "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"
}

De implementatiestack verwijderen

De implementatiestack en de beheerde resources verwijderen:

az stack group delete \
  --name 'demoStack' \
  --resource-group 'demoRg' \
  --action-on-unmanage 'deleteAll' 

Als u de implementatiestack wilt verwijderen, maar de beheerde resources loskoppelt. Voorbeeld:

az stack group delete \
  --name 'demoStack' \
  --resource-group 'demoRg' \
  --action-on-unmanage 'detachAll' 

Zie Implementatiestacks verwijderen voor meer informatie.

Resources opschonen

Met de opdracht Verwijderen worden alleen de beheerde resources en beheerde resourcegroepen verwijderd. U moet de resourcegroep nog steeds verwijderen.

az group delete \
  --name 'demoRg'

De sjabloonspecificatie en de resourcegroep verwijderen:

az group delete \
  --name 'templateSpecRG'

Volgende stappen