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 - add new property accelerated_networking_enabled #23160

Merged
merged 5 commits into from Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/services/batch/batch_pool.go
Expand Up @@ -1114,6 +1114,10 @@ func ExpandBatchPoolNetworkConfiguration(list []interface{}) (*pool.NetworkConfi
networkConfiguration.DynamicVnetAssignmentScope = pointer.To(pool.DynamicVNetAssignmentScope(v.(string)))
}

if v, ok := networkConfigValue["accelerated_networking_enabled"]; ok {
networkConfiguration.EnableAcceleratedNetworking = pointer.FromBool(v.(bool))
}

if v, ok := networkConfigValue["subnet_id"]; ok {
if value := v.(string); value != "" {
networkConfiguration.SubnetId = &value
Expand Down Expand Up @@ -1308,9 +1312,15 @@ func flattenBatchPoolNetworkConfiguration(input *pool.NetworkConfiguration) []in
dynamicVNetAssignmentScope = string(*input.DynamicVnetAssignmentScope)
}

acceleratedNetworkingEnabled := false
if input.EnableAcceleratedNetworking != nil && *input.EnableAcceleratedNetworking {
acceleratedNetworkingEnabled = true
}
Copy link
Member

Choose a reason for hiding this comment

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

Since it defaults to false we can use the pointer.From function further down and get rid of this

Suggested change
acceleratedNetworkingEnabled := false
if input.EnableAcceleratedNetworking != nil && *input.EnableAcceleratedNetworking {
acceleratedNetworkingEnabled = true
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed


return []interface{}{
map[string]interface{}{
"dynamic_vnet_assignment_scope": dynamicVNetAssignmentScope,
"accelerated_networking_enabled": acceleratedNetworkingEnabled,
liuwuliuyun marked this conversation as resolved.
Show resolved Hide resolved
"endpoint_configuration": endpointConfigs,
"public_address_provisioning_type": publicAddressProvisioningType,
"public_ips": pluginsdk.NewSet(pluginsdk.HashString, publicIPAddressIds),
Expand Down
4 changes: 4 additions & 0 deletions internal/services/batch/batch_pool_data_source.go
Expand Up @@ -478,6 +478,10 @@ func dataSourceBatchPool() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Computed: true,
},
"accelerated_networking_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},
"subnet_id": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down
8 changes: 7 additions & 1 deletion internal/services/batch/batch_pool_resource.go
Expand Up @@ -463,9 +463,15 @@ func resourceBatchPool() *pluginsdk.Resource {
string(pool.DynamicVNetAssignmentScopeJob),
}, false),
},
"accelerated_networking_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
"subnet_id": {
Type: pluginsdk.TypeString,
Required: true,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
Expand Down
58 changes: 58 additions & 0 deletions internal/services/batch/batch_pool_resource_test.go
Expand Up @@ -44,6 +44,22 @@ func TestAccBatchPool_basic(t *testing.T) {
})
}

func TestAccBatchPool_acceleratedNetworkingEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test")
r := BatchPoolResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.acceleratedNetworkingEnabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("network_configuration.0.accelerated_networking_enabled").HasValue("true"),
),
},
data.ImportStep("stop_pending_resize_operation"),
})
}

func TestAccBatchPool_identity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test")
r := BatchPoolResource{}
Expand Down Expand Up @@ -995,6 +1011,48 @@ resource "azurerm_batch_pool" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString)
}

func (BatchPoolResource) acceleratedNetworkingEnabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-batch-%d"
location = "%s"
}

resource "azurerm_batch_account" "test" {
name = "testaccbatch%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}

resource "azurerm_batch_pool" "test" {
name = "testaccpool%s"
resource_group_name = azurerm_resource_group.test.name
account_name = azurerm_batch_account.test.name
node_agent_sku_id = "batch.node.windows amd64"
vm_size = "Standard_D1_v2"

fixed_scale {
target_dedicated_nodes = 2
}

storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-datacenter-smalldisk"
version = "latest"
}

network_configuration {
accelerated_networking_enabled = true
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString)
}

func (BatchPoolResource) identity(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/batch_pool.html.markdown
Expand Up @@ -458,10 +458,12 @@ A `nfs_mount` block supports the following:

A `network_configuration` block supports the following:

* `subnet_id` - (Required) The ARM resource identifier of the virtual network subnet which the compute nodes of the pool will join. Changing this forces a new resource to be created.
* `subnet_id` - (Optional) The ARM resource identifier of the virtual network subnet which the compute nodes of the pool will join. Changing this forces a new resource to be created.

* `dynamic_vnet_assignment_scope` - (Optional) The scope of dynamic vnet assignment. Allowed values: `none`, `job`. Changing this forces a new resource to be created.

* `accelerated_networking_enabled` - (Optional) Whether to enable accelerated networking. Possible values are `true` and `false`. Defaults to `false`. Changing this forces a new resource to be created.

* `public_ips` - (Optional) A list of public IP ids that will be allocated to nodes. Changing this forces a new resource to be created.

* `endpoint_configuration` - (Optional) A list of inbound NAT pools that can be used to address specific ports on an individual compute node externally. Set as documented in the inbound_nat_pools block below. Changing this forces a new resource to be created.
Expand Down