[GH-ISSUE #59] Unhandled error: <class 'TypeError'>, unsupported operand type(s) for |: 'dict' and 'dict', <traceback object at 0x7fd145a77f80> #25

Closed
opened 2026-05-06 12:36:21 +02:00 by BreizhHardware · 12 comments

Originally created by @ViktorUJ on GitHub (Sep 23, 2023).
Original GitHub issue: https://github.com/patrickchugh/terravision/issues/59

I try terravision draw --source https://github.com/ViktorUJ/cks//terraform/modules/vpc

terravision draw --source https://github.com/ViktorUJ/cks//terraform/modules/vpc


/__ ___ _ __ _ __ __ ___ ()() ___ _ __
/ // _ \ '
| '/ ` \ \ / / / _| |/ _ | '
/ / | __/ | | | | (
| |\ V /| __ \ | (_) | | | |
/ _
|| || _,| _/ ||/|__/|| ||

Preflight check..
dot command detected: /usr/bin/dot
gvpr command detected: /usr/bin/gvpr
git command detected: /usr/bin/git
Loading Sources..
Downloading External Module: https://github.com/ViktorUJ/cks//terraform/modules/vpc
Cloning from Terraform registry source: https://github.com/ViktorUJ/cks
Added Source Location: https://github.com/ViktorUJ/cks//terraform/modules/vpc
Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/locals.tf
Found 1 locals stanza(s)
Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/vpc.tf
Found 2 resource stanza(s)
Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/subnet.tf
Found 1 resource stanza(s)
Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/route_table.tf
Found 2 resource stanza(s)
Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/providers.tf
Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/output.tf
Found 5 output stanza(s)
Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/var.tf
Found 7 variable stanza(s)
Processing Variables..
var.region
var.az_ids
var.vpc_default_cidr
var.aws
var.prefix
var.app_name
var.tags_common
aws_vpc.default
aws_internet_gateway.default
aws_subnet.subnets_pub
aws_route_table.pub
aws_route_table_association.pub

Locals list :
/main: item_id
/main: subnets_az
/main: subnets_az_cmdb
/main: tags_app
/main: tags_all

Module list :

Resource list :
vpc/vpc.tf: aws_vpc.default
vpc/vpc.tf: aws_internet_gateway.default
vpc/subnet.tf: aws_subnet.subnets_pub
vpc/route_table.tf: aws_route_table.pub
vpc/route_table.tf: aws_route_table_association.pub

Data list :

Variable List:

Module: main
  var.region =
  var.az_ids =
  var.vpc_default_cidr =
  var.aws =
  var.prefix =
  var.app_name =
  var.tags_common =
  var.variable = [{'region': {}}, {'az_ids': {'type': '${map(string)}'}}, {'vpc_default_cidr': {}}, {'aws': {}}, {'prefix': {}}, {'app_name': {}}, {'tags_common': {'type': '${map(string)}'}}]

Conditional Resource List:

Computing Relations between 5 out of 5 resources...
aws_vpc.default --> aws_internet_gateway.default (Reversed)
aws_vpc.default --> aws_subnet.subnets_pub (Reversed)
aws_vpc.default --> aws_route_table.pub (Reversed)
aws_route_table.pub --> aws_internet_gateway.default
aws_subnet.subnets_pub --> aws_route_table_association.pub (Reversed)
aws_route_table_association.pub --> aws_route_table.pub
aws_subnet.subnets_pub --> aws_route_table_association.pub (Reversed)

Unprocessed Graph Dictionary:
{
"aws_internet_gateway.default": [],
"aws_route_table.pub": [
"aws_internet_gateway.default"
],
"aws_route_table_association.pub": [
"aws_route_table.pub"
],
"aws_subnet.subnets_pub": [
"aws_route_table_association.pub"
],
"aws_vpc.default": [
"aws_internet_gateway.default",
"aws_subnet.subnets_pub",
"aws_route_table.pub"
]
}
Unhandled error: <class 'TypeError'>, unsupported operand type(s) for |: 'dict' and 'dict', <traceback object at 0x7f2416a270c0>

Originally created by @ViktorUJ on GitHub (Sep 23, 2023). Original GitHub issue: https://github.com/patrickchugh/terravision/issues/59 I try terravision draw --source https://github.com/ViktorUJ/cks//terraform/modules/vpc terravision draw --source https://github.com/ViktorUJ/cks//terraform/modules/vpc _____ _ _ /__ \___ _ __ _ __ __ ___ _(_)___(_) ___ _ __ / /\/ _ \ '__| '__/ _` \ \ / / / __| |/ _ \| '_ \ / / | __/ | | | | (_| |\ V /| \__ \ | (_) | | | | \/ \___|_| |_| \__,_| \_/ |_|___/_|\___/|_| |_| Preflight check.. dot command detected: /usr/bin/dot gvpr command detected: /usr/bin/gvpr git command detected: /usr/bin/git Loading Sources.. Downloading External Module: https://github.com/ViktorUJ/cks//terraform/modules/vpc Cloning from Terraform registry source: https://github.com/ViktorUJ/cks Added Source Location: https://github.com/ViktorUJ/cks//terraform/modules/vpc Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/locals.tf Found 1 locals stanza(s) Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/vpc.tf Found 2 resource stanza(s) Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/subnet.tf Found 1 resource stanza(s) Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/route_table.tf Found 2 resource stanza(s) Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/providers.tf Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/output.tf Found 5 output stanza(s) Parsing /root/.terravision/module_cache/https_//github.com/ViktorUJ/cks//terraform/modules/vpc;main;/terraform/modules/vpc/var.tf Found 7 variable stanza(s) Processing Variables.. var.region var.az_ids var.vpc_default_cidr var.aws var.prefix var.app_name var.tags_common aws_vpc.default aws_internet_gateway.default aws_subnet.subnets_pub aws_route_table.pub aws_route_table_association.pub Locals list : /main: item_id /main: subnets_az /main: subnets_az_cmdb /main: tags_app /main: tags_all Module list : Resource list : vpc/vpc.tf: aws_vpc.default vpc/vpc.tf: aws_internet_gateway.default vpc/subnet.tf: aws_subnet.subnets_pub vpc/route_table.tf: aws_route_table.pub vpc/route_table.tf: aws_route_table_association.pub Data list : Variable List: Module: main var.region = var.az_ids = var.vpc_default_cidr = var.aws = var.prefix = var.app_name = var.tags_common = var.variable = [{'region': {}}, {'az_ids': {'type': '${map(string)}'}}, {'vpc_default_cidr': {}}, {'aws': {}}, {'prefix': {}}, {'app_name': {}}, {'tags_common': {'type': '${map(string)}'}}] Conditional Resource List: Computing Relations between 5 out of 5 resources... aws_vpc.default --> aws_internet_gateway.default (Reversed) aws_vpc.default --> aws_subnet.subnets_pub (Reversed) aws_vpc.default --> aws_route_table.pub (Reversed) aws_route_table.pub --> aws_internet_gateway.default aws_subnet.subnets_pub --> aws_route_table_association.pub (Reversed) aws_route_table_association.pub --> aws_route_table.pub aws_subnet.subnets_pub --> aws_route_table_association.pub (Reversed) Unprocessed Graph Dictionary: { "aws_internet_gateway.default": [], "aws_route_table.pub": [ "aws_internet_gateway.default" ], "aws_route_table_association.pub": [ "aws_route_table.pub" ], "aws_subnet.subnets_pub": [ "aws_route_table_association.pub" ], "aws_vpc.default": [ "aws_internet_gateway.default", "aws_subnet.subnets_pub", "aws_route_table.pub" ] } Unhandled error: <class 'TypeError'>, unsupported operand type(s) for |: 'dict' and 'dict', <traceback object at 0x7f2416a270c0>
Author
Owner

@patrickchugh commented on GitHub (Oct 3, 2023):

I will be releasing a significant update that uses the Terraform binary - please test again with that once released.

<!-- gh-comment-id:1744723469 --> @patrickchugh commented on GitHub (Oct 3, 2023): I will be releasing a significant update that uses the Terraform binary - please test again with that once released.
Author
Owner

@patrickchugh commented on GitHub (Nov 21, 2023):

@ViktorUJ Hello, thank you for your feedback and thanks for testing out Terravision and helping to make this a better product. I have recently completed a major revamp to the code which uses the terraform binary to download source files and generate initial relationships, before augmenting it with source code parsing as before. This is a significant departure from the previous approach and whilst slower, ensures a more accurate output and will handle all terraform in built functions now when encountered in the source. Please do a git pull and re-test again with the latest source code. If your problem is resolved, please close the the thread in github issues and mark it as completed. If not, please give as much detail as you can about the errors and include any source files if possible so I can reproduce your issue. Once again, thanks for helping and look forward to hearing from you soon.

P.

<!-- gh-comment-id:1820022595 --> @patrickchugh commented on GitHub (Nov 21, 2023): @ViktorUJ Hello, thank you for your feedback and thanks for testing out Terravision and helping to make this a better product. I have recently completed a major revamp to the code which uses the terraform binary to download source files and generate initial relationships, before augmenting it with source code parsing as before. This is a significant departure from the previous approach and whilst slower, ensures a more accurate output and will handle all terraform in built functions now when encountered in the source. Please do a git pull and re-test again with the latest source code. If your problem is resolved, please close the the thread in github issues and mark it as completed. If not, please give as much detail as you can about the errors and include any source files if possible so I can reproduce your issue. Once again, thanks for helping and look forward to hearing from you soon. P.
Author
Owner

@patrickchugh commented on GitHub (Dec 28, 2023):

Closing since no feedback

<!-- gh-comment-id:1871522439 --> @patrickchugh commented on GitHub (Dec 28, 2023): Closing since no feedback
Author
Owner

@haisumriaz-tkxel commented on GitHub (Apr 3, 2024):

Hi This issue is still there as of April 3, 2024. i recently cloned the repo, and followed the instructions to setup terravision, but its still here. im using the Main branch. please let me know how i can troubleshoot this
image

<!-- gh-comment-id:2034286761 --> @haisumriaz-tkxel commented on GitHub (Apr 3, 2024): Hi This issue is still there as of April 3, 2024. i recently cloned the repo, and followed the instructions to setup terravision, but its still here. im using the Main branch. please let me know how i can troubleshoot this ![image](https://github.com/patrickchugh/terravision/assets/112874448/abbe0c58-3181-4663-816d-319ac4529e1d)
Author
Owner

@patrickchugh commented on GitHub (Apr 3, 2024):

Is it possible to share the terraform source so I can try to reproduce? @haisumriaz-tkxel

<!-- gh-comment-id:2034344470 --> @patrickchugh commented on GitHub (Apr 3, 2024): Is it possible to share the terraform source so I can try to reproduce? @haisumriaz-tkxel
Author
Owner

@haisumriaz-tkxel commented on GitHub (Apr 3, 2024):

Sure. let me know if im doing something wrong.

Here is the Structure!
terraform/

├── main.tf
├── variables.tf
├── outputs.tf

└── modules/
├── vpc/
│ ├── main.tf
│ ├── variables.tf
│ └── outputs.tf

├── subnets/
│ ├── main.tf
│ ├── variables.tf
│ └── outputs.tf

├── igw/
│ ├── main.tf
│ └── outputs.tf

├── ec2_instance/
│ ├── main.tf
│ ├── variables.tf
│ └── outputs.tf

└── security_group/
├── main.tf
├── variables.tf
└── outputs.tf

Main.tf (root)

module "vpc" {
source = "./modules/vpc"
cidr_block = var.vpc_cidr
}

module "subnets" {
source = "./modules/subnets"
vpc_id = module.vpc.vpc_id
public_cidr = var.public_subnet_cidr
private_cidr = var.private_subnet_cidr
}

module "igw" {
source = "./modules/igw"
vpc_id = module.vpc.vpc_id
}

module "security_groups" {
source = "./modules/security_groups"
security_group_name_prefix = "example"
vpc_id = module.vpc.vpc_id
public_subnet_cidr = var.public_subnet_cidr # Ensure this is defined in your variables
}

module "ec2_instance_public" {
source = "./modules/ec2_instance"
ami_id = "ami-080e1f13689e07408" # Replace with actual AMI ID
subnet_id = module.subnets.public_subnet_id
vpc_security_group_ids = [module.security_groups.public_sg_id]
}

module "ec2_instance_private" {
source = "./modules/ec2_instance"
ami_id = "ami-080e1f13689e07408" # Replace with actual AMI ID
subnet_id = module.subnets.private_subnet_id
vpc_security_group_ids = [module.security_groups.private_sg_id]
}

variables.tf

variable "vpc_cidr" {
description = "The CIDR block for the VPC"
default = "10.0.0.0/16"
}

variable "public_subnet_cidr" {
description = "The CIDR block for the public subnet"
default = "10.0.1.0/24"
}

variable "private_subnet_cidr" {
description = "The CIDR block for the private subnet"
default = "10.0.2.0/24"
}

<!-- gh-comment-id:2034379684 --> @haisumriaz-tkxel commented on GitHub (Apr 3, 2024): Sure. let me know if im doing something wrong. Here is the Structure! terraform/ │ ├── main.tf ├── variables.tf ├── outputs.tf │ └── modules/ ├── vpc/ │ ├── main.tf │ ├── variables.tf │ └── outputs.tf │ ├── subnets/ │ ├── main.tf │ ├── variables.tf │ └── outputs.tf │ ├── igw/ │ ├── main.tf │ └── outputs.tf │ ├── ec2_instance/ │ ├── main.tf │ ├── variables.tf │ └── outputs.tf │ └── security_group/ ├── main.tf ├── variables.tf └── outputs.tf Main.tf (root) ---------------------------------------------------------------------------- module "vpc" { source = "./modules/vpc" cidr_block = var.vpc_cidr } module "subnets" { source = "./modules/subnets" vpc_id = module.vpc.vpc_id public_cidr = var.public_subnet_cidr private_cidr = var.private_subnet_cidr } module "igw" { source = "./modules/igw" vpc_id = module.vpc.vpc_id } module "security_groups" { source = "./modules/security_groups" security_group_name_prefix = "example" vpc_id = module.vpc.vpc_id public_subnet_cidr = var.public_subnet_cidr # Ensure this is defined in your variables } module "ec2_instance_public" { source = "./modules/ec2_instance" ami_id = "ami-080e1f13689e07408" # Replace with actual AMI ID subnet_id = module.subnets.public_subnet_id vpc_security_group_ids = [module.security_groups.public_sg_id] } module "ec2_instance_private" { source = "./modules/ec2_instance" ami_id = "ami-080e1f13689e07408" # Replace with actual AMI ID subnet_id = module.subnets.private_subnet_id vpc_security_group_ids = [module.security_groups.private_sg_id] } variables.tf ------------------------------------------------------------------------------------------------ variable "vpc_cidr" { description = "The CIDR block for the VPC" default = "10.0.0.0/16" } variable "public_subnet_cidr" { description = "The CIDR block for the public subnet" default = "10.0.1.0/24" } variable "private_subnet_cidr" { description = "The CIDR block for the private subnet" default = "10.0.2.0/24" }
Author
Owner

@haisumriaz-tkxel commented on GitHub (Apr 3, 2024):

Terraform-Example.zip

here is the complete code that i am using. let me know if i should upload this to some repo or is it ok.

<!-- gh-comment-id:2034381997 --> @haisumriaz-tkxel commented on GitHub (Apr 3, 2024): [Terraform-Example.zip](https://github.com/patrickchugh/terravision/files/14851715/Terraform-Example.zip) here is the complete code that i am using. let me know if i should upload this to some repo or is it ok.
Author
Owner

@ly-richlockney commented on GitHub (Apr 4, 2024):

What version of Python are you using? I got that error when I attempted with Python 3.8.10. After upgrading to 3.9, I was able to move past that. I mean, I ran into a different error afterward, but it's progress.

<!-- gh-comment-id:2037774464 --> @ly-richlockney commented on GitHub (Apr 4, 2024): What version of Python are you using? I got that error when I attempted with Python 3.8.10. After upgrading to 3.9, I was able to move past that. I mean, I ran into a different error afterward, but it's progress.
Author
Owner

@haisumriaz-tkxel commented on GitHub (Apr 4, 2024):

I currently have 3.8.10 installed. let me try upgrading it. Please share what error did you run into so i can compare if its the same or something else.

<!-- gh-comment-id:2037887677 --> @haisumriaz-tkxel commented on GitHub (Apr 4, 2024): I currently have 3.8.10 installed. let me try upgrading it. Please share what error did you run into so i can compare if its the same or something else.
Author
Owner

@ly-richlockney commented on GitHub (Apr 4, 2024):

The application progresses through most of my plan, and then when it hits a stage labeled "Checking for additional links between X resources..", it steps through a number of aws_ resources and ends with:

"Unhandled error: <class 'KeyError'>, 'count', <traceback object at 0x7f696363e580>"

Note: I initially received a similar KeyError with regard to EFS volumes, so I commented out the EFS section in terravision/modules/cloud_config.py. Just to see if it was just hanging up on that one resource.

This, BTW is on Ubuntu 20 via WSL, with Python 3.9.

Other note: I am not very proficient at this at all. I just happened across the same issue that you did, but managed to get past it.

<!-- gh-comment-id:2037948888 --> @ly-richlockney commented on GitHub (Apr 4, 2024): The application progresses through most of my plan, and then when it hits a stage labeled "Checking for additional links between X resources..", it steps through a number of aws_ resources and ends with: "Unhandled error: <class 'KeyError'>, 'count', <traceback object at 0x7f696363e580>" Note: I initially received a similar KeyError with regard to EFS volumes, so I commented out the EFS section in terravision/modules/cloud_config.py. Just to see if it was just hanging up on that one resource. This, BTW is on Ubuntu 20 via WSL, with Python 3.9. Other note: I am not very proficient at this at all. I just happened across the same issue that you did, but managed to get past it.
Author
Owner

@haisumriaz-tkxel commented on GitHub (Apr 9, 2024):

@ly-richlockney i also managed to get past that by upgrading python version. facing this same new error, seems like there is another ticket that was open for this newer error.
@patrickchugh can we have a look at that one instead? this one was resolved using python 3.10.13 on ubuntu 20.04 LTS

<!-- gh-comment-id:2044591626 --> @haisumriaz-tkxel commented on GitHub (Apr 9, 2024): @ly-richlockney i also managed to get past that by upgrading python version. facing this same new error, seems like there is another ticket that was open for this newer error. @patrickchugh can we have a look at that one instead? this one was resolved using python 3.10.13 on ubuntu 20.04 LTS
Author
Owner

@patrickchugh commented on GitHub (May 11, 2024):

Thanks for the bug report. Can you confirm if this still exists with the latest release pushed just now?

<!-- gh-comment-id:2106029292 --> @patrickchugh commented on GitHub (May 11, 2024): Thanks for the bug report. Can you confirm if this still exists with the latest release pushed just now?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/terravision#25
No description provided.