@@ -702,20 +702,21 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
702
702
if attrs .ResourceID != "" {
703
703
// Look for a resource with matching ID
704
704
foundLabels := labelsByResourceID [attrs .ResourceID ]
705
- if len (foundLabels ) == 1 {
705
+ switch len (foundLabels ) {
706
+ case 0 :
707
+ // If we couldn't find by ID, fall back to graph traversal
708
+ logger .Warn (ctx , "coder_metadata resource_id not found, falling back to graph traversal" ,
709
+ slog .F ("resource_id" , attrs .ResourceID ),
710
+ slog .F ("metadata_address" , resource .Address ))
711
+ case 1 :
706
712
// Single match - use it
707
713
targetLabel = foundLabels [0 ]
708
- } else if len ( foundLabels ) > 1 {
714
+ default :
709
715
// Multiple resources with same ID - this creates ambiguity
710
716
logger .Warn (ctx , "multiple resources found with same resource_id, falling back to graph traversal" ,
711
717
slog .F ("resource_id" , attrs .ResourceID ),
712
718
slog .F ("metadata_address" , resource .Address ),
713
719
slog .F ("matching_labels" , foundLabels ))
714
- } else {
715
- // If we couldn't find by ID, fall back to graph traversal
716
- logger .Warn (ctx , "coder_metadata resource_id not found, falling back to graph traversal" ,
717
- slog .F ("resource_id" , attrs .ResourceID ),
718
- slog .F ("metadata_address" , resource .Address ))
719
720
}
720
721
}
721
722
0 commit comments