MCPcopy
hub / github.com/im2nguyen/rover / PopulateModuleState

Method PopulateModuleState

rso.go:156–261  ·  view source on GitHub ↗
(rso *ResourcesOverview, module *tfjson.StateModule, prior bool)

Source from the content-addressed store, hash-verified

154}
155
156func (r *rover) PopulateModuleState(rso *ResourcesOverview, module *tfjson.StateModule, prior bool) {
157 childIndex := regexp.MustCompile(`\[[^[\]]*\]$`)
158
159 rs := rso.States
160
161 // Loop through each resource type and populate states
162 for _, rst := range module.Resources {
163 id := rst.Address
164 parent := module.Address
165 //fmt.Printf("ID: %v\n", id)
166 if rst.AttributeValues != nil {
167
168 // Add resource to parent
169 // Create resource if doesn't exist
170 if _, ok := rs[id]; !ok {
171 rs[id] = &StateOverview{}
172 if rst.Mode == "data" {
173 rs[id].Type = ResourceTypeData
174 } else {
175 rs[id].Type = ResourceTypeResource
176 }
177 }
178
179 if _, ok := rs[parent]; !ok {
180 rs[parent] = &StateOverview{}
181 rs[parent].Type = ResourceTypeModule
182 rs[parent].IsParent = false
183 rs[parent].Children = make(map[string]*StateOverview)
184 }
185
186 // Check if resource has parent
187 // part of, resource w/ count or for_each
188 if childIndex.MatchString(id) {
189 parent = childIndex.ReplaceAllString(id, "")
190 // If resource has parent, create parent if doesn't exist
191 if _, ok := rs[parent]; !ok {
192 rs[parent] = &StateOverview{}
193 rs[parent].Children = make(map[string]*StateOverview)
194 if rst.Mode == "data" {
195 rs[parent].Type = ResourceTypeData
196 } else {
197 rs[parent].Type = ResourceTypeResource
198 }
199
200 }
201
202 rs[module.Address].Children[parent] = rs[parent]
203
204 }
205
206 //fmt.Printf("%v - %v\n", id, parent)
207 rs[parent].Children[id] = rs[id]
208
209 if prior {
210 rs[id].Change.Before = rst.AttributeValues
211 } else {
212 rs[id].Change.After = rst.AttributeValues
213 }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected