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_express_route_port_authorization: add a lock when create/update/delete authorization of express route port #21959

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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