Skip to content

Commit fa232bb

Browse files
committed
added arm, bicep, and terraform
1 parent acb4f89 commit fa232bb

File tree

1 file changed

+270
-0
lines changed

1 file changed

+270
-0
lines changed

articles/virtual-network/quickstart-create-virtual-network.md

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ If you don't have a service subscription, [create a free trial account](https://
5353

5454
- An Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
5555

56+
[!INCLUDE [About Azure Resource Manager](~/reusable-content/ce-skilling/azure/includes/resource-manager-quickstart-introduction.md)]
57+
5658
### [Bicep](#tab/bicep)
5759

5860
- An Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
@@ -410,6 +412,274 @@ The VMs take a few minutes to create. After Azure creates each VM, the Azure CLI
410412

411413
### [ARM](#tab/arm)
412414

415+
## Review the template
416+
417+
The template that you use in this quickstart is from [Azure Quickstart Templates](https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.network/vnet-two-subnets/azuredeploy.json).
418+
419+
:::code language="json" source="~/quickstart-templates/quickstarts/microsoft.network/vnet-two-subnets/azuredeploy.json" :::
420+
421+
The template defines the following Azure resources:
422+
423+
- [Microsoft.Network/virtualNetworks](/azure/templates/microsoft.network/virtualnetworks): Create a virtual network.
424+
- [Microsoft.Network/virtualNetworks/subnets](/azure/templates/microsoft.network/virtualnetworks/subnets): Create a subnet.
425+
426+
## Deploy the template
427+
428+
Deploy the Resource Manager template to Azure:
429+
430+
1. Select **Deploy to Azure** to sign in to Azure and open the template. The template creates a virtual network with two subnets.
431+
432+
:::image type="content" source="~/reusable-content/ce-skilling/azure/media/template-deployments/deploy-to-azure-button.svg" alt-text="Button to deploy the Resource Manager template to Azure." border="false" link="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2Fquickstarts%2Fmicrosoft.network%2Fvnet-two-subnets%2Fazuredeploy.json":::
433+
434+
1. In the portal, on the **Create a Virtual Network with two Subnets** page, enter or select the following values:
435+
- **Resource group**: Select **Create new**, enter **CreateVNetQS-rg** for the resource group name, and then select **OK**.
436+
- **Virtual Network Name**: Enter a name for the new virtual network.
437+
1. Select **Review + create**, and then select **Create**.
438+
1. When deployment finishes, select the **Go to resource** button to review the resources that you deployed.
439+
440+
## Review deployed resources
441+
442+
Explore the resources that you created with the virtual network by browsing through the settings panes for **VNet1**:
443+
444+
- The **Overview** tab shows the defined address space of **10.0.0.0/16**.
445+
446+
- The **Subnets** tab shows the deployed subnets of **Subnet1** and **Subnet2** with the appropriate values from the template.
447+
448+
To learn about the JSON syntax and properties for a virtual network in a template, see [Microsoft.Network/virtualNetworks](/azure/templates/microsoft.network/virtualnetworks).
449+
450+
### [Bicep](#tab/bicep)
451+
452+
## Create the virtual network and VMs
453+
454+
This quickstart uses the [Two VMs in VNET](https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.compute/2-vms-internal-load-balancer/main.bicep) Bicep template from [Azure Resource Manager Quickstart Templates](https://github.com/Azure/azure-quickstart-templates) to create the virtual network, resource subnet, and VMs. The Bicep template defines the following Azure resources:
455+
456+
- [Microsoft.Network virtualNetworks](/azure/templates/microsoft.network/virtualnetworks): Creates an Azure virtual network.
457+
- [Microsoft.Network virtualNetworks/subnets](/azure/templates/microsoft.network/virtualnetworks/subnets): Creates a subnet for the VMs.
458+
- [Microsoft.Compute virtualMachines](/azure/templates/microsoft.compute/virtualmachines): Creates the VMs.
459+
- [Microsoft.Compute availabilitySets](/azure/templates/microsoft.compute/availabilitysets): Creates an availability set.
460+
- [Microsoft.Network networkInterfaces](/azure/templates/microsoft.network/networkinterfaces): Creates network interfaces.
461+
- [Microsoft.Network loadBalancers](/azure/templates/microsoft.network/loadbalancers): Creates an internal load balancer.
462+
- [Microsoft.Storage storageAccounts](/azure/templates/microsoft.storage/storageaccounts): Creates a storage account.
463+
464+
Review the Bicep file:
465+
466+
:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.compute/2-vms-internal-load-balancer/main.bicep" :::
467+
468+
### Deploy the Bicep template
469+
470+
1. Save the Bicep file to your local computer as *main.bicep*.
471+
1. Deploy the Bicep file by using either the Azure CLI or Azure PowerShell:
472+
473+
### CLI
474+
475+
```azurecli
476+
az group create \
477+
--name TestRG \
478+
--location eastus
479+
480+
az deployment group create \
481+
--resource-group TestRG \
482+
--template-file main.bicep
483+
```
484+
485+
### PowerShell
486+
487+
```azurepowershell
488+
$rgParams = @{
489+
Name = 'TestRG'
490+
Location = 'eastus'
491+
}
492+
New-AzResourceGroup @rgParams
493+
494+
$deploymentParams = @{
495+
ResourceGroupName = 'TestRG'
496+
TemplateFile = 'main.bicep'
497+
}
498+
New-AzResourceGroupDeployment @deploymentParams
499+
```
500+
501+
When the deployment finishes, a message indicates that the deployment succeeded.
502+
503+
## Deploy Azure Bastion
504+
505+
Bastion uses your browser to connect to VMs in your virtual network over Secure Shell (SSH) or Remote Desktop Protocol (RDP) by using their private IP addresses. The VMs don't need public IP addresses, client software, or special configuration. For more information about Bastion, see [What is Azure Bastion?](~/articles/bastion/bastion-overview.md).
506+
507+
> [!NOTE]
508+
> [!INCLUDE [Pricing](~/reusable-content/ce-skilling/azure/includes/bastion-pricing.md)]
509+
510+
Use the [Azure Bastion as a Service](https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.network/azure-bastion/main.bicep) Bicep template from [Azure Resource Manager Quickstart Templates](https://github.com/Azure/azure-quickstart-templates) to deploy and configure Bastion in your virtual network. This Bicep template defines the following Azure resources:
511+
512+
- [Microsoft.Network virtualNetworks/subnets](/azure/templates/microsoft.network/virtualnetworks/subnets): Creates an **AzureBastionSubnet** subnet.
513+
- [Microsoft.Network bastionHosts](/azure/templates/microsoft.network/bastionhosts): Creates the Bastion host.
514+
- [Microsoft.Network publicIPAddresses](/azure/templates/microsoft.network/publicipaddresses): Creates a public IP address for the Bastion host.
515+
- [Microsoft Network networkSecurityGroups](/azure/templates/microsoft.network/networksecuritygroups): Controls the settings for network security groups.
516+
517+
Review the Bicep file:
518+
519+
:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.network/azure-bastion/main.bicep" :::
520+
521+
### Deploy the Bicep template
522+
523+
1. Save the Bicep file to your local computer as *bastion.bicep*.
524+
1. Use a text or code editor to make the following changes in the file:
525+
526+
- Line 2: Change `param vnetName string` from `'vnet01'` to `'VNet'`.
527+
- Line 5: Change `param vnetIpPrefix string` from `'10.1.0.0/16'` to `'10.0.0.0/16'`.
528+
- Line 12: Change `param vnetNewOrExisting string` from `'new'` to `'existing'`.
529+
- Line 15: Change `param bastionSubnetIpPrefix string` from `'10.1.1.0/26'` to `'10.0.1.0/26'`.
530+
- Line 18: Change `param bastionHostName string` to `param bastionHostName = 'VNet-bastion'`.
531+
532+
The first 18 lines of your Bicep file should now look like this example:
533+
534+
```bicep
535+
@description('Name of new or existing vnet to which Azure Bastion should be deployed')
536+
param vnetName string = 'VNet'
537+
538+
@description('IP prefix for available addresses in vnet address space')
539+
param vnetIpPrefix string = '10.0.0.0/16'
540+
541+
@description('Specify whether to provision new vnet or deploy to existing vnet')
542+
@allowed([
543+
'new'
544+
'existing'
545+
])
546+
param vnetNewOrExisting string = 'existing'
547+
548+
@description('Bastion subnet IP prefix MUST be within vnet IP prefix address space')
549+
param bastionSubnetIpPrefix string = '10.0.1.0/26'
550+
551+
@description('Name of Azure Bastion resource')
552+
param bastionHostName = 'VNet-bastion'
553+
554+
```
555+
556+
1. Save the *bastion.bicep* file.
557+
558+
1. Deploy the Bicep file by using either the Azure CLI or Azure PowerShell:
559+
560+
#### CLI
561+
562+
```azurecli
563+
az deployment group create \
564+
--resource-group TestRG \
565+
--template-file bastion.bicep
566+
```
567+
568+
### PowerShell
569+
570+
```azurepowershell
571+
$deploymentParams = @{
572+
ResourceGroupName = 'TestRG'
573+
TemplateFile = 'bastion.bicep'
574+
}
575+
New-AzResourceGroupDeployment @deploymentParams
576+
```
577+
578+
When the deployment finishes, a message indicates that the deployment succeeded.
579+
580+
> [!NOTE]
581+
> VMs in a virtual network with a Bastion host don't need public IP addresses. Bastion provides the public IP, and the VMs use private IPs to communicate within the network. You can remove the public IPs from any VMs in Bastion-hosted virtual networks. For more information, see [Dissociate a public IP address from an Azure VM](ip-services/remove-public-ip-address-vm.md).
582+
583+
## Review deployed resources
584+
585+
Use the Azure CLI, Azure PowerShell, or the Azure portal to review the deployed resources:
586+
587+
### CLI
588+
589+
```azurecli
590+
az resource list --resource-group TestRG
591+
```
592+
593+
### PowerShell
594+
595+
```azurepowershell
596+
Get-AzResource -ResourceGroupName TestRG
597+
```
598+
599+
### Portal
600+
601+
1. In the [Azure portal](https://portal.azure.com), search for and select **resource groups**. On the **Resource groups** page, select **TestRG** from the list of resource groups.
602+
603+
1. On the **Overview** page for **TestRG**, review all the resources that you created, including the virtual network, the two VMs, and the Bastion host.
604+
605+
1. Select the **VNet** virtual network. On the **Overview** page for **VNet**, note the defined address space of **10.0.0.0/16**.
606+
607+
1. On the left menu, select **Subnets**. On the **Subnets** page, note the deployed subnets of **backendSubnet** and **AzureBastionSubnet** with the assigned values from the Bicep files.
608+
609+
### [Terraform](#tab/terraform)
610+
611+
The script uses the Azure Resource Manager (`azurerm`) provider to interact with Azure resources. It uses the Random (`random`) provider to generate random pet names for the resources.
612+
613+
The script creates the following resources:
614+
615+
- A resource group: A container that holds related resources for an Azure solution.
616+
617+
- A virtual network: A fundamental building block for your private network in Azure.
618+
619+
- Two subnets: Segments of a virtual network's IP address range where you can place groups of isolated resources.
620+
621+
:::image type="content" source="./media/quick-create-bicep/virtual-network-bicep-resources.png" alt-text="Diagram of resources created in the virtual network quickstart." lightbox="./media/quick-create-bicep/virtual-network-bicep-resources.png":::
622+
623+
[!INCLUDE [About Terraform](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
624+
625+
## Implement the Terraform code
626+
627+
> [!NOTE]
628+
> The sample code for this article is in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-virtual-network-create-two-subnets). You can view the log file that contains the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/tree/master/quickstart/101-virtual-network-create-two-subnets/TestRecord.md).
629+
>
630+
> For more articles and sample code that show how to use Terraform to manage Azure resources, see the [documentation page for Terraform on Azure](/azure/terraform).
631+
632+
1. Create a directory in which to test and run the sample Terraform code, and make it the current directory.
633+
634+
1. Create a file named *main.tf* and insert the following code:
635+
636+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-virtual-network-create-two-subnets/main.tf":::
637+
638+
1. Create a file named *outputs.tf* and insert the following code:
639+
640+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-virtual-network-create-two-subnets/outputs.tf":::
641+
642+
1. Create a file named *providers.tf* and insert the following code:
643+
644+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-virtual-network-create-two-subnets/providers.tf":::
645+
646+
1. Create a file named *variables.tf* and insert the following code:
647+
648+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-virtual-network-create-two-subnets/variables.tf":::
649+
650+
## Initialize Terraform
651+
652+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
653+
654+
## Create a Terraform execution plan
655+
656+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
657+
658+
## Apply a Terraform execution plan
659+
660+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
661+
662+
## Verify the results
663+
664+
1. Get the Azure resource group name:
665+
666+
```console
667+
resource_group_name=$(terraform output -raw resource_group_name)
668+
```
669+
670+
1. Get the virtual network name:
671+
672+
```console
673+
virtual_network_name=$(terraform output -raw virtual_network_name)
674+
```
675+
676+
1. Use [`az network vnet show`](/cli/azure/network/vnet#az-network-vnet-show) to display the details of your newly created virtual network:
677+
678+
```azurecli
679+
az network vnet show \
680+
--resource-group $resource_group_name \
681+
--name $virtual_network_name
682+
```
413683

414684
---
415685

0 commit comments

Comments
 (0)