Skip to content
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
20 changes: 12 additions & 8 deletions internal/provider/resource_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,18 @@ func (r *repositoryResource) Update(ctx context.Context, req resource.UpdateRequ
return
}

// Update repository
sync.RepositoryMutex.Lock()
defer sync.RepositoryMutex.Unlock()
var updatedRepo *v1alpha1.Repository

updatedRepo, err := r.si.RepositoryClient.UpdateRepository(
ctx,
&repository.RepoUpdateRequest{Repo: repo},
)
func() {
// Keep mutex enclosed in a function to keep the lock scoped to it and to prevent deadlocking
sync.RepositoryMutex.Lock()
defer sync.RepositoryMutex.Unlock()

updatedRepo, err = r.si.RepositoryClient.UpdateRepository(
ctx,
&repository.RepoUpdateRequest{Repo: repo},
)
}()

if err != nil {
resp.Diagnostics.Append(diagnostics.ArgoCDAPIError("update", "repository", repo.Repo, err)...)
Expand All @@ -225,7 +229,7 @@ func (r *repositoryResource) Update(ctx context.Context, req resource.UpdateRequ
tflog.Trace(ctx, fmt.Sprintf("updated repository %s", updatedRepo.Repo))

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, data)...)
resp.Diagnostics.Append(resp.State.Set(ctx, data.updateFromAPI(updatedRepo))...)

// Perform a read to get the latest state
if !resp.Diagnostics.HasError() {
Expand Down
38 changes: 38 additions & 0 deletions internal/provider/resource_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -481,6 +482,43 @@ resource "argocd_repository" "boolean_fields" {
})
}

func TestAccArgoCDRepository_ProviderUpgradeStateMigration(t *testing.T) {
config := `
resource "argocd_repository" "private" {
count = 1
repo = "https://github.com/kubernetes-sigs/kustomize"
name = "gitlab-private"
type = "git"
}
`
resource.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"argocd": {
VersionConstraint: "7.8.0",
Source: "argoproj-labs/argocd",
},
},
Config: config,
},
{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Config: config,
},
{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Config: config,
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
},
},
})
}

// TestAccArgoCDRepository_EmptyStringFieldsConsistency tests handling of empty string fields
func TestAccArgoCDRepository_EmptyStringFieldsConsistency(t *testing.T) {
config := `
Expand Down