Skip to content

Commit 67229a7

Browse files
committed
netapp_enable_cmk_encryption
Signed-off-by: Jeff Owens <[email protected]>
1 parent 2fa7d22 commit 67229a7

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ module "netapp" {
259259
resource_group_name = local.aks_rg.name
260260
location = var.location
261261
subnet_id = module.vnet.subnets["netapp"].id
262-
network_features = var.netapp_network_features
262+
network_features = var.netapp_enable_cmk_encryption ? "Standard" : var.netapp_network_features
263263
service_level = var.netapp_service_level
264264
size_in_tb = var.netapp_size_in_tb
265265
protocols = var.netapp_protocols
@@ -269,6 +269,10 @@ module "netapp" {
269269
depends_on = [module.vnet]
270270

271271
community_netapp_volume_size = var.community_netapp_volume_size
272+
273+
netapp_enable_cmk_encryption = var.netapp_enable_cmk_encryption
274+
netapp_cmk_encryption_key_id = var.netapp_cmk_encryption_key_id
275+
netapp_cmk_encryption_key_uai = var.netapp_cmk_encryption_key_uai
272276
}
273277

274278
data "external" "git_hash" {

modules/azurerm_netapp/main.tf

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ resource "azurerm_netapp_account" "anf" {
1010
location = var.location
1111
resource_group_name = var.resource_group_name
1212
tags = var.tags
13+
14+
dynamic "identity" {
15+
for_each = var.netapp_enable_cmk_encryption ? [1] : []
16+
content {
17+
type = "UserAssigned"
18+
identity_ids = [var.netapp_cmk_encryption_key_uai]
19+
}
20+
}
21+
}
22+
23+
resource "azurerm_netapp_account_encryption" "anf" {
24+
count = var.netapp_enable_cmk_encryption ? 1 : 0
25+
26+
netapp_account_id = azurerm_netapp_account.anf.id
27+
encryption_key = var.netapp_cmk_encryption_key_id
28+
user_assigned_identity_id = var.netapp_cmk_encryption_key_uai
1329
}
1430

1531
resource "azurerm_netapp_pool" "anf" {
@@ -20,6 +36,10 @@ resource "azurerm_netapp_pool" "anf" {
2036
service_level = var.service_level
2137
size_in_tb = var.size_in_tb
2238
tags = var.tags
39+
40+
depends_on = [
41+
azurerm_netapp_account_encryption.anf
42+
]
2343
}
2444

2545
resource "azurerm_netapp_volume" "anf" {
@@ -49,6 +69,8 @@ resource "azurerm_netapp_volume" "anf" {
4969
}
5070

5171
depends_on = [
52-
azurerm_netapp_pool.anf
72+
azurerm_netapp_pool.anf,
73+
azurerm_netapp_account_encryption.anf
5374
]
5475
}
76+

modules/azurerm_netapp/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ variable "allowed_clients" {
5555
default = ["0.0.0.0/0"]
5656
}
5757

58+
variable "netapp_enable_cmk_encryption" {
59+
description = "Setting this variable to true enables CMK encryption on the netapp account. Only relevant when storage_type=ha."
60+
type = bool
61+
default = false
62+
}
63+
64+
variable "netapp_cmk_encryption_key_id" {
65+
description = "The ID of the key in keyvault to Encrypt ANF with (i.e. https://<keyvault-name>.vault.azure.net/keys/<key-name>). Must exist before running terraform. Only relevant when storage_type=ha. Required if enable_anf_cmk_encryption is true."
66+
type = string
67+
default = null
68+
}
69+
70+
variable "netapp_cmk_encryption_key_uai" {
71+
description = "The user assigned identity that will be used to access the key (i.e. /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<uai name>). Must exist and have Key Vault Crypto Service Encryption User permission on the keyvault before running terraform. Only relevant when storage_type=ha. Required if enable_anf_cmk_encryption is true."
72+
type = string
73+
default = null
74+
}
75+
5876
variable "tags" {
5977
description = "Map of tags to be placed on the Resources"
6078
type = map(any)

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,24 @@ variable "netapp_network_features" {
546546
}
547547
}
548548

549+
variable "netapp_enable_cmk_encryption" {
550+
description = "Setting this variable to true enables CMK encryption on the netapp account. Only relevant when storage_type=ha."
551+
type = bool
552+
default = false
553+
}
554+
555+
variable "netapp_cmk_encryption_key_id" {
556+
description = "The ID of the key in keyvault to Encrypt ANF with (i.e. https://<keyvault-name>.vault.azure.net/keys/<key-name>). Must exist before running terraform. Only relevant when storage_type=ha. Required if enable_anf_cmk_encryption is true."
557+
type = string
558+
default = null
559+
}
560+
561+
variable "netapp_cmk_encryption_key_uai" {
562+
description = "The user assigned identity that will be used to access the key (i.e. /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<uai name>). Must exist and have Key Vault Crypto Service Encryption User permission on the keyvault before running terraform. Only relevant when storage_type=ha. Required if enable_anf_cmk_encryption is true."
563+
type = string
564+
default = null
565+
}
566+
549567
variable "node_pools_availability_zone" {
550568
description = "Specifies a Availability Zone in which the Kubernetes Cluster Node Pool should be located."
551569
type = string

0 commit comments

Comments
 (0)