Skip to content

Commit

Permalink
Remove custom_name support
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardmaltais committed Sep 20, 2024
1 parent e0a713e commit b957885
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 37 deletions.
10 changes: 5 additions & 5 deletions ESLZ/vmss-linuxV2.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions ESLZ/vmss-linuxV2.tfvars
Original file line number Diff line number Diff line change
@@ -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-"
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions boot-diagnostic.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
}
}
Expand All @@ -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]
}
6 changes: 3 additions & 3 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -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) }
}
2 changes: 1 addition & 1 deletion name.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}
4 changes: 2 additions & 2 deletions output.tf
Original file line number Diff line number Diff line change
@@ -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"
}
30 changes: 15 additions & 15 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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
}

0 comments on commit b957885

Please sign in to comment.