Skip to content

Commit

Permalink
handle absent resources upon deletion, argocd_repository: force refre…
Browse files Browse the repository at this point in the history
…sh repo connection cache upon reads (#33)
  • Loading branch information
oboukili authored Oct 13, 2020
1 parent 9a69a0f commit 0b6ede0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion argocd/resource_argocd_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func resourceArgoCDApplicationDelete(d *schema.ResourceData, meta interface{}) e
c := *server.ApplicationClient
appName := d.Id()
_, err := c.Delete(context.Background(), &applicationClient.ApplicationDeleteRequest{Name: &appName})
if err != nil {
if err != nil && !strings.Contains(err.Error(), "NotFound") {
return err
}
d.SetId("")
Expand Down
2 changes: 1 addition & 1 deletion argocd/resource_argocd_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func resourceArgoCDProjectDelete(d *schema.ResourceData, meta interface{}) error
_, err := c.Delete(context.Background(), &projectClient.ProjectQuery{Name: projectName})
tokenMutexProjectMap[projectName].Unlock()

if err != nil {
if err != nil && !strings.Contains(err.Error(), "NotFound") {
return err
}
d.SetId("")
Expand Down
13 changes: 10 additions & 3 deletions argocd/resource_argocd_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func resourceArgoCDRepositoryRead(d *schema.ResourceData, meta interface{}) erro
tokenMutexConfiguration.RLock()
r, err = c.Get(context.Background(), &repository.RepoQuery{
Repo: d.Id(),
ForceRefresh: false,
ForceRefresh: true,
})
tokenMutexConfiguration.RUnlock()

Expand All @@ -89,7 +89,7 @@ func resourceArgoCDRepositoryRead(d *schema.ResourceData, meta interface{}) erro
tokenMutexConfiguration.RLock()
rl, err := c.ListRepositories(context.Background(), &repository.RepoQuery{
Repo: d.Id(),
ForceRefresh: false,
ForceRefresh: true,
})
tokenMutexConfiguration.RUnlock()

Expand Down Expand Up @@ -165,7 +165,14 @@ func resourceArgoCDRepositoryDelete(d *schema.ResourceData, meta interface{}) er
tokenMutexConfiguration.Unlock()

if err != nil {
return err
switch strings.Contains(err.Error(), "NotFound") {
// Repository has already been deleted in an out-of-band fashion
case true:
d.SetId("")
return nil
default:
return err
}
}
d.SetId("")
return nil
Expand Down
9 changes: 8 additions & 1 deletion argocd/resource_argocd_repository_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ func resourceArgoCDRepositoryCredentialsDelete(d *schema.ResourceData, meta inte
tokenMutexConfiguration.Unlock()

if err != nil {
return err
switch strings.Contains(err.Error(), "NotFound") {
// Repository credentials have already been deleted in an out-of-band fashion
case true:
d.SetId("")
return nil
default:
return err
}
}
d.SetId("")
return nil
Expand Down

0 comments on commit 0b6ede0

Please sign in to comment.