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

Code suggestion: limit recreation scenarios of bigip vm #56

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
48 changes: 25 additions & 23 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ resource "random_id" "module_id" {
byte_length = 2
}

data "azurerm_resource_group" "bigiprg" {
name = var.resource_group_name
}

data "azurerm_subscription" "current" {
}
data "azurerm_client_config" "current" {
Expand All @@ -199,8 +195,8 @@ data "azurerm_client_config" "current" {
resource "azurerm_user_assigned_identity" "user_identity" {
count = var.user_identity == null ? 1 : 0
name = format("%s-ident", local.instance_prefix)
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = var.resource_group_name
location = var.location
tags = merge(local.tags, {
Name = format("%s-ident", local.instance_prefix)
}
Expand Down Expand Up @@ -255,8 +251,8 @@ resource "random_string" "password" {
resource "azurerm_public_ip" "mgmt_public_ip" {
count = length(local.mgmt_public_subnet_id)
name = "${local.instance_prefix}-pip-mgmt-${count.index}"
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = var.location
resource_group_name = var.resource_group_name
domain_name_label = format("%s-mgmt-%s", local.instance_prefix, count.index)
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
Expand All @@ -270,8 +266,8 @@ resource "azurerm_public_ip" "mgmt_public_ip" {
resource "azurerm_public_ip" "external_public_ip" {
count = length(local.external_public_subnet_id)
name = "${local.instance_prefix}-pip-ext-${count.index}"
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = var.location
resource_group_name = var.resource_group_name
domain_name_label = format("%s-ext-%s", local.instance_prefix, count.index)
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
Expand All @@ -284,8 +280,8 @@ resource "azurerm_public_ip" "external_public_ip" {
resource "azurerm_public_ip" "secondary_external_public_ip" {
count = var.cfe_secondary_vip_disable ? 0 : length(local.external_public_subnet_id)
name = "${local.instance_prefix}-secondary-pip-ext-${count.index}"
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = var.location
resource_group_name = var.resource_group_name
domain_name_label = format("%s-sec-ext-%s", local.instance_prefix, count.index)
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
Expand All @@ -299,8 +295,8 @@ resource "azurerm_public_ip" "secondary_external_public_ip" {
resource "azurerm_network_interface" "mgmt_nic" {
count = length(local.bigip_map["mgmt_subnet_ids"])
name = "${local.instance_prefix}-mgmt-nic-${count.index}"
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = var.location
resource_group_name = var.resource_group_name
ip_configuration {
name = "${local.instance_prefix}-mgmt-ip-${count.index}"
subnet_id = local.bigip_map["mgmt_subnet_ids"][count.index]["subnet_id"]
Expand All @@ -317,8 +313,8 @@ resource "azurerm_network_interface" "mgmt_nic" {
resource "azurerm_network_interface" "external_nic" {
count = length(local.external_private_subnet_id)
name = "${local.instance_prefix}-ext-nic-${count.index}"
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = var.location
resource_group_name = var.resource_group_name
enable_ip_forwarding = var.external_enable_ip_forwarding
ip_configuration {
name = "${local.instance_prefix}-ext-ip-${count.index}"
Expand All @@ -343,8 +339,8 @@ resource "azurerm_network_interface" "external_nic" {
resource "azurerm_network_interface" "external_public_nic" {
count = length(local.external_public_subnet_id)
name = "${local.instance_prefix}-ext-nic-public-${count.index}"
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = var.location
resource_group_name = var.resource_group_name
enable_ip_forwarding = var.external_enable_ip_forwarding

ip_configuration {
Expand Down Expand Up @@ -374,8 +370,8 @@ resource "azurerm_network_interface" "external_public_nic" {
resource "azurerm_network_interface" "internal_nic" {
count = length(local.internal_private_subnet_id)
name = "${local.instance_prefix}-int-nic${count.index}"
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = var.location
resource_group_name = var.resource_group_name
//enable_accelerated_networking = var.enable_accelerated_networking

ip_configuration {
Expand Down Expand Up @@ -436,9 +432,15 @@ resource "azurerm_network_interface_application_security_group_association" "int

# Create F5 BIGIP1
resource "azurerm_linux_virtual_machine" "f5vm01" {
lifecycle {
ignore_changes = [
admin_password,
custom_data
]
}
name = var.vm_name == "" ? format("%s-f5vm01", local.instance_prefix) : var.vm_name
location = data.azurerm_resource_group.bigiprg.location
resource_group_name = data.azurerm_resource_group.bigiprg.name
location = var.location
resource_group_name = var.resource_group_name
network_interface_ids = concat(azurerm_network_interface.mgmt_nic.*.id, azurerm_network_interface.external_nic.*.id, azurerm_network_interface.external_public_nic.*.id, azurerm_network_interface.internal_nic.*.id)
size = var.f5_instance_type
disable_password_authentication = var.enable_ssh_key
Expand Down Expand Up @@ -531,6 +533,6 @@ resource "time_sleep" "wait_for_azurerm_virtual_machine_f5vm" {
# Getting Public IP Assigned to BIGIP
# data "azurerm_public_ip" "f5vm01mgmtpip" {
# name = azurerm_public_ip.mgmt_public_ip[0].name
# resource_group_name = data.azurerm_resource_group.bigiprg.name
# resource_group_name = var.resource_group_name
# depends_on = [azurerm_virtual_machine.f5vm01, azurerm_virtual_machine_extension.vmext, azurerm_public_ip.mgmt_public_ip[0]]
# }
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,8 @@ variable "sleep_time" {
default = "300s"
description = "The number of seconds/minutes of delay to build into creation of BIG-IP VMs; default is 250. BIG-IP requires a few minutes to complete the onboarding process and this value can be used to delay the processing of dependent Terraform resources."
}

variable "location" {
description = "The Azure region to deploy to"
type = string
}