MCPcopy
hub / github.com/Azure/aztfexport / ListResource

Method ListResource

internal/meta/meta_res.go:70–155  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

68}
69
70func (meta *MetaResource) ListResource(ctx context.Context) (ImportList, error) {
71 var rl []resourceset.AzureResource
72 for _, id := range meta.AzureIds {
73 rl = append(rl, resourceset.AzureResource{Id: id})
74 }
75
76 rl, err := meta.listByIds(ctx, rl)
77 if err != nil {
78 return nil, fmt.Errorf("listing resources: %v", err)
79 }
80
81 meta.Logger().Debug("Azure Resource set map to TF resource set")
82 rset := &resourceset.AzureResourceSet{Resources: rl}
83 var tfl []resourceset.TFResource
84 if meta.useAzAPI() {
85 tfl = rset.ToTFAzAPIResources()
86 } else {
87 tfl = rset.ToTFAzureRMResources(meta.Logger(), meta.parallelism, meta.azureSDKCred, meta.azureSDKClientOpt)
88 }
89
90 // Split the specified resources and the extension resources
91 var tfrl, tfel []resourceset.TFResource
92 for _, tfres := range tfl {
93 rmap := map[string]bool{}
94 for _, r := range rl {
95 rmap[r.Id.String()] = true
96 }
97 if rmap[tfres.AzureId.String()] {
98 tfrl = append(tfrl, tfres)
99 } else {
100 tfel = append(tfel, tfres)
101 }
102 }
103
104 var l ImportList
105
106 // The ResourceName and ResourceType are only honored for single non-role-assignment-resource
107 if len(tfrl) == 1 {
108 res := tfrl[0]
109
110 // Honor the ResourceName
111 name := meta.ResourceName
112 if name == "" {
113 name = fmt.Sprintf("%s%d%s", meta.resourceNamePrefix, 0, meta.resourceNameSuffix)
114 }
115
116 // Honor the ResourceType
117 tftype := res.TFType
118 tfid := res.TFId
119 if meta.ResourceType != "" && meta.ResourceType != res.TFType {
120 // res.TFType can be either empty (if aztft failed to query), or not.
121 // If the user has specified a different type, then use it.
122 tftype = meta.ResourceType
123
124 // Also use this resource type to requery its resource id.
125 var err error
126 tfid, err = aztft.QueryId(res.AzureId.String(), meta.ResourceType,
127 &aztft.APIOption{

Callers

nothing calls this directly

Calls 8

listByIdsMethod · 0.95
ToTFAzAPIResourcesMethod · 0.95
ToTFAzureRMResourcesMethod · 0.95
toImportListMethod · 0.95
useAzAPIMethod · 0.80
excludeImportListMethod · 0.80
LoggerMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected