Skip to content

Commit

Permalink
azurerm_express_route_port_authorization: add a lock when create/up…
Browse files Browse the repository at this point in the history
…date/delete authorization of express route port (#21959)
  • Loading branch information
wuxu92 authored Jun 1, 2023
1 parent f6b8856 commit 506445c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -85,6 +86,11 @@ func resourceExpressRoutePortAuthorizationCreate(d *pluginsdk.ResourceData, meta
ExpressRoutePortAuthorizationPropertiesFormat: &network.ExpressRoutePortAuthorizationPropertiesFormat{},
}

// can run only one create/update/delete operation of expressRoutePort at the same time
portID := parse.NewExpressRoutePortID(id.SubscriptionId, id.ResourceGroup, id.ExpressRoutePortName)
locks.ByID(portID.ID())
defer locks.UnlockByID(portID.ID())

future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.ExpressRoutePortName, id.AuthorizationName, properties)
if err != nil {
return fmt.Errorf("Creating/Updating %s: %+v", id, err)
Expand Down Expand Up @@ -140,6 +146,10 @@ func resourceExpressRoutePortAuthorizationDelete(d *pluginsdk.ResourceData, meta
return err
}

portID := parse.NewExpressRoutePortID(id.SubscriptionId, id.ResourceGroup, id.ExpressRoutePortName)
locks.ByID(portID.ID())
defer locks.UnlockByID(portID.ID())

future, err := client.Delete(ctx, id.ResourceGroup, id.ExpressRoutePortName, id.AuthorizationName)
if err != nil {
return fmt.Errorf("deleting %s: %+v", *id, err)
Expand Down
9 changes: 9 additions & 0 deletions internal/services/network/express_route_port_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
Expand Down Expand Up @@ -227,6 +228,10 @@ func resourceArmExpressRoutePortCreateUpdate(d *pluginsdk.ResourceData, meta int
param.ExpressRoutePortPropertiesFormat.BillingType = network.ExpressRoutePortsBillingType(v.(string))
}

// a lock is needed here for subresource express_route_port_authorization needs a lock.
locks.ByID(id.ID())
defer locks.UnlockByID(id.ID())

// The link properties can't be specified in first creation. It will result into either error (e.g. setting `adminState`) or being ignored (e.g. setting MACSec)
// Hence, if this is a new creation we will do a create-then-update here.
if d.IsNewResource() {
Expand Down Expand Up @@ -320,6 +325,10 @@ func resourceArmExpressRoutePortDelete(d *pluginsdk.ResourceData, meta interface
return err
}

// a lock is needed here for subresource express_route_port_authorization needs a lock.
locks.ByID(id.ID())
defer locks.UnlockByID(id.ID())

future, err := client.Delete(ctx, id.ResourceGroup, id.Name)
if err != nil {
return fmt.Errorf("deleting Express Route Port %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
Expand Down

0 comments on commit 506445c

Please sign in to comment.