Giter Club home page Giter Club logo

findnextcidrrange's Introduction

Intro

Hello ๐Ÿ‘‹

This repo hosts all the code and the mechanisms to deploy a Linux Azure Function App into to your tenant, with this function app acting as a method of getting the next CIDR range in a VNet. Please check and the original documentation and blog post for information on the original app.

This repo:

  • Hosts the code for the function app
  • Give examples on how to build function apps needed resources using terraform
  • Give examples on how to deploy the function via Azure Function Core tools

The function itself is an HTTP function, which, will only run on request. Please note, the function app does require reader permissions over the virtual network.

Worth a note, that this won't work out the box for you, you are expected to use your own intuition or reach out for help, we will keep mentioning this as the documentation goes on ๐Ÿ˜„

There is just one function:

  • GetCidr

You can query the API by feeding it the parameters in the following format via an HTTP GET request:

https://{{pathToFunctionApp}}?subscriptionId={{subscriptionId}}&resourceGroupName={{resourceGroupName}}&virtualNetworkName={{virtualNetworkName}}&cidr={{cidr}}&addressSpace={{addressSpace}}

The 'addressSpace' parameter is optional. If not specified, the code will return the first valid subnet it finds. All other parameters are mandatory.

So, for example:

https://fnc-ldo-euw-dev-01.azurewebsites.net/api/getcidr?subscriptionId=09d383ee-8ed0-4374-ad9f-3344cabc323b&resourceGroupName=rg-ldo-euw-dev-build&virtualNetworkName=vnet-ldo-euw-dev-01&cidr=26&addressSpace=10.30.0.0/16

With example output:

{
  "name": "vnet-ldo-euw-dev-01",
  "id": "/subscriptions/09d383ee-8ed0-4374-ad9f-3344cabc323b/resourceGroups/rg-ldo-euw-dev-build/providers/Microsoft.Network/virtualNetworks/vnet-ldo-euw-dev-01",
  "type": "Microsoft.Network/virtualNetworks",
  "location": "westeurope",
  "addressSpace": "10.0.0.0/16",
  "proposedCIDR": "10.0.0.0/26"
}

Please note, my function app will be taken down by Terraform regularly, chances are if you try to test query it, it will fail

Building the environment

At the time of writing, this project only supports local deployments and is set up to find some expected items in the Azure tenant. Please check the fork from Libre DevOps to see a automated build using continious integration from GitHub Actions ๐Ÿš€

You can freely use the modules used to deploy these resources to suit your needs, but setting up the bits regarding security, segregation, etc. will be up to you.

Terraform Build

Disclaimer

This solutions is not turnkey and won't take into considerations the perimeter network and identity policies you will have in your tenant.

The automation is provided as-is for a quick setup and is not intended for production deployments. Please be sure to conduct due diligence when using this automation.

The terraform build will deploy:

  • 1x Resource Group
  • 1x Linux Function app on Consumption Service Plan with Dotnet 6.0 Application Stack (up to date with the v3 Azurerm provider changes in terraform)
  • 1x Storage Account, Hot access tier, for the storage of the function apps file system

How to use

To use the terraform build, you will need to already have a virtual network inside a resource group, as well as knowing the name of the resource group and virtual network respectively, as these will be fed to the script.

You will also need IAM permissions to read and assign permissions to this resource (e.g Owner or Reader + User Access Administrator, again, please consult with the security policies in your tenant regarding IAM and identity)

Finally, simply edit the run-terraform.sh (for example) inside the terraform folder in this repo

The script is setup with the variables placed at the top of the script, which will then be passed to terraform. The shell script requires the azure-cli, curl, and jq to work. It will check if they are installed and error if not :cross:

Again, you will need various IAM access to run this terraform under your account used with the az login prompt, but you are free to adapt it to run under a service principal or managed identity should you wish ๐Ÿ˜„

An example is something like so:

#!/usr/bin/env bash

set -eou pipefail

vnet_rg_name="rg-ldo-euw-dev-build" # The resource group name where your _existing_ VNet is.
vnet_name="rg-ldo-euw-dev-build"    # The name of your existing virtual network.

rg_name="cidr-app"             # The name of the resource group which terraform will create and add the function app to
resource_location="westeurope" # The name of the Azure region all terraform (function app etc) resources will be created with

Alt Text

Deploying the Function

The deployment of the function can be done many ways, and again, this is not a turn-key solution, but an easy way to deploy is to make sure you have the stack (e.g. Python, Dotnet) installed, and install the azure-functions-core-tools-4. More info on this can be found on the Microsoft Documentation

After installing the stack and the tools, and assuming you have permission to write to the function app on your Azure account, you can run a script like the deploy-function.sh script inside the src folder

#!/usr/bin/env bash

function_app_name="example"
code_directory="Find-NextCidrRange"
additional_stack_params="--csharp --force"

This script will check you have logged in and the tools installed and attempt a deploy, it will not check for your language stack.

It will then give an output like so, assuming you have the dotnet-sdk-6.0 and the azure-functions-core-tools-4 packages installed:

Alt Text

However, this is just 1 of may ways to deploy this ๐Ÿ˜‰, so feel free to adapt or contribute to improve!

findnextcidrrange's People

Contributors

craigthackerx avatar gamullen avatar ausfy avatar

Stargazers

 avatar Yonatan Sasson avatar  avatar David McNeill avatar kimnrdqvst avatar  avatar Radmir Aiupov avatar Jarvis Yang avatar  avatar  avatar Mathew Peterson avatar Phil Huang avatar  avatar Dimitri Zilber avatar Kevin Fatkin avatar  avatar  avatar Troy Knapp avatar

Watchers

 avatar

findnextcidrrange's Issues

Getting error 500 for very few vnets

First of all thank you so much for this solution, we were using this solution from last few months, recently I observed, this solution is not working in rare cases, im not able to figure out whats difference between working vnets and non working.

There are no access related issues, I tried created new subnet in new RG and tested, still I get this error.

image

image

image

Work with VNETs with multiple address spaces

Hello guys,

First of all, thank you for this solution!
One thing to add - the current solution, I guess, doesn't work with VNET's containing a few address spaces.

Will be very nice to add it.

Discussion - My terraform support contribution may not work as intended

Hey Gary ๐Ÿ‘‹

Thanks for merging the PR! To be honest, I didn't actually think it would be merged without some comments from yourself as some of it is abit messy as it does have some requirements from my own GitHub Org.

As it is right now - you may want to revert the merge back to your own last commit since you will get emailed when it fails fail it's CI checks and whatnot since it won't have my organisation secrets, as well as using some custom terraform modules which would be nicer to be generic terraform for a repo like yours.

Although that's up to you ๐Ÿ˜„

I'll (try) prepare a new PR which will be more suitable for merge into your repo, it's more the fact I wanted to contribute something back as I found your function app hugely useful for something I was looking for in a personal project of mine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.