Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add private option for loadbalancer #3

Merged
merged 9 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 61 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,83 @@
# terraform-azurerm-loadbalancer #
[![Build Status](https://travis-ci.org/Azure/terraform-azurerm-loadbalancer.svg?branch=master)](https://travis-ci.org/Azure/terraform-azurerm-loadbalancer)

Create a basic load balancer in Azure
===========
A terraform module to provide load balancers in Azure with the following
characteristics:

This Terraform module deploys a load balancer in Azure.
- 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:

```hcl
variable "location" {
default = "eastus"
}

module "mylb" {
source = "Azure/loadbalancer/azurerm"
location = "North Central US"
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:

```hcl
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"
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"
}
}
```
Expand Down
8 changes: 6 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resource "azurerm_resource_group" "azlb" {
}

resource "azurerm_public_ip" "azlb" {
count = "${var.type == "public" ? 1 : 0}"
name = "${var.prefix}-publicIP"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.azlb.name}"
Expand All @@ -18,8 +19,11 @@ resource "azurerm_lb" "azlb" {
location = "${var.location}"

frontend_ip_configuration {
name = "${var.frontend_name}"
public_ip_address_id = "${azurerm_public_ip.azlb.id}"
name = "${var.frontend_name}"
public_ip_address_id = "${var.type == "public" ? join("",azurerm_public_ip.azlb.*.id) : ""}"
subnet_id = "${var.frontend_subnet_id}"
private_ip_address = "${var.frontend_private_ip_address}"
private_ip_address_allocation = "${var.frontend_private_ip_address_allocation}"
}
}

Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ output "azurerm_lb_nat_rule_ids" {

output "azurerm_public_ip_id" {
description = "the id for the azurerm_lb_public_ip resource"
value = "${azurerm_public_ip.azlb.id}"
value = "${azurerm_public_ip.azlb.*.id}"
}

output "azurerm_public_ip_address" {
description = "the ip address for the azurerm_lb_public_ip resource"
value = "${azurerm_public_ip.azlb.ip_address}"
value = "${azurerm_public_ip.azlb.*.ip_address}"
}

output "azurerm_lb_backend_address_pool_id" {
Expand Down
21 changes: 21 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,24 @@ variable "tags" {
source = "terraform"
}
}

variable "type" {
type = "string"
description = "(Optional) Defined if the loadbalancer is private or public"
default = "public"
}

variable "frontend_subnet_id" {
description = "(Optional) Frontend subnet id to use when in private mode"
default = ""
}

variable "frontend_private_ip_address" {
description = "(Optional) Private ip address to assign to frontend. Use it with type = private"
default = ""
}

variable "frontend_private_ip_address_allocation" {
description = "(Optional) Frontend ip allocation type (Static or Dynamic)"
default = "Dynamic"
}