Azure Network Bastion Host

This page shows how to write Terraform and Azure Resource Manager for Network Bastion Host and write them securely.

azurerm_bastion_host (Terraform)

The Bastion Host in Network can be configured in Terraform with the resource name azurerm_bastion_host. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

bastions.tf#L12
resource "azurerm_bastion_host" "bastion-spoke-1" {
  name                = "bastion-spoke-1"
  location            = var.location-spoke-1
  resource_group_name = azurerm_resource_group.vwan-microhack-spoke-rg.name

  ip_configuration {
bastions.tf#L12
resource "azurerm_bastion_host" "bastion-spoke-1" {
  name                = "bastion-spoke-1"
  location            = var.location-hub-1
  resource_group_name = azurerm_resource_group.vwan-microhack-spoke-rg.name

  ip_configuration {
bastion.tf#L18
resource "azurerm_bastion_host" "vm" {
  count                = var.create_bastion ? 1 : 0
  name                = "GitHubRunners"
  location            = azurerm_resource_group.vm.location
  resource_group_name = azurerm_resource_group.vm.name

bastion.tf#L16
resource "azurerm_bastion_host" "bastion_host" {
    name = "bastion-host"
    resource_group_name = azurerm_resource_group.bastion_rg.name
    location = var.location

    ip_configuration {
bastion_host.tf#L1
resource "azurerm_bastion_host" "bastion" {
  name                    = var.bastion_host
  location                = var.location
  resource_group_name     = azurerm_resource_group.rg.name

  ip_configuration {
bastion.tf#L1
resource "azurerm_bastion_host" "bastion" {
  name                = "kubebastion"
  location            = azurerm_resource_group.kubetest.location
  resource_group_name = azurerm_resource_group.kubetest.name

  ip_configuration {
bastion.tf#L17
resource "azurerm_bastion_host" "bastion" {
  name                = "bastion"
  location            = var.location
  resource_group_name = data.azurerm_resource_group.management.name

  depends_on = [azurerm_virtual_network.management]
bastion.tf#L19
resource "azurerm_bastion_host" "bastion_host" {
  name                = "bastion-host"
  resource_group_name = azurerm_resource_group.bastion_rg.name
  location            = var.location

  ip_configuration {
bastion.tf#L28
resource "azurerm_bastion_host" "bastion" {
  name                = "hellobastion"
  location            = azurerm_resource_group.bastion.location
  resource_group_name = azurerm_resource_group.bastion.name

  ip_configuration {
bastion.tf#L16
resource "azurerm_bastion_host" "bastion" {
  name                = var.bastion_host_name
  location            = var.location
  resource_group_name = var.resourcegroup_name

  ip_configuration {

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a Bastion Host.

Tips: Best Practices for The Other Azure Network Resources

In addition to the azurerm_network_security_group, Azure Network has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_network_security_group

Ensure to disable RDP port from the Internet

It is better to disable the RDP port from the Internet. RDP access should not be accepted from the Internet (*, 0.0.0.0, /0, internet, any), and consider using the Azure Bastion Service.

risk-label

azurerm_network_security_rule

Ensure to set a more restrictive CIDR range for ingress from the internet

It is better to set a more restrictive CIDR range not to use very broad subnets. If possible, segments should be divided into smaller subnets.

risk-label

azurerm_network_watcher_flow_log

Ensure to enable Retention policy for flow logs and set it to enough duration

It is better to enable a retention policy for flow logs. Flow logs show us all network activity in the cloud environment and support us when we face critical incidents.

Review your Azure Network settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Network/bastionHosts (Azure Resource Manager)

The bastionHosts in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/bastionHosts. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

azure.comnetwork-bastionHost.json#L313
              "type": "Microsoft.Network/bastionHosts"
            }
          ]
        }
      },
      "List_all_Bastion_Hosts_for_a_given_resource_group": {
BastionHostUpdateTags.json#L19
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "tags": {
          "tag1": "value1",
          "tag2": "value2"
BastionHostPut.json#L30
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "properties": {
          "provisioningState": "Succeeded",
          "dnsName": "bst-9d89d361-100e-4c01-b92d-466548c476dc.bastion.azure.com",
BastionHostPut.json#L30
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "properties": {
          "provisioningState": "Succeeded",
          "dnsName": "bst-9d89d361-100e-4c01-b92d-466548c476dc.bastion.azure.com",
BastionHostPut.json#L30
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "properties": {
          "provisioningState": "Succeeded",
          "dnsName": "bst-9d89d361-100e-4c01-b92d-466548c476dc.bastion.azure.com",
BastionHostPut.json#L30
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "properties": {
          "provisioningState": "Succeeded",
          "dnsName": "bst-9d89d361-100e-4c01-b92d-466548c476dc.bastion.azure.com",
BastionHostPut.json#L30
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "properties": {
          "provisioningState": "Succeeded",
          "dnsName": "bst-9d89d361-100e-4c01-b92d-466548c476dc.bastion.azure.com",
BastionHostPut.json#L30
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "properties": {
          "provisioningState": "Succeeded",
          "dnsName": "bst-9d89d361-100e-4c01-b92d-466548c476dc.bastion.azure.com",
BastionHostPut.json#L30
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "properties": {
          "provisioningState": "Succeeded",
          "dnsName": "bst-9d89d361-100e-4c01-b92d-466548c476dc.bastion.azure.com",
BastionHostPut.json#L30
        "type": "Microsoft.Network/bastionHosts",
        "etag": "w/\\00000000-0000-0000-0000-000000000000\\",
        "location": "West US",
        "properties": {
          "provisioningState": "Succeeded",
          "dnsName": "bst-9d89d361-100e-4c01-b92d-466548c476dc.bastion.azure.com",

Parameters

  • name required - string

    The name of the Bastion Host.

  • type required - string
  • apiVersion required - string
  • location required - string

    Resource location.

  • tags optional - string

    Resource tags.

  • properties required
      • ipConfigurations optional array
          • properties optional
              • subnet required
                  • id required - string

                    Resource ID.

              • publicIPAddress required
                  • id required - string

                    Resource ID.

              • privateIPAllocationMethod optional - string

                Private IP allocation method.

          • name optional - string

            Name of the resource that is unique within a resource group. This name can be used to access the resource.

      • dnsName optional - string

        FQDN for the endpoint on which bastion host is accessible.

Frequently asked questions

What is Azure Network Bastion Host?

Azure Network Bastion Host is a resource for Network of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Network Bastion Host?

For Terraform, the mddazure/azure-vwan-microhack, zipphreak/azure-vwan-microhack2.0 and techcentr/org-github-runners source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the rwth-acis/apis-guru-statistics, debhol/azuredocs and debhol/azuredocs source code examples are useful. See the Azure Resource Manager Example section for further details.