Skip to content

Commit

Permalink
Added new input variable 'name' (#35)
Browse files Browse the repository at this point in the history
* Added new input variable 'name'

* Added new input variable 'pip_name'

* fixed README example

* Update main.tf
  • Loading branch information
juan-acevedo-ntt authored May 26, 2021
1 parent 55eb6af commit f136ab2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ resource "azurerm_resource_group" "example" {
module "mylb" {
source = "Azure/loadbalancer/azurerm"
resource_group_name = azurerm_resource_group.example.name
prefix = "terraform-test"
name = "lb-terraform-test"
pip_name = "pip-terraform-test"
remote_port = {
ssh = ["Tcp", "22"]
Expand Down
9 changes: 7 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ data "azurerm_resource_group" "azlb" {
name = var.resource_group_name
}

locals {
lb_name = var.name != "" ? var.name : format("%s-lb", var.prefix)
pip_name = var.pip_name != "" ? var.pip_name : format("%s-publicIP", var.prefix)
}

resource "azurerm_public_ip" "azlb" {
count = var.type == "public" ? 1 : 0
name = "${var.prefix}-publicIP"
name = local.pip_name
resource_group_name = data.azurerm_resource_group.azlb.name
location = coalesce(var.location, data.azurerm_resource_group.azlb.location)
allocation_method = var.allocation_method
Expand All @@ -14,7 +19,7 @@ resource "azurerm_public_ip" "azlb" {
}

resource "azurerm_lb" "azlb" {
name = "${var.prefix}-lb"
name = local.lb_name
resource_group_name = data.azurerm_resource_group.azlb.name
location = coalesce(var.location, data.azurerm_resource_group.azlb.location)
sku = var.lb_sku
Expand Down
2 changes: 2 additions & 0 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module "mylb" {
frontend_private_ip_address = "10.0.1.6"
lb_sku = "Standard"
pip_sku = "Standard"
name = "lb-aztest"
pip_name = "pip-aztest"

remote_port = {
ssh = ["Tcp", "22"]
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,15 @@ variable "pip_sku" {
type = string
default = "Basic"
}

variable "name" {
description = "(Optional) Name of the load balancer. If it is set, the 'prefix' variable will be ignored."
type = string
default = ""
}

variable "pip_name" {
description = "(Optional) Name of public ip. If it is set, the 'prefix' variable will be ignored."
type = string
default = ""
}

0 comments on commit f136ab2

Please sign in to comment.