Share via


Quickstart: Een Azure SQL Managed Instance maken met Bicep

Deze quickstart is gericht op het implementeren van een Bicep-bestand om een Azure SQL Managed Instance en vNet te maken. Azure SQL Managed Instance is een intelligente, volledig beheerde, schaalbare clouddatabase met bijna 100% functiepariteit met de database-engine van SQL Server.

Bicep is een domeinspecifieke taal (DSL) die declaratieve syntaxis gebruikt om Azure-resources te implementeren. Het biedt beknopte syntaxis, betrouwbare typeveiligheid en ondersteuning voor het hergebruik van code. Bicep biedt de beste ontwerpervaring voor uw infrastructuur-als-code-oplossingen in Azure.

Vereisten

Als u nog geen abonnement op Azure hebt, maak dan een gratis account.

Het Bicep-bestand controleren

Het Bicep-bestand dat in deze quickstart wordt gebruikt, is afkomstig uit Azure-snelstartsjablonen.

@description('Enter managed instance name.')
param managedInstanceName string

@description('Enter user name.')
param administratorLogin string

@description('Enter password.')
@secure()
param administratorLoginPassword string

@description('Enter location. If you leave this field blank resource group location would be used.')
param location string = resourceGroup().location

@description('Enter virtual network name. If you leave this field blank name will be created by the template.')
param virtualNetworkName string = 'SQLMI-VNET'

@description('Enter virtual network address prefix.')
param addressPrefix string = '10.0.0.0/16'

@description('Enter subnet name.')
param subnetName string = 'ManagedInstance'

@description('Enter subnet address prefix.')
param subnetPrefix string = '10.0.0.0/24'

@description('Enter sku name.')
@allowed([
  'GP_Gen5'
  'BC_Gen5'
])
param skuName string = 'GP_Gen5'

@description('Enter number of vCores.')
@allowed([
  4
  8
  16
  24
  32
  40
  64
  80
])
param vCores int = 16

@description('Enter storage size.')
@minValue(32)
@maxValue(8192)
param storageSizeInGB int = 256

@description('Enter license type.')
@allowed([
  'BasePrice'
  'LicenseIncluded'
])
param licenseType string = 'LicenseIncluded'

var networkSecurityGroupName = 'SQLMI-${managedInstanceName}-NSG'
var routeTableName = 'SQLMI-${managedInstanceName}-Route-Table'

resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2021-08-01' = {
  name: networkSecurityGroupName
  location: location
  properties: {
    securityRules: [
      {
        name: 'allow_tds_inbound'
        properties: {
          description: 'Allow access to data'
          protocol: 'Tcp'
          sourcePortRange: '*'
          destinationPortRange: '1433'
          sourceAddressPrefix: 'VirtualNetwork'
          destinationAddressPrefix: '*'
          access: 'Allow'
          priority: 1000
          direction: 'Inbound'
        }
      }
      {
        name: 'allow_redirect_inbound'
        properties: {
          description: 'Allow inbound redirect traffic to Managed Instance inside the virtual network'
          protocol: 'Tcp'
          sourcePortRange: '*'
          destinationPortRange: '11000-11999'
          sourceAddressPrefix: 'VirtualNetwork'
          destinationAddressPrefix: '*'
          access: 'Allow'
          priority: 1100
          direction: 'Inbound'
        }
      }
      {
        name: 'deny_all_inbound'
        properties: {
          description: 'Deny all other inbound traffic'
          protocol: '*'
          sourcePortRange: '*'
          destinationPortRange: '*'
          sourceAddressPrefix: '*'
          destinationAddressPrefix: '*'
          access: 'Deny'
          priority: 4096
          direction: 'Inbound'
        }
      }
      {
        name: 'deny_all_outbound'
        properties: {
          description: 'Deny all other outbound traffic'
          protocol: '*'
          sourcePortRange: '*'
          destinationPortRange: '*'
          sourceAddressPrefix: '*'
          destinationAddressPrefix: '*'
          access: 'Deny'
          priority: 4096
          direction: 'Outbound'
        }
      }
    ]
  }
}

resource routeTable 'Microsoft.Network/routeTables@2021-08-01' = {
  name: routeTableName
  location: location
  properties: {
    disableBgpRoutePropagation: false
  }
}

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-08-01' = {
  name: virtualNetworkName
  location: location
  properties: {
    addressSpace: {
      addressPrefixes: [
        addressPrefix
      ]
    }
    subnets: [
      {
        name: subnetName
        properties: {
          addressPrefix: subnetPrefix
          routeTable: {
            id: routeTable.id
          }
          networkSecurityGroup: {
            id: networkSecurityGroup.id
          }
          delegations: [
            {
              name: 'managedInstanceDelegation'
              properties: {
                serviceName: 'Microsoft.Sql/managedInstances'
              }
            }
          ]
        }
      }
    ]
  }
}

resource managedInstance 'Microsoft.Sql/managedInstances@2021-11-01-preview' = {
  name: managedInstanceName
  location: location
  sku: {
    name: skuName
  }
  identity: {
    type: 'SystemAssigned'
  }
  dependsOn: [
    virtualNetwork
  ]
  properties: {
    administratorLogin: administratorLogin
    administratorLoginPassword: administratorLoginPassword
    subnetId: resourceId('Microsoft.Network/virtualNetworks/subnets', virtualNetworkName, subnetName)
    storageSizeInGB: storageSizeInGB
    vCores: vCores
    licenseType: licenseType
  }
}

Deze resources worden gedefinieerd in het Bicep-bestand:

Het Bicep-bestand implementeren

  1. Sla het Bicep-bestand op als main.bicep op uw lokale computer.

  2. Implementeer het Bicep-bestand met behulp van Azure CLI of Azure PowerShell.

    az group create --name exampleRG --location eastus
    az deployment group create --resource-group exampleRG --template-file main.bicep --parameters managedInstanceName=<instance-name> administratorLogin=<admin-login>
    

Notitie

Vervang exemplaarnaam> door< de naam van het beheerde exemplaar. Vervang admin-login> door< de gebruikersnaam van de beheerder. U wordt gevraagd administratorLoginPassword in te voeren.

Wanneer de implementatie is voltooid, ziet u een bericht dat aangeeft dat de implementatie is voltooid.

Geïmplementeerde resources bekijken

Gebruik de Azure Portal, Azure CLI of Azure PowerShell om de geïmplementeerde resources in de resourcegroep weer te geven.

az resource list --resource-group exampleRG

Resources opschonen

Wanneer u de resourcegroep en de bijbehorende resources niet meer nodig hebt, gebruikt u de Azure Portal, Azure CLI of Azure PowerShell.

az group delete --name exampleRG

Volgende stappen