Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
catch duplicate metadata resource
  • Loading branch information
mtojek committed Jul 5, 2023
commit 9e8f81c2b6da707cee4fa9c8646d18aacca67e8d
7 changes: 6 additions & 1 deletion provisioner/terraform/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
resourceIcon := map[string]string{}
resourceCost := map[string]int32{}

metadataTargetLabels := map[string]struct{}{}
for _, resources := range tfResourcesByLabel {
for _, resource := range resources {
if resource.Type != "coder_metadata" {
Expand All @@ -396,7 +397,6 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
if err != nil {
return nil, xerrors.Errorf("decode metadata attributes: %w", err)
}

resourceLabel := convertAddressToLabel(resource.Address)

var attachedNode *gographviz.Node
Expand Down Expand Up @@ -433,6 +433,11 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
}
targetLabel := attachedResource.Label

if _, ok := metadataTargetLabels[targetLabel]; ok {
return nil, xerrors.Errorf("duplicate metadata resource ID: %s", targetLabel)
}
metadataTargetLabels[targetLabel] = struct{}{}

resourceHidden[targetLabel] = attrs.Hide
resourceIcon[targetLabel] = attrs.Icon
resourceCost[targetLabel] = attrs.DailyCost
Expand Down