code: func marshalModules(
  	s *states.State,
  	schemas *terraform.Schemas,
  	modules []addrs.ModuleInstance,
  	moduleMap map[string][]addrs.ModuleInstance,
  ) ([]module, error) {
  	var ret []module
  	for _, child := range modules {
  		stateMod := s.Module(child)
  		// cm for child module, naming things is hard.
  		cm := module{Address: stateMod.Addr.String()}
  		rs, err := marshalResources(stateMod.Resources, schemas)
  		if err != nil {
  			return nil, err
  		}
  		cm.Resources = rs
  		if moduleMap[child.String()] != nil {
  			moreChildModules, err := marshalModules(s, schemas, moduleMap[child.String()], moduleMap)
  			if err != nil {
  				return nil, err
  			}
  			cm.ChildModules = moreChildModules
  		}
  
  		ret = append(ret, cm)
  	}
  
  	return ret, nil
  }
docs: // marshalModules is an ungainly recursive function to build a module
  // structure out of a teraform state.