Skip to content

Commit

Permalink
Add mutex to tenant variable to fix concurrent issue (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuyPhanNguyen authored Sep 12, 2024
1 parent 359e287 commit bc07af6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions octopusdeploy_framework/resource_tenant_project_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package octopusdeploy_framework
import (
"context"
"fmt"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
Expand Down Expand Up @@ -51,6 +52,8 @@ func (t *tenantProjectVariableResource) Configure(_ context.Context, req resourc
}

func (t *tenantProjectVariableResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
internal.Mutex.Lock()
defer internal.Mutex.Unlock()
var plan tenantProjectVariableResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
Expand Down Expand Up @@ -101,6 +104,9 @@ func (t *tenantProjectVariableResource) Create(ctx context.Context, req resource
}

func (t *tenantProjectVariableResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
internal.Mutex.Lock()
defer internal.Mutex.Unlock()

var state tenantProjectVariableResourceModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
Expand Down Expand Up @@ -141,6 +147,9 @@ func (t *tenantProjectVariableResource) Read(ctx context.Context, req resource.R
}

func (t *tenantProjectVariableResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
internal.Mutex.Lock()
defer internal.Mutex.Unlock()

var plan tenantProjectVariableResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
Expand Down Expand Up @@ -180,6 +189,9 @@ func (t *tenantProjectVariableResource) Update(ctx context.Context, req resource
}

func (t *tenantProjectVariableResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
internal.Mutex.Lock()
defer internal.Mutex.Unlock()

var state tenantProjectVariableResourceModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
Expand Down

0 comments on commit bc07af6

Please sign in to comment.