Skip to content

Commit 3d92225

Browse files
sreyaThomasK33
authored andcommitted
handle duplicate TF IDs
1 parent cfb02c7 commit 3d92225

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

provisioner/terraform/resources.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
209209
tfResourcesByLabel := map[string]map[string]*tfjson.StateResource{}
210210

211211
// Map resource IDs to labels for efficient lookup when processing metadata
212-
labelByResourceID := map[string]string{}
212+
// Multiple resources can have the same ID, so we store a slice of labels
213+
labelsByResourceID := map[string][]string{}
213214

214215
// Extra array to preserve the order of rich parameters.
215216
tfResourcesRichParameters := make([]*tfjson.StateResource, 0)
@@ -237,10 +238,10 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
237238
}
238239
tfResourcesByLabel[label][resource.Address] = resource
239240

240-
// Build the ID to label map
241+
// Build the ID to labels map - multiple resources can have the same ID
241242
if idAttr, hasID := resource.AttributeValues["id"]; hasID {
242243
if idStr, ok := idAttr.(string); ok && idStr != "" {
243-
labelByResourceID[idStr] = label
244+
labelsByResourceID[idStr] = append(labelsByResourceID[idStr], label)
244245
}
245246
}
246247
}
@@ -700,9 +701,16 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
700701
// First, check if ResourceID is provided and try to find the resource by ID
701702
if attrs.ResourceID != "" {
702703
// Look for a resource with matching ID
703-
foundLabel, foundByID := labelByResourceID[attrs.ResourceID]
704-
if foundByID {
705-
targetLabel = foundLabel
704+
foundLabels := labelsByResourceID[attrs.ResourceID]
705+
if len(foundLabels) == 1 {
706+
// Single match - use it
707+
targetLabel = foundLabels[0]
708+
} else if len(foundLabels) > 1 {
709+
// Multiple resources with same ID - this creates ambiguity
710+
logger.Warn(ctx, "multiple resources found with same resource_id, falling back to graph traversal",
711+
slog.F("resource_id", attrs.ResourceID),
712+
slog.F("metadata_address", resource.Address),
713+
slog.F("matching_labels", foundLabels))
706714
} else {
707715
// If we couldn't find by ID, fall back to graph traversal
708716
logger.Warn(ctx, "coder_metadata resource_id not found, falling back to graph traversal",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy