@@ -83,24 +83,33 @@ func resourceArgoCDRepositoryRead(ctx context.Context, d *schema.ResourceData, m
83
83
}
84
84
85
85
tokenMutexConfiguration .RLock ()
86
- r , err := si .RepositoryClient .Get (ctx , & repository.RepoQuery {
87
- Repo : d .Id (),
88
- AppProject : d .State ().Attributes ["project" ],
89
- ForceRefresh : true ,
90
- })
86
+ repos , err := si .RepositoryClient .List (ctx , & repository.RepoQuery {})
91
87
tokenMutexConfiguration .RUnlock ()
92
88
93
- if err != nil {
94
- // Repository has already been deleted in an out-of-band fashion
95
- if strings .Contains (err .Error (), "NotFound" ) {
96
- d .SetId ("" )
97
- return nil
89
+ var finalRepo * application.Repository
90
+
91
+ if repos != nil {
92
+ if len (repos .Items ) >= 1 {
93
+ for _ , repo := range repos .Items {
94
+ if repo .Repo == d .Id () {
95
+ finalRepo = repo
96
+ }
97
+ }
98
98
}
99
+ }
99
100
101
+ if finalRepo == nil {
102
+ // if finalRepo is empty this means that either there no repositories at all or the desired one isn't in the list
103
+ // that means we clear it from state and terraform will create it if desired
104
+ d .SetId ("" )
105
+ return nil
106
+ }
107
+
108
+ if err != nil {
100
109
return argoCDAPIError ("read" , "repository" , d .Id (), err )
101
110
}
102
111
103
- if err = flattenRepository (r , d ); err != nil {
112
+ if err = flattenRepository (finalRepo , d ); err != nil {
104
113
return errorToDiagnostics (fmt .Sprintf ("failed to flatten repository %s" , d .Id ()), err )
105
114
}
106
115
0 commit comments