@@ -89,7 +89,7 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
8989 }
9090 }
9191 c := * server .ApplicationClient
92- app , err := c .Get (ctx , & applicationClient.ApplicationQuery {
92+ apps , err := c .List (ctx , & applicationClient.ApplicationQuery {
9393 Name : & objectMeta .Name ,
9494 AppNamespace : & objectMeta .Namespace ,
9595 })
@@ -102,12 +102,22 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
102102 },
103103 }
104104 }
105- if app != nil {
106- switch app .DeletionTimestamp {
105+ if apps != nil {
106+ if len (apps .Items ) != 1 {
107+ return []diag.Diagnostic {
108+ {
109+ Severity : diag .Error ,
110+ Summary : fmt .Sprintf ("found multiple applications matching name '%s' and namespace '%s'" , objectMeta .Name , objectMeta .Namespace ),
111+ Detail : err .Error (),
112+ },
113+ }
114+ }
115+
116+ switch apps .Items [0 ].DeletionTimestamp {
107117 case nil :
108118 default :
109119 // Pre-existing app is still in Kubernetes soft deletion queue
110- time .Sleep (time .Duration (* app .DeletionGracePeriodSeconds ))
120+ time .Sleep (time .Duration (* apps . Items [ 0 ] .DeletionGracePeriodSeconds ))
111121 }
112122 }
113123
@@ -190,7 +200,7 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
190200 }
191201 }
192202
193- app , err = c .Create (ctx , & applicationClient.ApplicationCreateRequest {
203+ app , err : = c .Create (ctx , & applicationClient.ApplicationCreateRequest {
194204 Application : & application.Application {
195205 ObjectMeta : objectMeta ,
196206 Spec : spec ,
@@ -222,18 +232,21 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
222232
223233 if wait , ok := d .GetOk ("wait" ); ok && wait .(bool ) {
224234 err = resource .RetryContext (ctx , d .Timeout (schema .TimeoutCreate ), func () * resource.RetryError {
225- a , err := c .Get (ctx , & applicationClient.ApplicationQuery {
235+ list , err := c .List (ctx , & applicationClient.ApplicationQuery {
226236 Name : & app .Name ,
227237 AppNamespace : & app .Namespace ,
228238 })
229239 if err != nil {
230240 return resource .NonRetryableError (fmt .Errorf ("error while waiting for application %s to be synced and healthy: %s" , app .Name , err ))
231241 }
232- if a .Status .Health .Status != health .HealthStatusHealthy {
233- return resource .RetryableError (fmt .Errorf ("expected application health status to be healthy but was %s" , a .Status .Health .Status ))
242+ if len (list .Items ) != 1 {
243+ return resource .NonRetryableError (fmt .Errorf ("found multiple applications matching name '%s' and namespace '%s'" , app .Name , app .Namespace ))
244+ }
245+ if list .Items [0 ].Status .Health .Status != health .HealthStatusHealthy {
246+ return resource .RetryableError (fmt .Errorf ("expected application health status to be healthy but was %s" , list .Items [0 ].Status .Health .Status ))
234247 }
235- if a .Status .Sync .Status != application .SyncStatusCodeSynced {
236- return resource .RetryableError (fmt .Errorf ("expected application sync status to be synced but was %s" , a .Status .Sync .Status ))
248+ if list . Items [ 0 ] .Status .Sync .Status != application .SyncStatusCodeSynced {
249+ return resource .RetryableError (fmt .Errorf ("expected application sync status to be synced but was %s" , list . Items [ 0 ] .Status .Sync .Status ))
237250 }
238251 return nil
239252 })
@@ -268,7 +281,7 @@ func resourceArgoCDApplicationRead(ctx context.Context, d *schema.ResourceData,
268281 appName := ids [0 ]
269282 namespace := ids [1 ]
270283
271- app , err := c .Get (ctx , & applicationClient.ApplicationQuery {
284+ apps , err := c .List (ctx , & applicationClient.ApplicationQuery {
272285 Name : & appName ,
273286 AppNamespace : & namespace ,
274287 })
@@ -285,7 +298,16 @@ func resourceArgoCDApplicationRead(ctx context.Context, d *schema.ResourceData,
285298 },
286299 }
287300 }
288- err = flattenApplication (app , d )
301+ if len (apps .Items ) != 1 {
302+ return []diag.Diagnostic {
303+ {
304+ Severity : diag .Error ,
305+ Summary : fmt .Sprintf ("found multiple applications matching name '%s' and namespace '%s'" , appName , namespace ),
306+ Detail : err .Error (),
307+ },
308+ }
309+ }
310+ err = flattenApplication (& apps .Items [0 ], d )
289311 if err != nil {
290312 return []diag.Diagnostic {
291313 {
@@ -407,11 +429,11 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
407429 }
408430 }
409431 }
410- app , err := c .Get (ctx , & applicationClient.ApplicationQuery {
432+ apps , err := c .List (ctx , & applicationClient.ApplicationQuery {
411433 Name : & appName ,
412434 AppNamespace : & namespace ,
413435 })
414- if app != nil {
436+ if apps != nil {
415437 // Kubernetes API requires providing the up-to-date correct ResourceVersion for updates
416438 // FIXME ResourceVersion not available anymore
417439 // appRequest.ResourceVersion = app.ResourceVersion
@@ -428,18 +450,21 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
428450 }
429451 if wait , _ok := d .GetOk ("wait" ); _ok && wait .(bool ) {
430452 err = resource .RetryContext (ctx , d .Timeout (schema .TimeoutUpdate ), func () * resource.RetryError {
431- a , err := c .Get (ctx , & applicationClient.ApplicationQuery {
432- Name : & app . Name ,
433- AppNamespace : & app . Namespace ,
453+ list , err := c .List (ctx , & applicationClient.ApplicationQuery {
454+ Name : & appName ,
455+ AppNamespace : & namespace ,
434456 })
435457 if err != nil {
436- return resource .NonRetryableError (fmt .Errorf ("error while waiting for application %s to be synced and healthy: %s" , app .Name , err ))
458+ return resource .NonRetryableError (fmt .Errorf ("error while waiting for application %s to be synced and healthy: %s" , list .Items [0 ].Name , err ))
459+ }
460+ if len (list .Items ) != 1 {
461+ return resource .NonRetryableError (fmt .Errorf ("found multiple applications matching name '%s' and namespace '%s'" , appName , namespace ))
437462 }
438- if a .Status .Health .Status != health .HealthStatusHealthy {
439- return resource .RetryableError (fmt .Errorf ("expected application health status to be healthy but was %s" , a .Status .Health .Status ))
463+ if list . Items [ 0 ] .Status .Health .Status != health .HealthStatusHealthy {
464+ return resource .RetryableError (fmt .Errorf ("expected application health status to be healthy but was %s" , list . Items [ 0 ] .Status .Health .Status ))
440465 }
441- if a .Status .Sync .Status != application .SyncStatusCodeSynced {
442- return resource .RetryableError (fmt .Errorf ("expected application sync status to be synced but was %s" , a .Status .Sync .Status ))
466+ if list . Items [ 0 ] .Status .Sync .Status != application .SyncStatusCodeSynced {
467+ return resource .RetryableError (fmt .Errorf ("expected application sync status to be synced but was %s" , list . Items [ 0 ] .Status .Sync .Status ))
443468 }
444469 return nil
445470 })
@@ -489,7 +514,7 @@ func resourceArgoCDApplicationDelete(ctx context.Context, d *schema.ResourceData
489514 }
490515 if wait , ok := d .GetOk ("wait" ); ok && wait .(bool ) {
491516 err = resource .RetryContext (ctx , d .Timeout (schema .TimeoutDelete ), func () * resource.RetryError {
492- _ , err := c .Get (ctx , & applicationClient.ApplicationQuery {
517+ _ , err := c .List (ctx , & applicationClient.ApplicationQuery {
493518 Name : & appName ,
494519 AppNamespace : & namespace ,
495520 })
0 commit comments