From b9578856cda988a7807d7cbdea74e7c5d32184d3 Mon Sep 17 00:00:00 2001 From: Bernard Maltais Date: Fri, 20 Sep 2024 08:23:05 -0400 Subject: [PATCH] Remove custom_name support --- ESLZ/vmss-linuxV2.tf | 10 +++++----- ESLZ/vmss-linuxV2.tfvars | 5 ++--- boot-diagnostic.tf | 16 ++++++++-------- locals.tf | 6 +++--- name.tf | 2 +- output.tf | 4 ++-- variables.tf | 30 +++++++++++++++--------------- 7 files changed, 36 insertions(+), 37 deletions(-) diff --git a/ESLZ/vmss-linuxV2.tf b/ESLZ/vmss-linuxV2.tf index 4b6a13b..6a2488b 100644 --- a/ESLZ/vmss-linuxV2.tf +++ b/ESLZ/vmss-linuxV2.tf @@ -1,21 +1,21 @@ variable "vmss_linuxV2" { - type = any - default = {} + type = any + default = {} description = "Value for vmss_linuxV2. This is a collection of values as defined in vmss-linuxV2.tfvars" } module "vmss_linuxV2" { for_each = var.vmss_linuxV2 - source = "github.com/canada-ca-terraform-modules/terraform-azurerm-caf-vmss-linuxV2?ref=v1.0.2" + source = "github.com/canada-ca-terraform-modules/terraform-azurerm-caf-vmss-linuxV2?ref=v1.0.3" location = var.location subnets = local.subnets - resource_groups = local.resource_groups_all + resource_groups = local.resource_groups userDefinedString = each.key - tags = var.tags env = var.env group = var.group project = var.project + tags = var.tags vmss = each.value custom_data = try(each.value.custom_data, false) != false ? base64encode(file("${path.cwd}/${each.value.custom_data}")) : null user_data = try(each.value.user_data, false) != false ? base64encode(file("${path.cwd}/${each.value.user_data}")) : null diff --git a/ESLZ/vmss-linuxV2.tfvars b/ESLZ/vmss-linuxV2.tfvars index d42075c..fe5d57b 100644 --- a/ESLZ/vmss-linuxV2.tfvars +++ b/ESLZ/vmss-linuxV2.tfvars @@ -1,6 +1,5 @@ vmss_linuxV2 = { devops = { - # custom_name = "some-custom-name" # Optional. ONLY use if you really really really don't want to use the auto generated name userDefinedString = "devops" # Max 55 chars postfix = "01" computer_name_prefix = "vmsslin-" # (Optional) The prefix which should be used for the name of the Virtual Machines in this Scale Set. Default: "vmsslin-" @@ -103,9 +102,9 @@ vmss_linuxV2 = { frontend_ip_configuration = { feipc1 = { - subnet = "MAZ" # (Required) The name or the resource id of the Subnet which should be used for this IP Configuration + subnet = "MAZ" # (Required) The name or the resource id of the Subnet which should be used for this IP Configuration # private_ip_address = "10.10.10.10" # (Optional) Private IP Address to assign to the Load Balancer. The last one and first four IPs in any range are reserved and cannot be manually assigned. - private_ip_address_allocation = "Dynamic" # (Optional) The allocation method for the Private IP Address used by this Load Balancer. Possible values as Dynamic and Static. + private_ip_address_allocation = "Dynamic" # (Optional) The allocation method for the Private IP Address used by this Load Balancer. Possible values as Dynamic and Static. # private_ip_address_version = "IPv4" # (Optional) The version of IP that the Private IP Address is. Possible values are IPv4 or IPv6. # public_ip_address_id = "" # (Optional) The ID of a Public IP Address which should be associated with the Load Balancer. # public_ip_prefix_id = "" # (Optional) The ID of a Public IP Prefix which should be associated with the Load Balancer. Public IP Prefix can only be used with outbound rules. diff --git a/boot-diagnostic.tf b/boot-diagnostic.tf index 0b3965f..c4806b6 100644 --- a/boot-diagnostic.tf +++ b/boot-diagnostic.tf @@ -1,7 +1,7 @@ # A storage account is needed to store the boot diagnostic logs module "boot_diagnostic_storage" { source = "github.com/canada-ca-terraform-modules/terraform-azurerm-caf-storage_accountV2.git?ref=v1.0.3" - count = try(var.vmss.boot_diagnostic.use_managed_storage_account, true) ? 0 : (try(var.vmss.boot_diagnostic, false) ? (try(var.vmss.boot_diagnostic.storage_account_resource_id, "") == "" ? 1 : 0) : 0) + count = try(var.vmss.boot_diagnostic.use_managed_storage_account, true) ? 0 : (try(var.vmss.boot_diagnostic, false) ? (try(var.vmss.boot_diagnostic.storage_account_resource_id, "") == "" ? 1 : 0) : 0) userDefinedString = "${var.userDefinedString}-logs" location = var.location @@ -11,13 +11,13 @@ module "boot_diagnostic_storage" { private_dns_zone_ids = null tags = var.tags storage_account = { - resource_group = var.vmss.resource_group_name - account_tier = "Standard" - account_replication_type = "GRS" + resource_group = var.vmss.resource_group_name + account_tier = "Standard" + account_replication_type = "GRS" private_endpoint = { "${var.userDefinedString}-logs" = { - resource_group = var.vmss.resource_group_name - subnet = var.vmss.nic.nic1.ip_configuration.ipc1.subnet + resource_group = var.vmss.resource_group_name + subnet = var.vmss.nic.nic1.ip_configuration.ipc1.subnet subresource_names = ["blob"] } } @@ -37,7 +37,7 @@ resource "azurerm_user_assigned_identity" "user_assigned_identity_vmss_linux" { resource "azurerm_role_assignment" "vmss_contributor" { count = try(var.vmss.boot_diagnostic.use_managed_storage_account, true) ? 0 : (try(var.vmss.boot_diagnostic, false) ? 1 : 0) - scope = try(var.vmss.boot_diagnostic.storage_account_resource_id, "") == "" ? module.boot_diagnostic_storage[0].id : var.vmss.boot_diagnostic.storage_account_resource_id + scope = try(var.vmss.boot_diagnostic.storage_account_resource_id, "") == "" ? module.boot_diagnostic_storage[0].id : var.vmss.boot_diagnostic.storage_account_resource_id role_definition_name = "Storage Blob Data Contributor" - principal_id = try(var.vmss.identity.identity_ids, []) == [] ? azurerm_user_assigned_identity.user_assigned_identity_vmss_linux[0].principal_id : var.vmss.identity.identity_ids[0] + principal_id = try(var.vmss.identity.identity_ids, []) == [] ? azurerm_user_assigned_identity.user_assigned_identity_vmss_linux[0].principal_id : var.vmss.identity.identity_ids[0] } \ No newline at end of file diff --git a/locals.tf b/locals.tf index 6796306..86564c4 100644 --- a/locals.tf +++ b/locals.tf @@ -1,10 +1,10 @@ locals { # If resource_group was an ID, then parse the ID for the name, if not, then search in the provided resource_groups object - resource_group_name = strcontains(var.vmss.resource_group_name, "/resourceGroups/") ? regex("[^\\/]+$", var.vmss.resource_group_name) : var.resource_groups[var.vmss.resource_group_name].name + resource_group_name = strcontains(var.vmss.resource_group_name, "/resourceGroups/") ? regex("[^\\/]+$", var.vmss.resource_group_name) : var.resource_groups[var.vmss.resource_group_name].name # If disable_password_authentication is set to true, then no password is set. In this case, a ssh key is required. vm-admin-password = try(var.vmss.disable_password_authentication, false) ? null : (try(var.vmss.admin_password, "") == "" ? random_password.vm-admin-password[0].result : var.vmss.admin_password) - + # This list is used to organize the nics given to the module, used to determine which NIC will be the primary one. (At index 0) - nic_indices = {for k, v in var.vmss.nic : k => index(keys(var.vmss.nic), k)} + nic_indices = { for k, v in var.vmss.nic : k => index(keys(var.vmss.nic), k) } } \ No newline at end of file diff --git a/name.tf b/name.tf index 71362c0..fb3fd92 100644 --- a/name.tf +++ b/name.tf @@ -4,5 +4,5 @@ locals { serverType_3 = "SLG" postfix_3 = substr(var.vmss.postfix, 0, 3) userDefinedString_54 = substr(var.userDefinedString, 0, 54 - length(local.postfix_3)) - vmss_name = try(var.vmss.custom_name, replace("${local.env_4}${local.serverType_3}-${local.userDefinedString_54}${local.postfix_3}", local.vmss_linux_regex, "")) + vmss_name = replace("${local.env_4}${local.serverType_3}-${local.userDefinedString_54}${local.postfix_3}", local.vmss_linux_regex, "") } diff --git a/output.tf b/output.tf index 7ddffd6..8ff2297 100644 --- a/output.tf +++ b/output.tf @@ -1,9 +1,9 @@ output "vmss_linux" { - value = azurerm_linux_virtual_machine_scale_set.vmss_linux + value = azurerm_linux_virtual_machine_scale_set.vmss_linux description = "VMSS Linux object" } output "loadbalancer" { - value = azurerm_lb.loadbalancer + value = azurerm_lb.loadbalancer description = "Load Balancer object" } \ No newline at end of file diff --git a/variables.tf b/variables.tf index 552f6e0..e370bae 100644 --- a/variables.tf +++ b/variables.tf @@ -1,33 +1,33 @@ variable "location" { description = "Azure location for the VM" - type = string - default = "canadacentral" + type = string + default = "canadacentral" } variable "tags" { description = "Tags that will be applied to every associated VM resource" - type = map(string) - default = {} + type = map(string) + default = {} } variable "env" { description = "(Required) 4 character string defining the environment name prefix for the VM" - type = string + type = string } variable "group" { description = "(Required) Character string defining the group for the target subscription" - type = string + type = string } variable "project" { description = "(Required) Character string defining the project for the target subscription" - type = string + type = string } variable "userDefinedString" { description = "(Required) User defined portion value for the name of the VM." - type = string + type = string } variable "vmss" { @@ -38,23 +38,23 @@ variable "vmss" { variable "resource_groups" { description = "(Required) Resource group object for the VM" - type = any - default = {} + type = any + default = {} } variable "subnets" { description = "(Required) List of subnet objects for the VM" - type = any + type = any } variable "custom_data" { description = "(Optional) The Base64-Encoded Custom Data which should be used for this Virtual Machine Scale Set." - type = string - default = null + type = string + default = null } variable "user_data" { description = "(Optional) The Base64-Encoded User Data which should be used for this Virtual Machine Scale Set." - type = string - default = null + type = string + default = null } \ No newline at end of file