Skip to content

Commit

Permalink
terraform upgrade to v0.12 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
yupwei68 committed Jul 21, 2020
1 parent ffb9ef9 commit b40b8fc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- docker

env:
- TERRAFORM_VERSION=0.11.7 IMAGE_NAME=azure-loadbalancer-module
- TERRAFORM_VERSION=0.12.20 IMAGE_NAME=azure-loadbalancer-module

jobs:
include:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pull the base image with given version.
ARG BUILD_TERRAFORM_VERSION="0.11.7"
FROM microsoft/terraform-test:${BUILD_TERRAFORM_VERSION}
ARG BUILD_TERRAFORM_VERSION="0.12.20"
FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION}

ARG MODULE_NAME="terraform-azurerm-loadbalancer"

Expand Down
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
ruby "~> 2.3.0"

source 'https://rubygems.org/'

group :test do
git 'https://github.com/Azure/terramodtest.git' do
gem 'terramodtest', :tag => 'v0.2.0'
gem 'terramodtest', :tag => '0.5.0'
end
end
85 changes: 42 additions & 43 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,74 +1,73 @@
# Azure load balancer module
resource "azurerm_resource_group" "azlb" {
name = "${var.resource_group_name}"
location = "${var.location}"
tags = "${var.tags}"
name = var.resource_group_name
location = var.location
tags = var.tags
}

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}"
public_ip_address_allocation = "${var.public_ip_address_allocation}"
tags = "${var.tags}"
count = var.type == "public" ? 1 : 0
name = "${var.prefix}-publicIP"
resource_group_name = azurerm_resource_group.azlb.name
location = azurerm_resource_group.azlb.location
allocation_method = var.allocation_method
tags = var.tags
}

resource "azurerm_lb" "azlb" {
name = "${var.prefix}-lb"
resource_group_name = "${azurerm_resource_group.azlb.name}"
location = "${var.location}"
tags = "${var.tags}"
resource_group_name = azurerm_resource_group.azlb.name
location = azurerm_resource_group.azlb.location
tags = var.tags

frontend_ip_configuration {
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}"
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
}
}

resource "azurerm_lb_backend_address_pool" "azlb" {
resource_group_name = "${azurerm_resource_group.azlb.name}"
loadbalancer_id = "${azurerm_lb.azlb.id}"
name = "BackEndAddressPool"
resource_group_name = azurerm_resource_group.azlb.name
loadbalancer_id = azurerm_lb.azlb.id
}

resource "azurerm_lb_nat_rule" "azlb" {
count = "${length(var.remote_port)}"
resource_group_name = "${azurerm_resource_group.azlb.name}"
loadbalancer_id = "${azurerm_lb.azlb.id}"
count = length(var.remote_port)
name = "VM-${count.index}"
resource_group_name = azurerm_resource_group.azlb.name
loadbalancer_id = azurerm_lb.azlb.id
protocol = "tcp"
frontend_port = "5000${count.index + 1}"
backend_port = "${element(var.remote_port["${element(keys(var.remote_port), count.index)}"], 1)}"
frontend_ip_configuration_name = "${var.frontend_name}"
backend_port = element(var.remote_port[element(keys(var.remote_port), count.index)], 1)
frontend_ip_configuration_name = var.frontend_name
}

resource "azurerm_lb_probe" "azlb" {
count = "${length(var.lb_port)}"
resource_group_name = "${azurerm_resource_group.azlb.name}"
loadbalancer_id = "${azurerm_lb.azlb.id}"
name = "${element(keys(var.lb_port), count.index)}"
protocol = "${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 1)}"
port = "${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 2)}"
interval_in_seconds = "${var.lb_probe_interval}"
number_of_probes = "${var.lb_probe_unhealthy_threshold}"
count = length(var.lb_port)
name = element(keys(var.lb_port), count.index)
resource_group_name = azurerm_resource_group.azlb.name
loadbalancer_id = azurerm_lb.azlb.id
protocol = element(var.lb_port[element(keys(var.lb_port), count.index)], 1)
port = element(var.lb_port[element(keys(var.lb_port), count.index)], 2)
interval_in_seconds = var.lb_probe_interval
number_of_probes = var.lb_probe_unhealthy_threshold
}

resource "azurerm_lb_rule" "azlb" {
count = "${length(var.lb_port)}"
resource_group_name = "${azurerm_resource_group.azlb.name}"
loadbalancer_id = "${azurerm_lb.azlb.id}"
name = "${element(keys(var.lb_port), count.index)}"
protocol = "${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 1)}"
frontend_port = "${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 0)}"
backend_port = "${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 2)}"
frontend_ip_configuration_name = "${var.frontend_name}"
count = length(var.lb_port)
name = element(keys(var.lb_port), count.index)
resource_group_name = azurerm_resource_group.azlb.name
loadbalancer_id = azurerm_lb.azlb.id
protocol = element(var.lb_port[element(keys(var.lb_port), count.index)], 1)
frontend_port = element(var.lb_port[element(keys(var.lb_port), count.index)], 0)
backend_port = element(var.lb_port[element(keys(var.lb_port), count.index)], 2)
frontend_ip_configuration_name = var.frontend_name
enable_floating_ip = false
backend_address_pool_id = "${azurerm_lb_backend_address_pool.azlb.id}"
backend_address_pool_id = azurerm_lb_backend_address_pool.azlb.id
idle_timeout_in_minutes = 5
probe_id = "${element(azurerm_lb_probe.azlb.*.id,count.index)}"
depends_on = ["azurerm_lb_probe.azlb"]
probe_id = element(azurerm_lb_probe.azlb.*.id, count.index)
}
14 changes: 6 additions & 8 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
provider "azurerm" {
features {}
}

resource "random_id" "rg_name" {
byte_length = 8
}
Expand All @@ -8,17 +12,11 @@ module "mylb" {
location = "${var.location}"
prefix = "${random_id.rg_name.hex}"

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

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

module "network" {
source = "Azure/network/azurerm"
location = "${var.location}"
resource_group_name = "${random_id.rg_name.hex}"
}
8 changes: 4 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ variable "frontend_name" {
default = "myPublicIP"
}

variable "public_ip_address_allocation" {
variable "allocation_method" {
description = "(Required) Defines how an IP address is assigned. Options are Static or Dynamic."
default = "static"
default = "Static"
}

variable "tags" {
type = "map"
type = map(string)

default = {
source = "terraform"
}
}

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

0 comments on commit b40b8fc

Please sign in to comment.