Skip to content

Commit 13c625f

Browse files
authored
KUBE-1856: Expose EncryptionAtHost AKS setting in terraform. (#665)
* Add EncryptionAtHost field to nodeconfig * Update docs * Regenerate SDK
1 parent 4cf875d commit 13c625f

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

castai/resource_node_configuration.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const (
4848
FieldNodeConfigurationAKSApplicationSecurityGroups = "application_security_groups"
4949
FieldNodeConfigurationAKSPublicIP = "public_ip"
5050
FieldNodeConfigurationAKSPodSubnetID = "pod_subnet_id"
51+
FieldNodeConfigurationAKSEncryptionAtHost = "enable_encryption_at_host"
5152
)
5253

5354
const (
@@ -491,6 +492,11 @@ func resourceNodeConfiguration() *schema.Resource {
491492
Optional: true,
492493
Description: "ID of pod subnet to be used for provisioned nodes.",
493494
},
495+
FieldNodeConfigurationAKSEncryptionAtHost: {
496+
Type: schema.TypeBool,
497+
Optional: true,
498+
Description: "Whether to enable encryption at host for provisioned nodes. See https://learn.microsoft.com/en-us/azure/virtual-machines/disk-encryption#encryption-at-host---end-to-end-encryption-for-your-vm-data",
499+
},
494500
},
495501
},
496502
},
@@ -1190,6 +1196,10 @@ func toAKSSConfig(obj map[string]interface{}) *sdk.NodeconfigV1AKSConfig {
11901196
out.PodSubnetId = toPtr(v)
11911197
}
11921198

1199+
if v, ok := obj[FieldNodeConfigurationAKSEncryptionAtHost].(bool); ok {
1200+
out.EnableEncryptionAtHost = toPtr(v)
1201+
}
1202+
11931203
return out
11941204
}
11951205

@@ -1386,6 +1396,10 @@ func flattenAKSConfig(config *sdk.NodeconfigV1AKSConfig) []map[string]interface{
13861396
m[FieldNodeConfigurationAKSPodSubnetID] = *v
13871397
}
13881398

1399+
if v := config.EnableEncryptionAtHost; v != nil {
1400+
m[FieldNodeConfigurationAKSEncryptionAtHost] = *v
1401+
}
1402+
13891403
return []map[string]interface{}{m}
13901404
}
13911405

castai/resource_node_configuration_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,55 @@ func Test_NodeConfiguration_UpdateContext(t *testing.T) {
376376
})
377377
}
378378
}
379+
380+
func TestToAKSSConfig_EnableEncryptionAtHost(t *testing.T) {
381+
tests := []struct {
382+
name string
383+
input any
384+
expected any
385+
}{
386+
{name: "true", input: true, expected: true},
387+
{name: "false", input: false, expected: false},
388+
{name: "nil", input: nil, expected: nil},
389+
}
390+
for _, tt := range tests {
391+
t.Run(tt.name, func(t *testing.T) {
392+
out := toAKSSConfig(map[string]any{
393+
FieldNodeConfigurationAKSEncryptionAtHost: tt.input,
394+
})
395+
396+
if tt.expected == nil {
397+
require.Nil(t, out.EnableEncryptionAtHost)
398+
} else {
399+
require.Equal(t, tt.expected, *out.EnableEncryptionAtHost)
400+
}
401+
})
402+
}
403+
404+
t.Run("empty", func(t *testing.T) {
405+
out := toAKSSConfig(map[string]any{})
406+
407+
require.Nil(t, out.EnableEncryptionAtHost)
408+
})
409+
}
410+
411+
func TestFlattenAKSConfig_EnableEncryptionAtHost(t *testing.T) {
412+
tests := []struct {
413+
name string
414+
input *bool
415+
expected any
416+
}{
417+
{name: "true", input: toPtr(true), expected: true},
418+
{name: "false", input: toPtr(false), expected: false},
419+
{name: "nil", input: nil, expected: nil},
420+
}
421+
for _, tt := range tests {
422+
t.Run(tt.name, func(t *testing.T) {
423+
result := flattenAKSConfig(&sdk.NodeconfigV1AKSConfig{
424+
EnableEncryptionAtHost: tt.input,
425+
})
426+
require.Len(t, result, 1)
427+
require.Equal(t, tt.expected, result[0][FieldNodeConfigurationAKSEncryptionAtHost])
428+
})
429+
}
430+
}

castai/sdk/api.gen.go

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/resources/node_configuration.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)