[GH-ISSUE #112] Unhandled error: <class 'KeyError'>, 'aws_subnet.private[1a]', <traceback object at 0xffffb06148c0> #59

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

Originally created by @jonbutland on GitHub (Mar 19, 2024).
Original GitHub issue: https://github.com/patrickchugh/terravision/issues/112

The variable,

subnets = {
    "1a" = {
      "public_cidr": "x.x.x.x/24"
      "private_cidr": "x.x.x.x/24"
      "az": "us-east-1a"
    }
    "1b" = {
      "public_cidr": "x.x.x.x/24"
      "private_cidr": "x.x.x.x/24"
      "az": "us-east-1b"
    }
    "1c" = {
      "public_cidr": "x.x.x.x/24"
      "private_cidr": "x.x.x.x/24"
      "az": "us-east-1c"
    }
  }

The code,

resource "aws_subnet" "private" {
  for_each    = var.subnets
  vpc_id      = aws_vpc.vpc.id
  cidr_block  = each.value["private_cidr"]
  availability_zone = each.value["az"]
  tags = {
    Name      = "private-subnet-${each.key}"
  }
}

terravision draw --source --debug

Traceback (most recent call last):
File "/terravision/terravision", line 265, in
cli(
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/terravision/terravision", line 188, in draw
tfdata = compile_tfdata(source, varfile, workspace, debug, annotate)
File "/terravision/terravision", line 64, in compile_tfdata
tfdata = graphmaker.handle_special_resources(tfdata)
File "/terravision/modules/graphmaker.py", line 462, in handle_special_resources
tfdata = getattr(resource_handlers, handler)(tfdata)
File "/terravision/modules/resource_handlers.py", line 154, in aws_handle_subnet_azs
tfdata["meta_data"][az]["count"] = tfdata["meta_data"][subnet]["count"]
KeyError: 'aws_subnet.private[1a]'

Originally created by @jonbutland on GitHub (Mar 19, 2024). Original GitHub issue: https://github.com/patrickchugh/terravision/issues/112 The variable, ``` subnets = { "1a" = { "public_cidr": "x.x.x.x/24" "private_cidr": "x.x.x.x/24" "az": "us-east-1a" } "1b" = { "public_cidr": "x.x.x.x/24" "private_cidr": "x.x.x.x/24" "az": "us-east-1b" } "1c" = { "public_cidr": "x.x.x.x/24" "private_cidr": "x.x.x.x/24" "az": "us-east-1c" } } ``` The code, ``` resource "aws_subnet" "private" { for_each = var.subnets vpc_id = aws_vpc.vpc.id cidr_block = each.value["private_cidr"] availability_zone = each.value["az"] tags = { Name = "private-subnet-${each.key}" } } ``` terravision draw --source --debug Traceback (most recent call last): File "/terravision/terravision", line 265, in <module> cli( File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__ return self.main(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke return __callback(*args, **kwargs) File "/terravision/terravision", line 188, in draw tfdata = compile_tfdata(source, varfile, workspace, debug, annotate) File "/terravision/terravision", line 64, in compile_tfdata tfdata = graphmaker.handle_special_resources(tfdata) File "/terravision/modules/graphmaker.py", line 462, in handle_special_resources tfdata = getattr(resource_handlers, handler)(tfdata) File "/terravision/modules/resource_handlers.py", line 154, in aws_handle_subnet_azs tfdata["meta_data"][az]["count"] = tfdata["meta_data"][subnet]["count"] KeyError: 'aws_subnet.private[1a]'
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:2106029858 --> @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?
Author
Owner

@jonbutland commented on GitHub (May 13, 2024):

That error seems to be fixed now.

<!-- gh-comment-id:2107706133 --> @jonbutland commented on GitHub (May 13, 2024): That error seems to be fixed 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#59
No description provided.