From bc07af685d18dc101989107658cfc363dc38d962 Mon Sep 17 00:00:00 2001 From: Huy Nguyen <162080607+HuyPhanNguyen@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:25:48 +1000 Subject: [PATCH] Add mutex to tenant variable to fix concurrent issue (#780) --- .../resource_tenant_project_variable.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/octopusdeploy_framework/resource_tenant_project_variable.go b/octopusdeploy_framework/resource_tenant_project_variable.go index 65d5e8261..39a8957ce 100644 --- a/octopusdeploy_framework/resource_tenant_project_variable.go +++ b/octopusdeploy_framework/resource_tenant_project_variable.go @@ -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" @@ -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() { @@ -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() { @@ -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() { @@ -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() {