Skip to content

Commit ed20285

Browse files
azurerm_batch_pool - support for new block security_profile (#28069)
* Add `security_profile` block to `azurerm_batch_pool` * Change test format * Apply suggestions from code review Co-authored-by: catriona-m <86247157+catriona-m@users.noreply.github.com> * Update according to review comments * Change pointers package usage and doc based on review comments --------- Co-authored-by: catriona-m <86247157+catriona-m@users.noreply.github.com>
1 parent 32b3f42 commit ed20285

File tree

4 files changed

+158
-0
lines changed

4 files changed

+158
-0
lines changed

internal/services/batch/batch_pool.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,22 @@ func flattenBatchPoolIdentityReferenceToIdentityID(ref *pool.ComputeNodeIdentity
411411
return ""
412412
}
413413

414+
func flattenBatchPoolSecurityProfile(configProfile *pool.SecurityProfile) []interface{} {
415+
securityProfile := make([]interface{}, 0)
416+
securityConfig := make(map[string]interface{})
417+
418+
securityConfig["host_encryption_enabled"] = pointer.From(configProfile.EncryptionAtHost)
419+
securityConfig["security_type"] = string(pointer.From(configProfile.SecurityType))
420+
421+
if configProfile.UefiSettings != nil {
422+
securityConfig["secure_boot_enabled"] = pointer.From(configProfile.UefiSettings.SecureBootEnabled)
423+
securityConfig["vtpm_enabled"] = pointer.From(configProfile.UefiSettings.VTpmEnabled)
424+
}
425+
426+
securityProfile = append(securityProfile, securityConfig)
427+
return securityProfile
428+
}
429+
414430
func flattenBatchPoolUserAccount(d *pluginsdk.ResourceData, account *pool.UserAccount) map[string]interface{} {
415431
userAccount := make(map[string]interface{})
416432
userAccount["name"] = account.Name
@@ -791,13 +807,46 @@ func expandBatchPoolVirtualMachineConfig(d *pluginsdk.ResourceData) (*pool.Virtu
791807
result.OsDisk = expandBatchPoolOSDisk(v)
792808
}
793809

810+
if v, ok := d.GetOk("security_profile"); ok {
811+
result.SecurityProfile = expandBatchPoolSecurityProfile(v.([]interface{}))
812+
}
813+
794814
if v, ok := d.GetOk("windows"); ok {
795815
result.WindowsConfiguration = expandBatchPoolWindowsConfiguration(v.([]interface{}))
796816
}
797817

798818
return &result, nil
799819
}
800820

821+
func expandBatchPoolSecurityProfile(profile []interface{}) *pool.SecurityProfile {
822+
if len(profile) == 0 {
823+
return nil
824+
}
825+
826+
item := profile[0].(map[string]interface{})
827+
securityProfile := &pool.SecurityProfile{
828+
UefiSettings: &pool.UefiSettings{},
829+
}
830+
831+
if v, ok := item["host_encryption_enabled"]; ok {
832+
securityProfile.EncryptionAtHost = pointer.To(v.(bool))
833+
}
834+
835+
if v, ok := item["security_type"]; ok {
836+
securityProfile.SecurityType = pointer.To(pool.SecurityTypes(v.(string)))
837+
}
838+
839+
if v, ok := item["secure_boot_enabled"]; ok {
840+
securityProfile.UefiSettings.SecureBootEnabled = pointer.To(v.(bool))
841+
}
842+
843+
if v, ok := item["vtpm_enabled"]; ok {
844+
securityProfile.UefiSettings.VTpmEnabled = pointer.To(v.(bool))
845+
}
846+
847+
return securityProfile
848+
}
849+
801850
func expandBatchPoolOSDisk(ref interface{}) *pool.OSDisk {
802851
if ref == nil {
803852
return nil

internal/services/batch/batch_pool_resource.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,40 @@ func resourceBatchPool() *pluginsdk.Resource {
724724
}, false),
725725
},
726726

727+
"security_profile": {
728+
Type: pluginsdk.TypeList,
729+
Optional: true,
730+
ForceNew: true,
731+
MaxItems: 1,
732+
Elem: &pluginsdk.Resource{
733+
Schema: map[string]*pluginsdk.Schema{
734+
"host_encryption_enabled": {
735+
Type: pluginsdk.TypeBool,
736+
ForceNew: true,
737+
Optional: true,
738+
},
739+
"security_type": {
740+
Type: pluginsdk.TypeString,
741+
Optional: true,
742+
ForceNew: true,
743+
ValidateFunc: validation.StringInSlice(pool.PossibleValuesForSecurityTypes(), false),
744+
},
745+
"secure_boot_enabled": {
746+
Type: pluginsdk.TypeBool,
747+
Optional: true,
748+
ForceNew: true,
749+
RequiredWith: []string{"security_profile.0.security_type"},
750+
},
751+
"vtpm_enabled": {
752+
Type: pluginsdk.TypeBool,
753+
Optional: true,
754+
ForceNew: true,
755+
RequiredWith: []string{"security_profile.0.security_type"},
756+
},
757+
},
758+
},
759+
},
760+
727761
"target_node_communication_mode": {
728762
Type: pluginsdk.TypeString,
729763
Optional: true,
@@ -1246,11 +1280,17 @@ func resourceBatchPoolRead(d *pluginsdk.ResourceData, meta interface{}) error {
12461280
nodePlacementConfiguration = append(nodePlacementConfiguration, nodePlacementConfig)
12471281
d.Set("node_placement", nodePlacementConfiguration)
12481282
}
1283+
12491284
osDiskPlacement := ""
12501285
if config.OsDisk != nil && config.OsDisk.EphemeralOSDiskSettings != nil && config.OsDisk.EphemeralOSDiskSettings.Placement != nil {
12511286
osDiskPlacement = string(*config.OsDisk.EphemeralOSDiskSettings.Placement)
12521287
}
12531288
d.Set("os_disk_placement", osDiskPlacement)
1289+
1290+
if config.SecurityProfile != nil {
1291+
d.Set("security_profile", flattenBatchPoolSecurityProfile(config.SecurityProfile))
1292+
}
1293+
12541294
if config.WindowsConfiguration != nil {
12551295
windowsConfig := []interface{}{
12561296
map[string]interface{}{

internal/services/batch/batch_pool_resource_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,24 @@ func TestAccBatchPool_interNodeCommunicationWithTaskSchedulingPolicy(t *testing.
740740
})
741741
}
742742

743+
func TestAccBatchPool_securityProfileWithUEFISettings(t *testing.T) {
744+
data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test")
745+
r := BatchPoolResource{}
746+
data.ResourceTest(t, r, []acceptance.TestStep{
747+
{
748+
Config: r.securityProfileWithUEFISettings(data),
749+
Check: acceptance.ComposeTestCheckFunc(
750+
check.That(data.ResourceName).ExistsInAzure(r),
751+
check.That(data.ResourceName).Key("security_profile.0.host_encryption_enabled").HasValue("false"),
752+
check.That(data.ResourceName).Key("security_profile.0.security_type").HasValue("trustedLaunch"),
753+
check.That(data.ResourceName).Key("security_profile.0.secure_boot_enabled").HasValue("true"),
754+
check.That(data.ResourceName).Key("security_profile.0.vtpm_enabled").HasValue("false"),
755+
),
756+
},
757+
data.ImportStep("stop_pending_resize_operation"),
758+
})
759+
}
760+
743761
func TestAccBatchPool_linuxUserAccounts(t *testing.T) {
744762
data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test")
745763
r := BatchPoolResource{}
@@ -2657,3 +2675,37 @@ resource "azurerm_subnet_network_security_group_association" "test" {
26572675
}
26582676
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString)
26592677
}
2678+
2679+
func (BatchPoolResource) securityProfileWithUEFISettings(data acceptance.TestData) string {
2680+
template := BatchPoolResource{}.template(data)
2681+
return fmt.Sprintf(`
2682+
%s
2683+
resource "azurerm_batch_account" "test" {
2684+
name = "acctestbatch%s"
2685+
resource_group_name = azurerm_resource_group.test.name
2686+
location = azurerm_resource_group.test.location
2687+
}
2688+
resource "azurerm_batch_pool" "test" {
2689+
name = "acctestpool%s"
2690+
resource_group_name = azurerm_resource_group.test.name
2691+
account_name = azurerm_batch_account.test.name
2692+
node_agent_sku_id = "batch.node.ubuntu 22.04"
2693+
vm_size = "Standard_A1"
2694+
fixed_scale {
2695+
target_dedicated_nodes = 1
2696+
}
2697+
security_profile {
2698+
host_encryption_enabled = false
2699+
security_type = "trustedLaunch"
2700+
secure_boot_enabled = true
2701+
vtpm_enabled = false
2702+
}
2703+
storage_image_reference {
2704+
publisher = "Canonical"
2705+
offer = "0001-com-ubuntu-server-jammy"
2706+
sku = "22_04-lts"
2707+
version = "latest"
2708+
}
2709+
}
2710+
`, template, data.RandomString, data.RandomString)
2711+
}

website/docs/r/batch_pool.html.markdown

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ The following arguments are supported:
165165

166166
* `os_disk_placement` - (Optional) Specifies the ephemeral disk placement for operating system disk for all VMs in the pool. This property can be used by user in the request to choose which location the operating system should be in. e.g., cache disk space for Ephemeral OS disk provisioning. For more information on Ephemeral OS disk size requirements, please refer to Ephemeral OS disk size requirements for Windows VMs at <https://docs.microsoft.com/en-us/azure/virtual-machines/windows/ephemeral-os-disks#size-requirements> and Linux VMs at <https://docs.microsoft.com/en-us/azure/virtual-machines/linux/ephemeral-os-disks#size-requirements>. The only possible value is `CacheDisk`.
167167

168+
* `security_profile` - (Optional) A `security_profile` block that describes the security settings for the Batch pool as defined below. Changing this forces a new resource to be created.
169+
168170
* `target_node_communication_mode` - (Optional) The desired node communication mode for the pool. Possible values are `Classic`, `Default` and `Simplified`.
169171

170172
* `task_scheduling_policy` - (Optional) A `task_scheduling_policy` block that describes how tasks are distributed across compute nodes in a pool as defined below. If not specified, the default is spread as defined below.
@@ -502,6 +504,21 @@ A `task_scheduling_policy` block supports the following:
502504

503505
* `node_fill_type` - (Optional) Supported values are "Pack" and "Spread". "Pack" means as many tasks as possible (taskSlotsPerNode) should be assigned to each node in the pool before any tasks are assigned to the next node in the pool. "Spread" means that tasks should be assigned evenly across all nodes in the pool.
504506

507+
---
508+
A `security_profile` block supports the following:
509+
510+
* `host_encryption_enabled` - (Optional) Whether to enable host encryption for the Virtual Machine or Virtual Machine Scale Set. This will enable the encryption for all the disks including Resource/Temp disk at host itself. Possible values are `true` and `false`. Changing this forces a new resource to be created.
511+
512+
* `security_type` - (Optional) The security type of the Virtual Machine. Possible values are `confidentialVM` and `trustedLaunch`. Changing this forces a new resource to be created.
513+
514+
* `secure_boot_enabled` - (Optional) Whether to enable secure boot for the Virtual Machine or Virtual Machine Scale Set. Possible values are `true` and `false`. Changing this forces a new resource to be created.
515+
516+
* `vtpm_enabled` - (Optional) Whether to enable virtual trusted platform module (vTPM) for the Virtual Machine or Virtual Machine Scale Set. Possible values are `true` and `false`. Changing this forces a new resource to be created.
517+
518+
~> **NOTE:** `security_profile` block can only be specified during creation and does not support updates.
519+
520+
~> **NOTE:** `security_type` must be specified to set UEFI related properties including `secure_boot_enabled` and `vtpm_enabled`.
521+
505522
---
506523

507524
A `user_accounts` block supports the following:

0 commit comments

Comments
 (0)