cli
cli copied to clipboard
TypeError: unhashable type: 'dict'
Description
Using terraform-compliance 1.3.21 and a terraform 1.0.2 plan file I get TypeError: unhashable type: 'dict' on a specific resource.
To Reproduce
- git checkout https://github.com/joaoubaldo/cli/tree/525-issue-demo
- cd demo-unhashable-dict
- (optional since planfile is in the path) terraform plan -out=planfile && terraform show -json planfile > planfile.json
- terraform-compliance -p planfile.json -f ./features
Sample Terraform Code: https://github.com/joaoubaldo/cli/tree/525-issue-demo/demo-unhashable-dict
Error Output:
Python exception (below) is thrown and features/scenarios/steps are not executed. I can apply the plan without issues. After debugging I found that
tags {
key = "kubernetes.io/cluster/${var.cluster_name}"
value = "owned"
}
is somehow causing tag['key'] to be a dict at this point https://github.com/terraform-compliance/cli/blob/master/terraform_compliance/extensions/terraform.py#L565

Exception:
! ERROR: Hook 'load_terraform_data' from /usr/local/lib/python3.8/dist-packages/terraform_compliance/steps/terrain.py:9 raised: 'TypeError: unhashable type: 'dict''
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/radish/hookregistry.py", line 132, in call
func(model, *args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/terraform_compliance/steps/terrain.py", line 11, in load_terraform_data
world.config.terraform = TerraformParser(world.config.user_data['plan_file'])
File "/usr/local/lib/python3.8/dist-packages/terraform_compliance/extensions/terraform.py", line 51, in __init__
self.parse()
File "/usr/local/lib/python3.8/dist-packages/terraform_compliance/extensions/terraform.py", line 505, in parse
self._expand_resource_tags(resource)
File "/usr/local/lib/python3.8/dist-packages/terraform_compliance/extensions/terraform.py", line 568, in _expand_resource_tags
tag[tag['key']] = tag['value']
TypeError: unhashable type: 'dict'
Expected Behavior:
I expected terraform-compliance not to fail/crash.
Tested Versions:
- terraform-compliance version:
terraform-compliance v1.3.21 - terraform version:
Terraform v1.0.2 on linux_amd64 - python version:
Python 3.8.10