tofu will only report resources in the root of the terraform state tree.
The problem is in L111: this assumes there is no terraform module being used except for the main, root definition.
Instead of hardcoded value of 0, self.data.modules should iterated because the length can be n.
An example from a more complex terraform infra using modules:
>>> len(data['modules'])
8
>>> filter( lambda x : re.search('openstack_compute_instance_v2', x), data['modules'][0]['resources'].keys() )
[]
>>> filter( lambda x : re.search('openstack_compute_instance_v2', x), data['modules'][1]['resources'].keys() )
[]
>>> filter( lambda x : re.search('openstack_compute_instance_v2', x), data['modules'][2]['resources'].keys() )
[]
>>> filter( lambda x : re.search('openstack_compute_instance_v2', x), data['modules'][3]['resources'].keys() )
[]
>>> filter( lambda x : re.search('openstack_compute_instance_v2', x), data['modules'][4]['resources'].keys() )
[]
>>> filter( lambda x : re.search('openstack_compute_instance_v2', x), data['modules'][5]['resources'].keys() )
[u'openstack_compute_instance_v2.vm_2n.0', u'openstack_compute_instance_v2.vm_2n.1', u'openstack_compute_instance_v2.vm_2n.2']
>>> filter( lambda x : re.search('openstack_compute_instance_v2', x), data['modules'][6]['resources'].keys() )
[u'openstack_compute_instance_v2.vm_2n.0', u'openstack_compute_instance_v2.vm_2n.1', u'openstack_compute_instance_v2.vm_2n.2']
>>> filter( lambda x : re.search('openstack_compute_instance_v2', x), data['modules'][7]['resources'].keys() )
[u'openstack_compute_instance_v2.instance']
This is because in this tf infra there is no vm being built in the root, but only using modules.
tofuwill only report resources in therootof the terraform state tree.The problem is in L111: this assumes there is no terraform module being used except for the main, root definition.
Instead of hardcoded value of
0,self.data.modulesshould iterated because the length can ben.An example from a more complex terraform infra using modules:
This is because in this tf infra there is no vm being built in the root, but only using modules.