Skip to content

Commit a8358af

Browse files
authored
feat: (IAC-1386) EncryptAtHost changes for NIST (#372)
1 parent f12ea54 commit a8358af

File tree

9 files changed

+112
-43
lines changed

9 files changed

+112
-43
lines changed

main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ data "azurerm_resource_group" "aks_rg" {
4949
count = var.resource_group_name == null ? 0 : 1
5050
name = var.resource_group_name
5151
}
52+
5253
resource "azurerm_proximity_placement_group" "proximity" {
5354
count = var.node_pools_proximity_placement ? 1 : 0
5455

@@ -143,6 +144,8 @@ module "aks" {
143144
aks_cluster_max_pods = var.default_nodepool_max_pods
144145
aks_cluster_os_disk_size = var.default_nodepool_os_disk_size
145146
aks_cluster_node_vm_size = var.default_nodepool_vm_type
147+
aks_cluster_enable_host_encryption = var.aks_cluster_enable_host_encryption
148+
aks_node_disk_encryption_set_id = var.aks_node_disk_encryption_set_id
146149
aks_cluster_node_admin = var.node_vm_admin
147150
aks_cluster_ssh_public_key = try(file(var.ssh_public_key), "")
148151
aks_cluster_private_dns_zone_id = var.aks_cluster_private_dns_zone_id
@@ -206,6 +209,7 @@ module "node_pools" {
206209
zones = (var.node_pools_availability_zone == "" || var.node_pools_proximity_placement == true) ? [] : (var.node_pools_availability_zones != null) ? var.node_pools_availability_zones : [var.node_pools_availability_zone]
207210
proximity_placement_group_id = element(coalescelist(azurerm_proximity_placement_group.proximity[*].id, [""]), 0)
208211
orchestrator_version = var.kubernetes_version
212+
enable_host_encryption = var.aks_cluster_enable_host_encryption
209213
tags = var.tags
210214
}
211215

modules/aks_node_pool/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "autoscale_node_pool" {
1010
vnet_subnet_id = var.vnet_subnet_id
1111
zones = var.zones
1212
fips_enabled = var.fips_enabled
13+
enable_host_encryption = var.enable_host_encryption
1314
proximity_placement_group_id = var.proximity_placement_group_id == "" ? null : var.proximity_placement_group_id
1415
vm_size = var.machine_type
1516
os_disk_size_gb = var.os_disk_size
@@ -40,6 +41,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "static_node_pool" {
4041
vnet_subnet_id = var.vnet_subnet_id
4142
zones = var.zones
4243
fips_enabled = var.fips_enabled
44+
enable_host_encryption = var.enable_host_encryption
4345
proximity_placement_group_id = var.proximity_placement_group_id == "" ? null : var.proximity_placement_group_id
4446
vm_size = var.machine_type
4547
os_disk_size_gb = var.os_disk_size

modules/aks_node_pool/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ variable "fips_enabled" {
2323
default = false
2424
}
2525

26+
variable "enable_host_encryption" {
27+
description = "Enables host encryption on all the nodes in the Node Pool. Changing this forces a new resource to be created."
28+
type = bool
29+
default = false
30+
}
31+
2632
variable "vnet_subnet_id" {
2733
description = "The ID of the Subnet where this Node Pool should exist. Changing this forces a new resource to be created."
2834
type = string

modules/azure_aks/main.tf

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ resource "azurerm_kubernetes_cluster" "aks" {
1313
support_plan = var.cluster_support_tier
1414
role_based_access_control_enabled = true
1515
http_application_routing_enabled = false
16+
disk_encryption_set_id = var.aks_node_disk_encryption_set_id
1617

1718
# https://docs.microsoft.com/en-us/azure/aks/supported-kubernetes-versions
1819
# az aks get-versions --location eastus -o table
@@ -52,22 +53,23 @@ resource "azurerm_kubernetes_cluster" "aks" {
5253
}
5354

5455
default_node_pool {
55-
name = "system"
56-
vm_size = var.aks_cluster_node_vm_size
57-
zones = var.aks_availability_zones
58-
enable_auto_scaling = var.aks_cluster_node_auto_scaling
59-
enable_node_public_ip = false
60-
node_labels = {}
61-
node_taints = []
62-
fips_enabled = var.fips_enabled
63-
max_pods = var.aks_cluster_max_pods
64-
os_disk_size_gb = var.aks_cluster_os_disk_size
65-
max_count = var.aks_cluster_max_nodes
66-
min_count = var.aks_cluster_min_nodes
67-
node_count = var.aks_cluster_node_count
68-
vnet_subnet_id = var.aks_vnet_subnet_id
69-
tags = var.aks_cluster_tags
70-
orchestrator_version = var.kubernetes_version
56+
name = "system"
57+
vm_size = var.aks_cluster_node_vm_size
58+
zones = var.aks_availability_zones
59+
enable_auto_scaling = var.aks_cluster_node_auto_scaling
60+
enable_node_public_ip = false
61+
node_labels = {}
62+
node_taints = []
63+
fips_enabled = var.fips_enabled
64+
enable_host_encryption = var.aks_cluster_enable_host_encryption
65+
max_pods = var.aks_cluster_max_pods
66+
os_disk_size_gb = var.aks_cluster_os_disk_size
67+
max_count = var.aks_cluster_max_nodes
68+
min_count = var.aks_cluster_min_nodes
69+
node_count = var.aks_cluster_node_count
70+
vnet_subnet_id = var.aks_vnet_subnet_id
71+
tags = var.aks_cluster_tags
72+
orchestrator_version = var.kubernetes_version
7173
}
7274

7375
dynamic "service_principal" {

modules/azure_aks/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ variable "aks_cluster_max_pods" {
113113
default = 110
114114
}
115115

116+
variable "aks_cluster_enable_host_encryption" {
117+
description = "Enables host encryption on all the nodes in the Default Node Pool"
118+
type = bool
119+
default = false
120+
}
121+
122+
variable "aks_node_disk_encryption_set_id" {
123+
description = "The ID of the Disk Encryption Set which should be used for the Nodes and Volumes. Changing this forces a new resource to be created."
124+
type = string
125+
default = null
126+
}
127+
116128
variable "kubernetes_version" {
117129
description = "The AKS cluster K8s version"
118130
type = string

modules/azurerm_vm/main.tf

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ resource "azurerm_network_interface_security_group_association" "vm_nic_sg" {
3636

3737
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk
3838
resource "azurerm_managed_disk" "vm_data_disk" {
39-
count = var.data_disk_count
40-
name = format("%s-disk%02d", var.name, count.index + 1)
41-
location = var.azure_rg_location
42-
resource_group_name = var.azure_rg_name
43-
storage_account_type = var.data_disk_storage_account_type
44-
create_option = "Empty"
45-
disk_size_gb = var.data_disk_size
46-
zone = var.data_disk_zone
47-
tags = var.tags
39+
count = var.data_disk_count
40+
name = format("%s-disk%02d", var.name, count.index + 1)
41+
location = var.azure_rg_location
42+
resource_group_name = var.azure_rg_name
43+
storage_account_type = var.data_disk_storage_account_type
44+
create_option = "Empty"
45+
disk_size_gb = var.data_disk_size
46+
zone = var.data_disk_zone
47+
disk_encryption_set_id = var.disk_encryption_set_id
48+
tags = var.tags
4849
}
4950

5051
resource "azurerm_virtual_machine_data_disk_attachment" "vm_data_disk_attach" {
@@ -64,6 +65,7 @@ resource "azurerm_linux_virtual_machine" "vm" {
6465
size = var.machine_type
6566
admin_username = var.vm_admin
6667
zone = var.vm_zone
68+
encryption_at_host_enabled = var.encryption_at_host_enabled
6769

6870
#Cloud Init
6971
custom_data = (var.cloud_init != "" ? var.cloud_init : null)
@@ -78,9 +80,10 @@ resource "azurerm_linux_virtual_machine" "vm" {
7880
}
7981

8082
os_disk {
81-
caching = var.os_disk_caching
82-
storage_account_type = var.os_disk_storage_account_type
83-
disk_size_gb = var.os_disk_size
83+
caching = var.os_disk_caching
84+
storage_account_type = var.os_disk_storage_account_type
85+
disk_size_gb = var.os_disk_size
86+
disk_encryption_set_id = var.disk_encryption_set_id
8487
}
8588

8689
source_image_reference {

modules/azurerm_vm/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,15 @@ variable "proximity_placement_group_id" {
162162
type = string
163163
default = ""
164164
}
165+
166+
variable "encryption_at_host_enabled" {
167+
description = "Enables all of the disks (including the temp disk) attached to this Virtual Machine be encrypted by enabling Encryption at Host. Defaults to false"
168+
type = bool
169+
default = false
170+
}
171+
172+
variable "disk_encryption_set_id" {
173+
description = "The ID of the Disk Encryption Set which should be used to Encrypt this OS Disk."
174+
type = string
175+
default = null
176+
}

variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ variable "default_nodepool_availability_zones" {
165165
default = ["1"]
166166
}
167167

168+
variable "aks_cluster_enable_host_encryption" {
169+
description = "Enables host encryption on all the nodes in the Node Pool."
170+
type = bool
171+
default = false
172+
}
173+
174+
variable "aks_node_disk_encryption_set_id" {
175+
description = "The ID of the Disk Encryption Set which should be used for the Nodes and Volumes. Changing this forces a new resource to be created."
176+
type = string
177+
default = null
178+
}
179+
168180
# AKS advanced network config
169181
variable "aks_network_plugin" {
170182
description = "Network plugin to use for networking. Currently supported values are azure and kubenet. Changing this forces a new resource to be created."
@@ -362,6 +374,18 @@ variable "jump_rwx_filestore_path" {
362374
default = "/viya-share"
363375
}
364376

377+
variable "enable_vm_host_encryption" {
378+
description = "Setting this variable enables all of the disks (including the temp disk) attached to this Virtual Machine be encrypted by enabling Encryption at Host. This setting applies to both Jump and NFS VM. Defaults to false"
379+
type = bool
380+
default = false
381+
}
382+
383+
variable "vm_disk_encryption_set_id" {
384+
description = "The ID of the Disk Encryption Set which should be used to Encrypt this OS Disk. This setting applies to both Jump and NFS VM."
385+
type = string
386+
default = null
387+
}
388+
365389
variable "storage_type" {
366390
description = "Type of Storage. Valid Values: `standard`, `ha` and `none`. `standard` creates NFS server VM, `ha` creates Azure Netapp Files"
367391
type = string

vms.tf

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,23 @@ data "cloudinit_config" "jump" {
5454
module "jump" {
5555
source = "./modules/azurerm_vm"
5656

57-
count = var.create_jump_vm ? 1 : 0
58-
name = "${var.prefix}-jump"
59-
azure_rg_name = local.aks_rg.name
60-
azure_rg_location = var.location
61-
vnet_subnet_id = module.vnet.subnets["misc"].id
62-
machine_type = var.jump_vm_machine_type
63-
azure_nsg_id = local.nsg.id
64-
tags = var.tags
65-
vm_admin = var.jump_vm_admin
66-
vm_zone = var.jump_vm_zone
67-
fips_enabled = var.fips_enabled
68-
ssh_public_key = local.ssh_public_key
69-
cloud_init = data.cloudinit_config.jump[0].rendered
70-
create_public_ip = var.create_jump_public_ip
71-
enable_public_static_ip = var.enable_jump_public_static_ip
57+
count = var.create_jump_vm ? 1 : 0
58+
name = "${var.prefix}-jump"
59+
azure_rg_name = local.aks_rg.name
60+
azure_rg_location = var.location
61+
vnet_subnet_id = module.vnet.subnets["misc"].id
62+
machine_type = var.jump_vm_machine_type
63+
azure_nsg_id = local.nsg.id
64+
tags = var.tags
65+
vm_admin = var.jump_vm_admin
66+
vm_zone = var.jump_vm_zone
67+
fips_enabled = var.fips_enabled
68+
ssh_public_key = local.ssh_public_key
69+
cloud_init = data.cloudinit_config.jump[0].rendered
70+
create_public_ip = var.create_jump_public_ip
71+
enable_public_static_ip = var.enable_jump_public_static_ip
72+
encryption_at_host_enabled = var.enable_vm_host_encryption
73+
disk_encryption_set_id = var.vm_disk_encryption_set_id
7274

7375
# Jump VM mounts NFS path hence dependency on 'module.nfs'
7476
depends_on = [module.vnet, module.nfs]
@@ -109,6 +111,8 @@ module "nfs" {
109111
data_disk_size = var.nfs_raid_disk_size
110112
data_disk_storage_account_type = var.nfs_raid_disk_type
111113
data_disk_zone = var.nfs_raid_disk_zone
114+
encryption_at_host_enabled = var.enable_vm_host_encryption
115+
disk_encryption_set_id = var.vm_disk_encryption_set_id
112116
depends_on = [module.vnet]
113117
}
114118

0 commit comments

Comments
 (0)