/terraform-azurerm-loadbalancer

Terraform Azure RM Module for Load Balancer

Primary LanguageHCLMIT LicenseMIT

terraform-azurerm-loadbalancer

Build Status

A terraform module to provide load balancers in Azure with the following characteristics:

  • Ability to specify public or private loadbalancer using: var.type. Default is public.
  • Specify subnet to use for the loadbalancer: frontend_subnet_id
  • For private loadbalancer, specify the private ip address using frontend_private_ip_address
  • Specify the type of the private ip address with frontend_private_ip_address_allocation, Dynamic or Static , default is Dynamic

Usage

Public loadbalancer example:

variable "location" {
  default = "eastus"
}

module "mylb" {
  source              = "Azure/loadbalancer/azurerm"
  resource_group_name = "${var.resource_group_name}"
  location            = "${var.location}"
  prefix              = "terraform-test"

  "remote_port" {
    ssh = ["Tcp", "22"]
  }

  "lb_port" {
    http = ["80", "Tcp", "80"]
  }
}

module "network" {
  source              = "Azure/network/azurerm"
  location            = "${var.location}"
  resource_group_name = "${var.resource_group_name}"
}

Private loadbalancer example:

module "mylb" {
  source                                 = "Azure/loadbalancer/azurerm"
  location                               = "westus"
  type                                   = "private"
  frontend_subnet_id                     = "${module.network.vnet_subnets[0]}"
  frontend_private_ip_address_allocation = "Static"
  frontend_private_ip_address            = "10.0.1.6"

  "remote_port" {
    ssh = ["Tcp", "22"]
  }

  "lb_port" {
    http  = ["80", "Tcp", "80"]
    https = ["443", "Tcp", "443"]
  }

  "tags" {
    cost-center = "12345"
    source      = "terraform"
  }
}

module "network" {
  source              = "Azure/network/azurerm"
  resource_group_name = "myapp"
  location            = "westus"
  address_space       = "10.0.0.0/16"
  subnet_prefixes     = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  subnet_names        = ["subnet1", "subnet2", "subnet3"]

  tags = {
    environment = "dev"
    costcenter  = "it"
  }
}

Test

Configurations

We provide 2 ways to build, run, and test module on local dev box:

Native(Mac/Linux)

Prerequisites

Environment setup

We provide simple script to quickly set up module development environment:

$ curl -sSL https://raw.githubusercontent.com/Azure/terramodtest/master/tool/env_setup.sh | sudo bash

Run test

Then simply run it in local shell:

$ bundle install
$ rake build

Docker

We provide Dockerfile to build and run module development environment locally:

Prerequisites

Build the image

docker build -t azure-loadbalancer .

Run test

$ docker run -it azure-loadbalancer /bin/sh
$ rake build

Authors

Originally created by David Tesar

License

MIT