From e8efc3f6713c626b67f76f2af293705743b78d4b Mon Sep 17 00:00:00 2001 From: Stephen Turcol <107954323+stturc@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:53:52 -0400 Subject: [PATCH] feat: (IAC-1001) Add ability to set allocation method for public ips of jump and nfs vms (#290) --- docs/CONFIG-VARS.md | 2 ++ modules/azurerm_vm/main.tf | 8 ++++---- modules/azurerm_vm/variables.tf | 6 ++++++ variables.tf | 12 ++++++++++++ vms.tf | 30 ++++++++++++++++-------------- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/docs/CONFIG-VARS.md b/docs/CONFIG-VARS.md index 8028b985..5a34bac6 100644 --- a/docs/CONFIG-VARS.md +++ b/docs/CONFIG-VARS.md @@ -185,6 +185,7 @@ Ubuntu 20.04 LTS is the operating system used on the Jump/NFS servers. Ubuntu cr | kubernetes_version | The AKS cluster Kubernetes version | string | "1.26" |Use of specific versions is still supported. If you need exact kubernetes version please use format `x.y.z`, where `x` is the major version, `y` is the minor version, and `z` is the patch version | | create_jump_vm | Create bastion host | bool | true | | | create_jump_public_ip | Add public IP address to the jump VM | bool | true | | +| enable_jump_public_static_ip | Enables `Static` allocation method for the public IP address of Jump Server. Setting false will enable `Dynamic` allocation method. | bool | true | Only used with `create_jump_public_ip=true` | | jump_vm_admin | Operating system Admin User for the jump VM | string | "jumpuser" | | | jump_vm_machine_type | SKU to use for the jump VM | string | "Standard_B2s" | To check for valid types for your subscription, run: `az vm list-skus --resource-type virtualMachines --subscription $subscription --location $location -o table`| | jump_rwx_filestore_path | File store mount point on jump server | string | "/viya-share" | This location cannot include `/mnt` as its root location. This disk is ephemeral on Ubuntu, which is the operating system being used for the jump/NFS servers. | @@ -300,6 +301,7 @@ When `storage_type=standard`, a NFS Server VM is created, only when these variab | Name | Description | Type | Default | Notes | | :--- | ---: | ---: | ---: | ---: | | create_nfs_public_ip | Add public ip to the NFS server VM | bool | false | | +| enable_nfs_public_static_ip | Enables `Static` allocation method for the public IP address of NFS Server. Setting false will enable `Dynamic` allocation method | bool | true | Only used with `create_nfs_public_ip=true` | | nfs_vm_admin | OS Admin User for the NFS server VM | string | "nfsuser" | | | nfs_vm_machine_type | SKU to use for NFS server VM | string | "Standard_D8s_v4" | To check for valid types for your subscription, run: `az vm list-skus --resource-type virtualMachines --subscription $subscription --location $location -o table`| | nfs_vm_zone | Zone in which NFS server VM should be created | string | null | | diff --git a/modules/azurerm_vm/main.tf b/modules/azurerm_vm/main.tf index 350ca503..97f48504 100644 --- a/modules/azurerm_vm/main.tf +++ b/modules/azurerm_vm/main.tf @@ -7,7 +7,7 @@ resource "azurerm_public_ip" "vm_ip" { name = "${var.name}-public_ip" location = var.azure_rg_location resource_group_name = var.azure_rg_name - allocation_method = "Static" + allocation_method = var.enable_public_static_ip ? "Static" : "Dynamic" sku = var.vm_zone == null ? "Basic" : "Standard" zones = var.vm_zone == null ? [] : [var.vm_zone] tags = var.tags @@ -93,9 +93,9 @@ resource "azurerm_linux_virtual_machine" "vm" { dynamic "plan" { for_each = var.fips_enabled ? [1] : [] content { - name = "pro-fips-20_04-gen2" - publisher = "canonical" - product = "0001-com-ubuntu-pro-focal-fips" + name = "pro-fips-20_04-gen2" + publisher = "canonical" + product = "0001-com-ubuntu-pro-focal-fips" } } diff --git a/modules/azurerm_vm/variables.tf b/modules/azurerm_vm/variables.tf index 28c06eee..1bd3b989 100644 --- a/modules/azurerm_vm/variables.tf +++ b/modules/azurerm_vm/variables.tf @@ -151,6 +151,12 @@ variable "create_public_ip" { default = false } +variable "enable_public_static_ip" { + description = "Enables `Static` allocation method for the public IP address. Setting false will enable `Dynamic` allocation method." + type = bool + default = true +} + variable "proximity_placement_group_id" { description = "The ID of the Proximity Placement Group which the Virtual Machine should be assigned to." type = string diff --git a/variables.tf b/variables.tf index 616343d3..23cc644a 100644 --- a/variables.tf +++ b/variables.tf @@ -320,6 +320,12 @@ variable "create_jump_public_ip" { default = true } +variable "enable_jump_public_static_ip" { + description = "Enables `Static` allocation method for the public IP address of Jump Server. Setting false will enable `Dynamic` allocation method." + type = bool + default = true +} + variable "jump_vm_admin" { description = "OS Admin User for Jump VM" type = string @@ -361,6 +367,12 @@ variable "create_nfs_public_ip" { default = false } +variable "enable_nfs_public_static_ip" { + description = "Enables `Static` allocation method for the public IP address of NFS Server. Setting false will enable `Dynamic` allocation method." + type = bool + default = true +} + variable "nfs_vm_machine_type" { description = "SKU which should be used for this Virtual Machine" type = string diff --git a/vms.tf b/vms.tf index 8813535d..e941f8db 100644 --- a/vms.tf +++ b/vms.tf @@ -54,20 +54,21 @@ data "cloudinit_config" "jump" { module "jump" { source = "./modules/azurerm_vm" - count = var.create_jump_vm ? 1 : 0 - name = "${var.prefix}-jump" - azure_rg_name = local.aks_rg.name - azure_rg_location = var.location - vnet_subnet_id = module.vnet.subnets["misc"].id - machine_type = var.jump_vm_machine_type - azure_nsg_id = local.nsg.id - tags = var.tags - vm_admin = var.jump_vm_admin - vm_zone = var.jump_vm_zone - fips_enabled = var.fips_enabled - ssh_public_key = local.ssh_public_key - cloud_init = data.cloudinit_config.jump[0].rendered - create_public_ip = var.create_jump_public_ip + count = var.create_jump_vm ? 1 : 0 + name = "${var.prefix}-jump" + azure_rg_name = local.aks_rg.name + azure_rg_location = var.location + vnet_subnet_id = module.vnet.subnets["misc"].id + machine_type = var.jump_vm_machine_type + azure_nsg_id = local.nsg.id + tags = var.tags + vm_admin = var.jump_vm_admin + vm_zone = var.jump_vm_zone + fips_enabled = var.fips_enabled + ssh_public_key = local.ssh_public_key + cloud_init = data.cloudinit_config.jump[0].rendered + create_public_ip = var.create_jump_public_ip + enable_public_static_ip = var.enable_jump_public_static_ip # Jump VM mounts NFS path hence dependency on 'module.nfs' depends_on = [module.vnet, module.nfs] @@ -103,6 +104,7 @@ module "nfs" { ssh_public_key = local.ssh_public_key cloud_init = data.cloudinit_config.nfs[0].rendered create_public_ip = var.create_nfs_public_ip + enable_public_static_ip = var.enable_nfs_public_static_ip data_disk_count = 4 data_disk_size = var.nfs_raid_disk_size data_disk_storage_account_type = var.nfs_raid_disk_type