Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_batch_pool - support for new block security_profile #28069

Merged
merged 5 commits into from
Dec 17, 2024

Conversation

liuwuliuyun
Copy link
Contributor

@liuwuliuyun liuwuliuyun commented Nov 19, 2024

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

For resource azurerm_batch_pool

  • support new block security_profile
  • add documentation for security_profile

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

image

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #27952

@liuwuliuyun liuwuliuyun requested review from katbyte and a team as code owners November 19, 2024 09:19
@liuwuliuyun liuwuliuyun changed the title azurerm_batch_pool - support new block security_profile azurerm_batch_pool - support for new block security_profile Nov 19, 2024
Copy link
Member

@catriona-m catriona-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @liuwuliuyun - I've had a look through and left some suggestions inline but once those are addressed I can take another look. Thanks!

internal/services/batch/batch_pool_resource_test.go Outdated Show resolved Hide resolved
internal/services/batch/batch_pool_resource_test.go Outdated Show resolved Hide resolved
@@ -740,6 +740,24 @@ func TestAccBatchPool_interNodeCommunicationWithTaskSchedulingPolicy(t *testing.
})
}

func TestAccBatchPool_securityProfileWithUEFISettings(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add additional steps to this test to test updating the properties in the block and to test adding/removing the block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I have just recalled that the security_profile can only be specified during creation and does not support updates. I will ensure this information is added to the documentation.

Copy link
Contributor Author

@liuwuliuyun liuwuliuyun Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus I will mark this block as forceNew

website/docs/r/batch_pool.html.markdown Outdated Show resolved Hide resolved
website/docs/r/batch_pool.html.markdown Outdated Show resolved Hide resolved
website/docs/r/batch_pool.html.markdown Outdated Show resolved Hide resolved
website/docs/r/batch_pool.html.markdown Outdated Show resolved Hide resolved
Comment on lines 1283 to 1296
if config.SecurityProfile != nil {
securityProfile := make([]interface{}, 0)
securityConfig := make(map[string]interface{})
securityConfig["host_encryption_enabled"] = pointer.ToBool(config.SecurityProfile.EncryptionAtHost)
if config.SecurityProfile.SecurityType != nil {
securityConfig["security_type"] = string(*config.SecurityProfile.SecurityType)
}
if config.SecurityProfile.UefiSettings != nil {
securityConfig["secure_boot_enabled"] = pointer.ToBool(config.SecurityProfile.UefiSettings.SecureBootEnabled)
securityConfig["vtpm_enabled"] = pointer.ToBool(config.SecurityProfile.UefiSettings.VTpmEnabled)
}
securityProfile = append(securityProfile, securityConfig)
d.Set("security_profile", securityProfile)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move this into a flatten func?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will do

@liuwuliuyun
Copy link
Contributor Author

liuwuliuyun commented Dec 10, 2024

New testing evidence:
image

Copy link
Member

@catriona-m catriona-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating this @liuwuliuyun - I left a couple more suggestions inline but can take another look after those are addressed. Thanks!

Comment on lines 418 to 420
if configProfile.EncryptionAtHost != nil {
securityConfig["host_encryption_enabled"] = *configProfile.EncryptionAtHost
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if configProfile.EncryptionAtHost != nil {
securityConfig["host_encryption_enabled"] = *configProfile.EncryptionAtHost
}
securityConfig["host_encryption_enabled"] = pointer.From(configProfile.EncryptionAtHost)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 422 to 424
if configProfile.SecurityType != nil {
securityConfig["security_type"] = string(*configProfile.SecurityType)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if configProfile.SecurityType != nil {
securityConfig["security_type"] = string(*configProfile.SecurityType)
}
securityConfig["security_type"] = pointer.From(*configProfile.SecurityType)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 427 to 429
if configProfile.UefiSettings.SecureBootEnabled != nil {
securityConfig["secure_boot_enabled"] = pointer.ToBool(configProfile.UefiSettings.SecureBootEnabled)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if configProfile.UefiSettings.SecureBootEnabled != nil {
securityConfig["secure_boot_enabled"] = pointer.ToBool(configProfile.UefiSettings.SecureBootEnabled)
}
securityConfig["secure_boot_enabled"] = pointer.From(configProfile.UefiSettings.SecureBootEnabled)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 430 to 432
if configProfile.UefiSettings.VTpmEnabled != nil {
securityConfig["vtpm_enabled"] = pointer.ToBool(configProfile.UefiSettings.VTpmEnabled)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if configProfile.UefiSettings.VTpmEnabled != nil {
securityConfig["vtpm_enabled"] = pointer.ToBool(configProfile.UefiSettings.VTpmEnabled)
}
securityConfig["vtpm_enabled"] = pointer.From(configProfile.UefiSettings.VTpmEnabled)

Copy link
Contributor Author

@liuwuliuyun liuwuliuyun Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

if v, ok := item["host_encryption_enabled"]; ok {
securityProfile.EncryptionAtHost = pointer.FromBool(v.(bool))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
securityProfile.EncryptionAtHost = pointer.FromBool(v.(bool))
securityProfile.EncryptionAtHost = pointer.To(v.(bool))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

if v, ok := item["secure_boot_enabled"]; ok {
securityProfile.UefiSettings.SecureBootEnabled = pointer.FromBool(v.(bool))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
securityProfile.UefiSettings.SecureBootEnabled = pointer.FromBool(v.(bool))
securityProfile.UefiSettings.SecureBootEnabled = pointer.To(v.(bool))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

if v, ok := item["vtpm_enabled"]; ok {
securityProfile.UefiSettings.VTpmEnabled = pointer.FromBool(v.(bool))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
securityProfile.UefiSettings.VTpmEnabled = pointer.FromBool(v.(bool))
securityProfile.UefiSettings.VTpmEnabled = pointer.To(v.(bool))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -165,6 +165,8 @@ The following arguments are supported:

* `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`.

* `security_profile` - (Optional) A `security_profile` block that describes the security settings for the Batch pool as defined below.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add here that Changing this forces a new resource to be created.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Comment on lines +510 to +516
* `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.

* `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.

* `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.

* `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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the properties within the block cannot be updated once it's been created as well, we should add ForceNew to these properties in the schema too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Copy link
Member

@catriona-m catriona-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @liuwuliuyun LGTM!

@catriona-m catriona-m merged commit ed20285 into hashicorp:main Dec 17, 2024
33 checks passed
@github-actions github-actions bot added this to the v4.15.0 milestone Dec 17, 2024
catriona-m added a commit that referenced this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for TrustedLaunch in "azurerm_batch_pool"
2 participants