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

support public_ips for resource azurerm_batch_pool #5967

Merged
merged 6 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azurerm/helpers/azure/batch_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package azure
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
)

// ExpandBatchAccountKeyVaultReference expands Batch account KeyVault reference
Expand Down
15 changes: 14 additions & 1 deletion azurerm/helpers/azure/batch_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"strings"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -571,6 +571,15 @@ func ExpandBatchPoolNetworkConfiguration(list []interface{}) (*batch.NetworkConf
}
}

if v, ok := networkConfigValue["public_ips"]; ok {
confPublicIPs := v.([]interface{})
publicIPs := make([]string, 0, len(confPublicIPs))
for _, publicIP := range confPublicIPs {
publicIPs = append(publicIPs, publicIP.(string))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think utils.ExplainStringArray() might work here?

networkConfiguration.PublicIPs = &publicIPs
}

if v, ok := networkConfigValue["endpoint_configuration"]; ok {
endpoint, err := ExpandBatchPoolEndpointConfiguration(v.([]interface{}))
if err != nil {
Expand Down Expand Up @@ -661,6 +670,10 @@ func FlattenBatchPoolNetworkConfiguration(networkConfig *batch.NetworkConfigurat
result["subnet_id"] = *networkConfig.SubnetID
}

if networkConfig.PublicIPs != nil {
result["public_ips"] = *networkConfig.PublicIPs
}

if cfg := networkConfig.EndpointConfiguration; cfg != nil && cfg.InboundNatPools != nil && len(*cfg.InboundNatPools) != 0 {
endpointConfigs := make([]interface{}, len(*cfg.InboundNatPools))

Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/batch/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"time"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"time"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down
11 changes: 10 additions & 1 deletion azurerm/internal/services/batch/resource_arm_batch_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -397,6 +397,14 @@ func resourceArmBatchPool() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"public_ips": {
Type: schema.TypeList,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably be a TypeSet

Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"endpoint_configuration": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -736,6 +744,7 @@ func resourceArmBatchPoolRead(d *schema.ResourceData, meta interface{}) error {

if props := resp.PoolProperties; props != nil {
d.Set("vm_size", props.VMSize)
d.Set("max_tasks_per_node", props.MaxTasksPerNode)

if scaleSettings := props.ScaleSettings; scaleSettings != nil {
if err := d.Set("auto_scale", azure.FlattenBatchPoolAutoScaleSettings(scaleSettings.AutoScale)); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,20 @@ func TestAccAzureRMBatchPool_frontEndPortRanges(t *testing.T) {
Config: testaccAzureRMBatchPool_networkConfiguration(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchPoolExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"),
resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"),
resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)),
resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"),
resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"),
resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "UbuntuServer"),
resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.#", "0"),
resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_dedicated_nodes", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "0"),
resource.TestCheckResourceAttr(data.ResourceName, "network_configuration.#", "1"),
resource.TestCheckResourceAttrSet(data.ResourceName, "network_configuration.0.subnet_id"),
resource.TestCheckResourceAttr(data.ResourceName, "network_configuration.0.public_ips.#", "1"),
),
},
data.ImportStep("stop_pending_resize_operation"),
Expand Down Expand Up @@ -1242,6 +1256,15 @@ resource "azurerm_subnet" "test" {
address_prefix = "10.0.2.0/24"
}

resource "azurerm_public_ip" "test" {
name = "acctestpublicip-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Static"
sku = "Standard"
domain_name_label = "acctest-publicip"
}

resource "azurerm_batch_account" "test" {
name = "testaccbatch%s"
resource_group_name = "${azurerm_resource_group.test.name}"
Expand All @@ -1267,7 +1290,8 @@ resource "azurerm_batch_pool" "test" {
}

network_configuration {
subnet_id = "${azurerm_subnet.test.id}"
subnet_id = "${azurerm_subnet.test.id}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we make this .12

Suggested change
subnet_id = "${azurerm_subnet.test.id}"
subnet_id = azurerm_subnet.test.id

public_ips = [azurerm_public_ip.test.id]

endpoint_configuration {
name = "SSH"
Expand All @@ -1283,5 +1307,5 @@ resource "azurerm_batch_pool" "test" {
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomString)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomString)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading