Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error on function _mount_resources due to non-iterable self.resources[source_resource]['values'] #554

Open
hjribeiro opened this issue Sep 9, 2021 · 4 comments
Assignees
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation

Comments

@hjribeiro
Copy link
Contributor

hjribeiro commented Sep 9, 2021

Description

terraform-compliance is failing on terraform_compliance/extensions/terraform.py#L321 with tf 1.0.6 and tf.10.5

To Reproduce

Plan File:
I'm working on cutting and anonymizing the plan file - will attach it soon

this is the resource that fails when looped over in the _mount_resources function:

{'address': 'module.tgw-dev.module.tgw-attach-accept.aws_ec2_transit_gateway_vpc_attachment_accepter.tgw_accept[0]', 'module_address': 'module.tgw-dev.module.tgw-attach-accept', 'mode': 'managed', 'type': 'aws_ec2_transit_gateway_vpc_attachment_accepter', 'name': 'tgw_accept', 'index': 0, 'provider_name': 'registry.terraform.io/hashicorp/aws', 'values': None, 'terraform-compliance.mounted_resources': {}, 'terraform-compliance.mounted_resources.addresses': {}, 'terraform-compliance.mounted_resources.addresses_list': []}

Running via Docker:
No
Error Output:
with version 1.3.27 we get this output:

  File "/Users/hribeiro/.pyenv/versions/3.8.11/lib/python3.8/site-packages/radish/hookregistry.py", line 132, in call
    func(model, *args, **kwargs)
  File "/Users/hribeiro/.pyenv/versions/3.8.11/lib/python3.8/site-packages/terraform_compliance/steps/terrain.py", line 11, in load_terraform_data
    world.config.terraform = TerraformParser(world.config.user_data['plan_file'])
  File "/Users/hribeiro/.pyenv/versions/3.8.11/lib/python3.8/site-packages/terraform_compliance/extensions/terraform.py", line 51, in __init__
    self.parse()
  File "/Users/hribeiro/.pyenv/versions/3.8.11/lib/python3.8/site-packages/terraform_compliance/extensions/terraform.py", line 543, in parse
    self._mount_references()
  File "/Users/hribeiro/.pyenv/versions/3.8.11/lib/python3.8/site-packages/terraform_compliance/extensions/terraform.py", line 495, in _mount_references
    self._mount_resources(source=source_resources,
  File "/Users/hribeiro/.pyenv/versions/3.8.11/lib/python3.8/site-packages/terraform_compliance/extensions/terraform.py", line 311, in _mount_resources
    if ref_type not in self.resources[target_resource]['values']:
TypeError: argument of type 'NoneType' is not iterable

with 1.3.26 the error output is different:

  File "/usr/local/lib/python3.9/site-packages/radish/hookregistry.py", line 132, in call
194    func(model, *args, **kwargs)
195  File "/usr/local/lib/python3.9/site-packages/terraform_compliance/steps/terrain.py", line 11, in load_terraform_data
196    world.config.terraform = TerraformParser(world.config.user_data['plan_file'])
197  File "/usr/local/lib/python3.9/site-packages/terraform_compliance/extensions/terraform.py", line 51, in __init__
198    self.parse()
199  File "/usr/local/lib/python3.9/site-packages/terraform_compliance/extensions/terraform.py", line 485, in parse
200    self._mount_references()
201  File "/usr/local/lib/python3.9/site-packages/terraform_compliance/extensions/terraform.py", line 419, in _mount_references
202    if type(value) is type(self.resources[t_r]['values'].get(key)) and self.resources[t_r]['values'].get(key) != value:
203AttributeError: 'NoneType' object has no attribute 'get'

Expected Behavior:
I'd expect the plan to pass compliance

Tested Versions:

  • terraform-compliance version: 1.3.27
  • terraform version: 1.0.6
  • python version: python 3.8.11

Additional Context:
I believe this is related to your recent bugfix .27 and to issues with terraform 1.0.6 and 1.0.5. Probably checking `if source_reource.get('values') would stop it from tripping. I'll have a play with the code as well.

@hjribeiro
Copy link
Contributor Author

I was able to fix it with the following change:

#556

if this seems reasonable I can add some unit tests and complete the PR.

thanks

@eerkunt
Copy link
Member

eerkunt commented Sep 13, 2021

hey @hjribeiro ,

Thanks for the issue and more importantly the PR! Good spot :)

Instead of unit tests, I think we can also add some functional tests for this to the PR with the currently plan you have.

@hjribeiro
Copy link
Contributor Author

hey @hjribeiro ,

Thanks for the issue and more importantly the PR! Good spot :)

Instead of unit tests, I think we can also add some functional tests for this to the PR with the currently plan you have.

PR updated with functional test. Give us a shout if you feel it needs anything else.

H

@eerkunt
Copy link
Member

eerkunt commented Sep 16, 2021

Thanks for the PR! Just released 1.3.28 including your PR in it.

@eerkunt eerkunt added the waiting for confirmation Workaround/Fix applied, waiting for confirmation label Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants