Skip to content

Commit

Permalink
Merge pull request #13718 from magodo/batch_sdk_update
Browse files Browse the repository at this point in the history
Update sdk version for batch from 2020-03-01 to 2021-06-01
  • Loading branch information
stephybun authored Oct 13, 2021
2 parents e0946c0 + e57f4c0 commit bbddf0e
Show file tree
Hide file tree
Showing 28 changed files with 2,016 additions and 994 deletions.
2 changes: 1 addition & 1 deletion internal/services/batch/batch_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package batch
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2020-03-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2021-06-01/batch"
)

// expandBatchAccountKeyVaultReference expands Batch account KeyVault reference
Expand Down
6 changes: 3 additions & 3 deletions internal/services/batch/batch_account_data_source.go
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/2020-03-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2021-06-01/batch"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/batch/validate"
Expand Down Expand Up @@ -106,7 +106,7 @@ func dataSourceBatchAccountRead(d *pluginsdk.ResourceData, meta interface{}) err
d.Set("pool_allocation_mode", props.PoolAllocationMode)
poolAllocationMode := d.Get("pool_allocation_mode").(string)

if poolAllocationMode == string(batch.BatchService) {
if poolAllocationMode == string(batch.PoolAllocationModeBatchService) {
keys, err := client.GetKeys(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Cannot read keys for Batch account %q (resource group %q): %v", name, resourceGroup, err)
Expand All @@ -117,7 +117,7 @@ func dataSourceBatchAccountRead(d *pluginsdk.ResourceData, meta interface{}) err

// set empty keyvault reference which is not needed in Batch Service allocation mode.
d.Set("key_vault_reference", []interface{}{})
} else if poolAllocationMode == string(batch.UserSubscription) {
} else if poolAllocationMode == string(batch.PoolAllocationModeUserSubscription) {
if err := d.Set("key_vault_reference", flattenBatchAccountKeyvaultReference(props.KeyVaultReference)); err != nil {
return fmt.Errorf("flattening `key_vault_reference`: %+v", err)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/services/batch/batch_account_resource.go
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/2020-03-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2021-06-01/batch"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down Expand Up @@ -62,10 +62,10 @@ func resourceBatchAccount() *pluginsdk.Resource {
"pool_allocation_mode": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(batch.BatchService),
Default: string(batch.PoolAllocationModeBatchService),
ValidateFunc: validation.StringInSlice([]string{
string(batch.BatchService),
string(batch.UserSubscription),
string(batch.PoolAllocationModeBatchService),
string(batch.PoolAllocationModeUserSubscription),
}, false),
},

Expand Down Expand Up @@ -158,7 +158,7 @@ func resourceBatchAccountCreate(d *pluginsdk.ResourceData, meta interface{}) err
}

// if pool allocation mode is UserSubscription, a key vault reference needs to be set
if poolAllocationMode == string(batch.UserSubscription) {
if poolAllocationMode == string(batch.PoolAllocationModeUserSubscription) {
keyVaultReferenceSet := d.Get("key_vault_reference").([]interface{})
keyVaultReference, err := expandBatchAccountKeyVaultReference(keyVaultReferenceSet)
if err != nil {
Expand Down Expand Up @@ -241,7 +241,7 @@ func resourceBatchAccountRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("pool_allocation_mode", props.PoolAllocationMode)
}

if d.Get("pool_allocation_mode").(string) == string(batch.BatchService) {
if d.Get("pool_allocation_mode").(string) == string(batch.PoolAllocationModeBatchService) {
keys, err := client.GetKeys(ctx, id.ResourceGroup, id.BatchAccountName)
if err != nil {
return fmt.Errorf("Cannot read keys for Batch account %q (resource group %q): %v", id.BatchAccountName, id.ResourceGroup, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/batch/batch_application_resource.go
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/2020-03-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2021-06-01/batch"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
12 changes: 4 additions & 8 deletions internal/services/batch/batch_certificate_resource.go
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/2020-03-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2021-06-01/batch"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down Expand Up @@ -66,8 +66,8 @@ func resourceBatchCertificate() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(batch.Cer),
string(batch.Pfx),
string(batch.CertificateFormatCer),
string(batch.CertificateFormatPfx),
}, false),
},

Expand Down Expand Up @@ -146,15 +146,11 @@ func resourceBatchCertificateCreate(d *pluginsdk.ResourceData, meta interface{})
CertificateCreateOrUpdateProperties: &certificateProperties,
}

future, err := client.Create(ctx, resourceGroupName, accountName, name, parameters, "", "")
_, err := client.Create(ctx, resourceGroupName, accountName, name, parameters, "", "")
if err != nil {
return fmt.Errorf("creating Batch certificate %q (Account %q / Resource Group %q): %+v", name, accountName, resourceGroupName, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for creation of Batch certificate %q (Account %q / Resource Group %q): %+v", name, accountName, resourceGroupName, err)
}

read, err := client.Get(ctx, resourceGroupName, accountName, name)
if err != nil {
return fmt.Errorf("retrieving Batch certificate %q (Account %q / Resource Group %q): %+v", name, accountName, resourceGroupName, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/batch/batch_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
"strings"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2020-03-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2021-06-01/batch"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/batch/batch_pool_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func dataSourceBatchPoolRead(d *pluginsdk.ResourceData, meta interface{}) error

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

if scaleSettings := props.ScaleSettings; scaleSettings != nil {
if err := d.Set("auto_scale", flattenBatchPoolAutoScaleSettings(scaleSettings.AutoScale)); err != nil {
Expand Down
44 changes: 20 additions & 24 deletions internal/services/batch/batch_pool_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2020-03-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2021-06-01/batch"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down Expand Up @@ -336,10 +336,10 @@ func resourceBatchPool() *pluginsdk.Resource {
"elevation_level": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(batch.NonAdmin),
Default: string(batch.ElevationLevelNonAdmin),
ValidateFunc: validation.StringInSlice([]string{
string(batch.NonAdmin),
string(batch.Admin),
string(batch.ElevationLevelNonAdmin),
string(batch.ElevationLevelAdmin),
}, false),
},
"scope": {
Expand Down Expand Up @@ -429,9 +429,9 @@ func resourceBatchPool() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(batch.BatchManaged),
string(batch.UserManaged),
string(batch.NoPublicIPAddresses),
string(batch.IPAddressProvisioningTypeBatchManaged),
string(batch.IPAddressProvisioningTypeUserManaged),
string(batch.IPAddressProvisioningTypeNoPublicIPAddresses),
}, false),
},
"endpoint_configuration": {
Expand All @@ -451,8 +451,8 @@ func resourceBatchPool() *pluginsdk.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(batch.TCP),
string(batch.UDP),
string(batch.InboundEndpointProtocolTCP),
string(batch.InboundEndpointProtocolUDP),
}, false),
},
"backend_port": {
Expand Down Expand Up @@ -487,8 +487,8 @@ func resourceBatchPool() *pluginsdk.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(batch.Allow),
string(batch.Deny),
string(batch.NetworkSecurityGroupRuleAccessAllow),
string(batch.NetworkSecurityGroupRuleAccessDeny),
}, false),
},
"source_address_prefix": {
Expand Down Expand Up @@ -539,9 +539,9 @@ func resourceBatchPoolCreate(d *pluginsdk.ResourceData, meta interface{}) error

parameters := batch.Pool{
PoolProperties: &batch.PoolProperties{
VMSize: &vmSize,
DisplayName: &displayName,
MaxTasksPerNode: &maxTasksPerNode,
VMSize: &vmSize,
DisplayName: &displayName,
TaskSlotsPerNode: &maxTasksPerNode,
},
}

Expand Down Expand Up @@ -621,15 +621,11 @@ func resourceBatchPoolCreate(d *pluginsdk.ResourceData, meta interface{}) error
return fmt.Errorf("expanding `network_configuration`: %+v", err)
}

future, err := client.Create(ctx, resourceGroup, accountName, poolName, parameters, "", "")
_, err = client.Create(ctx, resourceGroup, accountName, poolName, parameters, "", "")
if err != nil {
return fmt.Errorf("creating Batch pool %q (Resource Group %q): %+v", poolName, resourceGroup, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for creation of Batch pool %q (Resource Group %q): %+v", poolName, resourceGroup, err)
}

read, err := client.Get(ctx, resourceGroup, accountName, poolName)
if err != nil {
return fmt.Errorf("retrieving Batch pool %q (Resource Group %q): %+v", poolName, resourceGroup, err)
Expand All @@ -642,7 +638,7 @@ func resourceBatchPoolCreate(d *pluginsdk.ResourceData, meta interface{}) error
d.SetId(*read.ID)

// if the pool is not Steady after the create operation, wait for it to be Steady
if props := read.PoolProperties; props != nil && props.AllocationState != batch.Steady {
if props := read.PoolProperties; props != nil && props.AllocationState != batch.AllocationStateSteady {
if err = waitForBatchPoolPendingResizeOperation(ctx, client, resourceGroup, accountName, poolName); err != nil {
return fmt.Errorf("waiting for Batch pool %q (resource group %q) being ready", poolName, resourceGroup)
}
Expand All @@ -666,7 +662,7 @@ func resourceBatchPoolUpdate(d *pluginsdk.ResourceData, meta interface{}) error
return fmt.Errorf("retrieving the Batch pool %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

if resp.PoolProperties.AllocationState != batch.Steady {
if resp.PoolProperties.AllocationState != batch.AllocationStateSteady {
log.Printf("[INFO] there is a pending resize operation on this pool...")
stopPendingResizeOperation := d.Get("stop_pending_resize_operation").(bool)
if !stopPendingResizeOperation {
Expand Down Expand Up @@ -735,7 +731,7 @@ func resourceBatchPoolUpdate(d *pluginsdk.ResourceData, meta interface{}) error
}

// if the pool is not Steady after the update, wait for it to be Steady
if props := result.PoolProperties; props != nil && props.AllocationState != batch.Steady {
if props := result.PoolProperties; props != nil && props.AllocationState != batch.AllocationStateSteady {
if err := waitForBatchPoolPendingResizeOperation(ctx, client, id.ResourceGroup, id.BatchAccountName, id.Name); err != nil {
return fmt.Errorf("waiting for Batch pool %q (resource group %q) being ready", id.Name, id.ResourceGroup)
}
Expand Down Expand Up @@ -779,7 +775,7 @@ func resourceBatchPoolRead(d *pluginsdk.ResourceData, meta interface{}) error {
}
}

d.Set("max_tasks_per_node", props.MaxTasksPerNode)
d.Set("max_tasks_per_node", props.TaskSlotsPerNode)

if props.DeploymentConfiguration != nil &&
props.DeploymentConfiguration.VirtualMachineConfiguration != nil &&
Expand Down Expand Up @@ -895,7 +891,7 @@ func waitForBatchPoolPendingResizeOperation(ctx context.Context, client *batch.P
return fmt.Errorf("retrieving the Batch pool %q (Resource Group %q): %+v", poolName, resourceGroup, err)
}

isSteady = resp.PoolProperties.AllocationState == batch.Steady
isSteady = resp.PoolProperties.AllocationState == batch.AllocationStateSteady
time.Sleep(time.Second * 30)
log.Printf("[INFO] waiting for the pending resize operation on this pool to be stopped... New try in 30 seconds...")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/services/batch/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

batchDataplane "github.com/Azure/azure-sdk-for-go/services/batch/2020-03-01.11.0/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2020-03-01/batch"
"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2021-06-01/batch"
"github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/batch/parse"
Expand Down

This file was deleted.

Loading

0 comments on commit bbddf0e

Please sign in to comment.