Giter Club home page Giter Club logo

ci-security-steps's Introduction

terraform-azurerm-load-balancer

Description

This Terraform module creates a standardised load balancer and availability set.

Refer to the variables.tf for a full list of the possible options and default values.

Note that if the load_balancer rules list is not specified then it will default to a NAT rule passing 443 (HTTPS) through to the 443 port on the backend.

Example 1

resource "azurerm_resource_group" "example" {
  name     = "lb-example"
  location = "West Europe"
  tags = {
    owner = "Richard Cheney",
    dept  = "Azure Citadel"
  }
}

resource "azurerm_virtual_network" "example" {
  name                = "example-vnet"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  tags                = azurerm_resource_group.example.tags
  address_space       = ["10.0.0.0/24"]
}

resource "azurerm_subnet" "example" {
  name                 = "example-subnet"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.0.0/26"]
}

module "example-lb" {
  source = "https://github.com/terraform-azurerm-modules/terraform-azurerm-load-balancer"

  name                = "lb-example"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  tags                = azurerm_resource_group.example.tags
  subnet_id           = azurerm_subnet.example.id

  load_balancer_rules = [{
      protocol      = "Tcp",
      frontend_port = 80,
      backend_port  = 8080
    },
    {
      protocol      = "Tcp",
      frontend_port = 443,
      backend_port  = 8443
    }
  ]
}

output "example_load_balancer_ip_address" {
  value = module.example-lb.load_balancer_private_ip_address
}

output "example_availability_set_id" {
  value = module.example-lb.availability_set_id
}

output "example_load_balancer_backend_address_pool_id" {
  value = module.example-lb.load_balancer_backend_address_pool_id
}

Example 2

The real benefit of the module is that you can define a set of defaults and leverage that if you are creating many availability sets and load balancers.

See the example-hub and example-spoke repositories for fuller examples, including how the outputs are used by the terraform-azurerm-linux-vm and terraform-azurerm-linux-vmss modules.

<snip>

locals {
  defaults = {
    resource_group_name = azurerm_resource_group.example.name
    location            = azurerm_resource_group.example.location
    tags                = azurerm_resource_group.example.tags
    subnet_id           = azurerm_subnet.example.id
  }
}

module "example-lb1" {
  source   = "https://github.com/terraform-azurerm-modules/terraform-azurerm-local-balancer"
  defaults = locals.defaults
  name     = "lb-example1"
}

module "example-lb2" {
  source   = "https://github.com/terraform-azurerm-modules/terraform-azurerm-local-balancer"
  defaults = locals.defaults
  name     = "lb-example2"

  load_balancer_rules = [
    { protocol      = "Tcp", frontend_port = 80,  backend_port  = 8080 },
    { protocol      = "Tcp", frontend_port = 443, backend_port  = 8443 }
  ]
}

module "example-lb3" {
  source    = "https://github.com/terraform-azurerm-modules/terraform-azurerm-local-balancer"
  defaults  = locals.defaults
  name      = "lb-example3"
  subnet_id = azurerm_subnet.alternative.id
}

ci-security-steps's People

Contributors

zacharyrgonzales avatar

Watchers

 avatar

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.