Skip to content

Commit 04175c6

Browse files
authored
Fix error inconsistent result after apply on argocd_repository_credentials (#243)
1 parent b211553 commit 04175c6

File tree

5 files changed

+28
-30
lines changed

5 files changed

+28
-30
lines changed

argocd/resource_argocd_cluster.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,12 @@ func resourceArgoCDClusterUpdate(ctx context.Context, d *schema.ResourceData, me
265265
tokenMutexClusters.Unlock()
266266

267267
if err != nil {
268-
if strings.Contains(err.Error(), "NotFound") {
269-
d.SetId("")
270-
return nil
271-
} else {
272-
return []diag.Diagnostic{
273-
{
274-
Severity: diag.Error,
275-
Summary: fmt.Sprintf("something went wrong during cluster update: %s", err),
276-
Detail: err.Error(),
277-
},
278-
}
268+
return []diag.Diagnostic{
269+
{
270+
Severity: diag.Error,
271+
Summary: fmt.Sprintf("something went wrong during cluster update: %s", err),
272+
Detail: err.Error(),
273+
},
279274
}
280275
}
281276
return resourceArgoCDClusterRead(ctx, d, meta)

argocd/resource_argocd_repository.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,6 @@ func resourceArgoCDRepositoryUpdate(ctx context.Context, d *schema.ResourceData,
262262
tokenMutexConfiguration.Unlock()
263263

264264
if err != nil {
265-
if strings.Contains(err.Error(), "NotFound") {
266-
// Repository has already been deleted in an out-of-band fashion
267-
d.SetId("")
268-
return nil
269-
}
270265
return []diag.Diagnostic{
271266
{
272267
Severity: diag.Error,

argocd/resource_argocd_repository_credentials.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func resourceArgoCDRepositoryCredentialsRead(ctx context.Context, d *schema.Reso
104104
},
105105
}
106106
}
107-
if rcl == nil {
107+
if rcl == nil || len(rcl.Items) == 0 {
108108
// Repository credentials have already been deleted in an out-of-band fashion
109109
d.SetId("")
110110
return nil
@@ -155,18 +155,12 @@ func resourceArgoCDRepositoryCredentialsUpdate(ctx context.Context, d *schema.Re
155155
tokenMutexConfiguration.Unlock()
156156

157157
if err != nil {
158-
if strings.Contains(err.Error(), "NotFound") {
159-
// Repository credentials have already been deleted in an out-of-band fashion
160-
d.SetId("")
161-
return nil
162-
} else {
163-
return []diag.Diagnostic{
164-
{
165-
Severity: diag.Error,
166-
Summary: fmt.Sprintf("credentials for repository %s could not be updated", repoCreds.URL),
167-
Detail: err.Error(),
168-
},
169-
}
158+
return []diag.Diagnostic{
159+
{
160+
Severity: diag.Error,
161+
Summary: fmt.Sprintf("credentials for repository %s could not be updated", repoCreds.URL),
162+
Detail: err.Error(),
163+
},
170164
}
171165
}
172166
d.SetId(r.URL)

argocd/resource_argocd_repository_credentials_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func TestAccArgoCDRepositoryCredentials(t *testing.T) {
2222
Steps: []resource.TestStep{
2323
{
2424
Config: testAccArgoCDRepositoryCredentialsSimple(
25+
"https://github.com/oboukili/terraform-provider-argocd",
26+
),
27+
},
28+
{
29+
Config: testAccArgoCDRepositoryCredentialsSSH(
2530
"https://private-git-repository.argocd.svc.cluster.local/project-1.git",
2631
"git",
2732
sshPrivateKey,
@@ -89,7 +94,15 @@ func TestAccArgoCDRepositoryCredentials_GitHubApp(t *testing.T) {
8994
})
9095
}
9196

92-
func testAccArgoCDRepositoryCredentialsSimple(repoUrl, username, sshPrivateKey string) string {
97+
func testAccArgoCDRepositoryCredentialsSimple(repoUrl string) string {
98+
return fmt.Sprintf(`
99+
resource "argocd_repository_credentials" "simple" {
100+
url = "%s"
101+
}
102+
`, repoUrl)
103+
}
104+
105+
func testAccArgoCDRepositoryCredentialsSSH(repoUrl, username, sshPrivateKey string) string {
93106
return fmt.Sprintf(`
94107
resource "argocd_repository_credentials" "simple" {
95108
url = "%s"

argocd/schema_repository_credentials.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func repositoryCredentialsSchema() map[string]*schema.Schema {
1010
Type: schema.TypeString,
1111
Description: "URL that these credentials matches to.",
1212
Required: true,
13+
ForceNew: true,
1314
},
1415
"username": {
1516
Type: schema.TypeString,

0 commit comments

Comments
 (0)