question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translation of subnets seems to be not working

See original GitHub issue

I try to add a subnet to virtual network configuration. But I realise that generated ARM template doesn’t contain the subnet. My configuration looks as follows:

let bastionSubnet = subnet {
  name "AzureBastionSubnet"
  prefix "10.1.0.0/27"
}

let virtualNetwork env = vnet {
  name (sprintf "vnet-%s" env)
  add_address_spaces [ "10.0.0.0/16" ]
  add_subnets [ bastionSubnet ]
}

let machine env = vm {
  name (sprintf "machine-%s" env)
  vm_size Vm.Standard_B1s
  operating_system Vm.UbuntuServer_1804LTS
  os_disk 128 Vm.StandardSSD_LRS
  username "heheheheheheh"
  subnet_prefix "10.0.0.0/24"
  depends_on (virtualNetwork env)
}

While generated ARM template looks like this:

    {
      "apiVersion": "2018-11-01",
      "location": "centralus",
      "name": "vnet-test",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "10.0.0.0/16"
          ]
        },
        "subnets": [
          {
            "name": "machine-test-subnet",
            "properties": {
              "addressPrefix": "10.0.0.0/24",
              "delegations": []
            }
          }
        ]
      },
      "tags": {},
      "type": "Microsoft.Network/virtualNetworks"
    }

As you may see the only subnet added to the VirtualNetwork is a machine subnet. When I remove creation of a machine from the script, the template looks as follows:

{
      "apiVersion": "2018-11-01",
      "location": "centralus",
      "name": "vnet-test",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "10.0.0.0/16"
          ]
        },
        "subnets": [
          {
            "name": "AzureBastionSubnet",
            "properties": {
              "addressPrefix": "10.1.0.0/27",
              "delegations": []
            }
          }
        ]
      },
      "tags": {},
      "type": "Microsoft.Network/virtualNetworks"
    }

I think that the problem is here where the Subnets would be overriden(?)

I would appreciate any hint regarding that I’m doing something wrong or where I could take a look to fix the issue and provide a PR : )

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ninjarobotcommented, Sep 29, 2020

You’ll need to use link_to_vnet and subnet_name to specify the vnet and subnet to use, otherwise the implicitly generated vnet will overwrite things.

One other item is that the AzureBastionSubnet is not contained within the vnet address space you defined. To make sure the pieces fit, I suggest using the builder to carve out subnets within the address space:

let privateNet = vnet {
    name "vnet-test"
    build_address_spaces [
        address_space {
            space "10.0.0.0/16"
            subnets [
                build_subnet "vms" 24
                build_subnet "AzureBastionSubnet" 27
            ]
       }
    ]
}

let machine = vm {
  name "machine-1234"
  vm_size Vm.Standard_B1s
  operating_system Vm.UbuntuServer_1804LTS
  os_disk 128 Vm.StandardSSD_LRS
  username "heheheheheheh"
  subnet_name "vms"
  link_to_vnet privateNet.Name
}

let template = arm {
  add_resource privateNet
  add_resource machine
}

1reaction
MNiecommented, Sep 30, 2020

@ninjarobot , @isaacabraham thanks to that everything seems to be working as expected. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenVPN site-to-site with subnet translation?
Hello everyone, I'm attempting to configure a site-to-site OpenVPN link with subnet translation. This seems straightforward, except I must have a ...
Read more >
Using Site-to-site VPN Translation - Cisco Meraki
To configure VPN subnet translation: Navigate to Security & SD-WAN > Configure > Site-to-site VPN. Set VPN subnet translation to Enabled. This ...
Read more >
Subnets on single switch problem
Hi i recently completed a CCENT and am now moving onto to CCNA. I came across a network recently shown in the attachment...
Read more >
Help with Subnet Routing not working : r/Tailscale
RPi is 192.168.2.3 on our work network, but I can not connect to anything on that subnet from home that is not running...
Read more >
Solved: Not getting subnet translation to work
Solved: We are trying to replace a Cisco router with a FortiGate running 5.4 but are unable to get subnet translation to work...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found