From 27b580ba3086f7ab79cc8cde66be2e6fc6064e6e Mon Sep 17 00:00:00 2001 From: "jelle.broekhuijsen@gridly.nl" Date: Wed, 12 Jul 2023 16:34:00 +0200 Subject: [PATCH 1/3] Remove dependency on data source for static values --- main.tf | 38 +++++++++++++++++++------------------- variables.tf | 5 +++++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/main.tf b/main.tf index 237c6f1..0920120 100644 --- a/main.tf +++ b/main.tf @@ -199,8 +199,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) } @@ -255,8 +255,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 @@ -270,8 +270,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 @@ -284,8 +284,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 @@ -299,8 +299,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"] @@ -317,8 +317,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}" @@ -343,8 +343,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 { @@ -374,8 +374,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 { @@ -437,8 +437,8 @@ resource "azurerm_network_interface_application_security_group_association" "int # Create F5 BIGIP1 resource "azurerm_linux_virtual_machine" "f5vm01" { 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 @@ -531,6 +531,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]] # } diff --git a/variables.tf b/variables.tf index e64cf99..f7ec835 100644 --- a/variables.tf +++ b/variables.tf @@ -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 +} \ No newline at end of file From 859ac9869875b000559c58d1511a5fa678519906 Mon Sep 17 00:00:00 2001 From: "jelle.broekhuijsen@gridly.nl" Date: Wed, 12 Jul 2023 16:36:05 +0200 Subject: [PATCH 2/3] Add ignore changes of password and custom_data --- main.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.tf b/main.tf index 0920120..c85523c 100644 --- a/main.tf +++ b/main.tf @@ -436,6 +436,12 @@ 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 = var.location resource_group_name = var.resource_group_name From 06799677422041523b17fc0d59377e03d89f8c68 Mon Sep 17 00:00:00 2001 From: "jelle.broekhuijsen@gridly.nl" Date: Wed, 12 Jul 2023 16:38:54 +0200 Subject: [PATCH 3/3] Remove obsolete data source --- main.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.tf b/main.tf index c85523c..8b49156 100644 --- a/main.tf +++ b/main.tf @@ -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" {