Coder Social home page Coder Social logo

davidobrien1985 / pulumi-azure-vm-manage-lifecycle Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 24 KB

Pulumi code to deploy an Azure Function that applies auto shutdown policies to Azure VMs

License: MIT License

Makefile 1.94% JavaScript 98.06%
azure serverless infrastructure-as-code infrastructure-automation infrastructure-management pulumi azure-functions nodejs

pulumi-azure-vm-manage-lifecycle's Introduction

Manage the lifecycle of Azure VMs (shut down and start)

This repo holds code that can be used to stand up an Azure Function leveraging the open source infrastructure as real code tool Pulumi. The Azure Function runs every 5 minutes and checks if there are any Azure VMs that do not have an Azure VM Auto Shutdown schedule attached to them. These schedules are specifically important in test and development environments where cloud engineers / cloud administrators are allowed to create VMs manually and might forget to turn them off when they do not need them any more.

  • Azure Function
    • /functions
      • Check Readme to understand how to use the function and what it does
  • Infracode using Pulumi
    • /infracode

Requirements

  • make
  • zip
  • az cli (azure cli)
  • npm
  • pulumi

Build and Deploy

Follow these steps to deploy this Azure Function:

  • Build the Azure Function
    • CURRENTDIR=${PWD}; cd functions; make; cd ${CURRENTDIR}
    • this will build the NodeJS Azure Function and zip the whole Function app into the /functions/build directory
  • Pulumi infra deployment
    • create a new pulumi stack
      • pulumi stack init pulumi-azure-vm-shutdown
    • update the values in ./infracode/Pulumi.<stackName>.yaml
      • you can do it manually or use
        • pulumi config set notificationGroup <emailAddress>
        • pulumi config set subscriptionId <subscriptionId>
  • Restore npm modules
    • CURRENTDIR=${PWD}; cd infracode; npm install; cd ${CURRENTDIR}
  • Check what pulumi will do
    • CURRENTDIR=${PWD}; cd infracode; pulumi preview; cd ${CURRENTDIR}
  • If all looks well, deploy the infrastructure
    • CURRENTDIR=${PWD}; cd infracode; pulumi update; cd ${CURRENTDIR}

Next up

Future iterations of this Azure Function will see the following capabilities:

  • Turn VMs on according to a specified schedule or VM tags
  • Turn VMs off according to VM tags (without leveraging the VM shutdown schedule feature)

Cost

I recommend doing your own cost calculation for this Azure Function. In my calculations on a consumption plan I don't get the Function to ever cost me anything, due to the free tier grant for Azure Functions, but YMMV.

pulumi-azure-vm-manage-lifecycle's People

Contributors

davidobrien1985 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

jygastaud

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.