Skip to content

Commit

Permalink
use createThenPoll; fix error message; fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Jul 11, 2024
1 parent 6e38eae commit 2214a62
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,12 @@ func (r StackHCILogicalNetworkResource) Create() sdk.ResourceFunc {
},
}

future, err := client.CreateOrUpdate(ctx, id, payload)
if err != nil {
if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil {
return fmt.Errorf("performing create %s: %+v", id, err)
}

metadata.SetID(id)

if err := future.Poller.PollUntilDone(ctx); err != nil {
return fmt.Errorf("polling after create %s: %+v", id, err)
}

return nil
},
}
Expand Down Expand Up @@ -332,7 +327,7 @@ func (r StackHCILogicalNetworkResource) Update() sdk.ResourceFunc {

parameters := resp.Model
if parameters == nil {
return fmt.Errorf("retrieving %s: model was nil", *id)
return fmt.Errorf("retrieving %s: `model` was nil", *id)
}

if metadata.ResourceData.HasChange("tags") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"os"
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2024-01-01/logicalnetworks"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

type StackHCILogicalNetworkResource struct{}
Expand All @@ -28,7 +27,7 @@ func TestAccStackHCILogicalNetwork_dynamic(t *testing.T) {
r := StackHCILogicalNetworkResource{}

if os.Getenv(customLocationIdEnv) == "" {
t.Skipf("skip the test as one or more of below environment variables are not specified: %q", customLocationIdEnv)
t.Skipf("skipping since %q has not been specified", customLocationIdEnv)
}

data.ResourceTest(t, r, []acceptance.TestStep{
Expand All @@ -47,7 +46,7 @@ func TestAccStackHCILogicalNetwork_update(t *testing.T) {
r := StackHCILogicalNetworkResource{}

if os.Getenv(customLocationIdEnv) == "" {
t.Skipf("skip the test as one or more of below environment variables are not specified: %q", customLocationIdEnv)
t.Skipf("skipping since %q has not been specified", customLocationIdEnv)
}

data.ResourceTest(t, r, []acceptance.TestStep{
Expand Down Expand Up @@ -121,14 +120,10 @@ func (r StackHCILogicalNetworkResource) Exists(ctx context.Context, client *clie

resp, err := clusterClient.Get(ctx, *id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return utils.Bool(false), nil
}

return nil, fmt.Errorf("retrieving %s: %+v", *id, err)
}

return utils.Bool(resp.Model != nil), nil
return pointer.To(resp.Model != nil), nil
}

func (r StackHCILogicalNetworkResource) dynamic(data acceptance.TestData) string {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/stack_hci_logical_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The following arguments are supported:

* `custom_location_id` - (Required) The ID of Custom Location where the Azure Stack HCI Logical Network should exist. Changing this forces a new resource to be created.

* `virtual_switch_name` - (Required) The name of the virtual switch on the cluster used to associate with the Azure Stack HCI Logical Network. Possible switch name can be retrieved following the [Azure documents](https://learn.microsoft.com/azure-stack/hci/manage/create-logical-networks?tabs=azurecli#prerequisites). Changing this forces a new resource to be created.
* `virtual_switch_name` - (Required) The name of the virtual switch on the cluster used to associate with the Azure Stack HCI Logical Network. Possible switch names can be retrieved by following this [Azure guide](https://learn.microsoft.com/azure-stack/hci/manage/create-logical-networks?tabs=azurecli#prerequisites). Changing this forces a new resource to be created.

* `subnet` - (Required) A `subnet` block as defined below. Changing this forces a new resource to be created.

Expand Down Expand Up @@ -93,7 +93,7 @@ A `subnet` block supports the following:

* `route` - (Optional) One or more `route` block as defined above. Changing this forces a new resource to be created.

* `vlan_id` - (Optional) VLAN ID for the Logical Network. Changing this forces a new resource to be created.
* `vlan_id` - (Optional) The VLAN ID for the Logical Network. Changing this forces a new resource to be created.

## Attributes Reference

Expand Down

0 comments on commit 2214a62

Please sign in to comment.