blast-radius icon indicating copy to clipboard operation
blast-radius copied to clipboard

Error fetching terraform module in blast-radius

Open NeerajJ-addweb opened this issue 3 years ago • 16 comments

I am trying to create a graph using blast-radius but it's throwing below error, can anyone please help me. I think it's unable to fetch terraform module. Thank you

` * Serving Flask app "blastradius.server.server" (lazy loading)

  • Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Debug mode: off
  • Running on http://0.0.0.0:4004/ (Press CTRL+C to quit) 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET / HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/jquery.slim.min.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/bootstrap.min.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/d3.v4.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/fontawesome-all.min.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/blast-radius.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/d3-tip.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/categories.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/selectize.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/css/bootstrap.min.css HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/css/selectize.css HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/js/svg-pan-zoom.js HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /static/css/style.css HTTP/1.1" 200 - 127.0.0.1 - - [02/Sep/2020 15:56:46] "GET /favicon.ico HTTP/1.1" 404 - [2020-09-02 15:56:53,479] ERROR in app: Exception on /graph.svg [GET] Traceback (most recent call last): File "/home/harsh896/.local/lib/python3.8/site-packages/blastradius/handlers/dot.py", line 455, in _module return m.groupdict()['module'] AttributeError: 'NoneType' object has no attribute 'groupdict'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/usr/lib/python3/dist-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/lib/python3/dist-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python3/dist-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/lib/python3/dist-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/usr/lib/python3/dist-packages/flask/app.py", line 1935, in dispatch_request return self.view_functionsrule.endpoint File "/home/harsh896/.local/lib/python3.8/site-packages/blastradius/server/server.py", line 36, in graph_svg dot = DotGraph('', file_contents=run_tf_graph()) File "/home/harsh896/.local/lib/python3.8/site-packages/blastradius/handlers/dot.py", line 56, in init self.nodes.append(DotNode(e.target)) File "/home/harsh896/.local/lib/python3.8/site-packages/blastradius/handlers/dot.py", line 415, in init self.module = DotNode._module(self.label) # for module groupings. 'root' or 'module.foo.module.bar' File "/home/harsh896/.local/lib/python3.8/site-packages/blastradius/handlers/dot.py", line 457, in _module raise Exception("None: ", label) Exception: ('None: ', '[root] module.services (close)') 127.0.0.1 - - [02/Sep/2020 15:56:53] "GET /graph.svg HTTP/1.1" 500 - `

NeerajJ-addweb avatar Sep 02 '20 11:09 NeerajJ-addweb

I have the same issue, guessing it'll be a tf0.13 issue

dwilliams782 avatar Sep 02 '20 15:09 dwilliams782

Same issue, terraform 0.13.5

NandoTheessen avatar Mar 01 '21 09:03 NandoTheessen

I have it with Terraform v0.14.9

dano0b avatar Apr 02 '21 12:04 dano0b

I have the issue with Terraform v0.15.3

jryan128 avatar May 17 '21 18:05 jryan128

I have a same issue with 0.13.6 :( So sad I just found this great project which may help me visualizing Terraform graph.

caiconkhicon avatar May 27 '21 06:05 caiconkhicon

Same error.

AttributeError: 'NoneType' object has no attribute 'groupdict' in blastradius/handlers/dot.py.

alen-z avatar Jul 07 '21 13:07 alen-z

Same here on v1.0.4:

[2021-08-17 11:18:46,902] ERROR in app: Exception on /graph.svg [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/blastradius/handlers/dot.py", line 455, in _module
    return m.groupdict()['module']
AttributeError: 'NoneType' object has no attribute 'groupdict'

KieranP avatar Aug 16 '21 23:08 KieranP

I have the issue with Terraform v0.15.5

krystian1981 avatar May 20 '22 09:05 krystian1981

same issue with terraform v1.2.9

[2022-09-23 22:09:27,966] ERROR in app: Exception on /graph.svg [GET]
Traceback (most recent call last):
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/blastradius/handlers/dot.py", line 455, in _module
    return m.groupdict()['module']
AttributeError: 'NoneType' object has no attribute 'groupdict'

During handling of the above exception, another exception occurred:

xiaopeng163 avatar Sep 23 '22 22:09 xiaopeng163

Not sure if this will help, but you can try using my version of Blast Radius which I've tried to increase compatibility for.

Source Code: Blast Radius Fork

Installation: python3 -m pip install git+https://github.com/Ianyliu/blast-radius-fork

docker run --rm -it -p 5000:5000 \ -v $(pwd):/data:ro \ --security-opt apparmor:unconfined \ --cap-add=SYS_ADMIN \ ianyliu/blast-radius-fork

Docker image:

Ianyliu avatar Sep 25 '22 04:09 Ianyliu

Not sure if this will help, but you can try using my version of Blast Radius which I've tried to increase compatibility for.

Source Code: Blast Radius Fork

Installation: python3 -m pip install git+https://github.com/Ianyliu/blast-radius-fork

docker run --rm -it -p 5000:5000 \ -v $(pwd):/data:ro \ --security-opt apparmor:unconfined \ --cap-add=SYS_ADMIN \ ianyliu/blast-radius-fork

Docker image:

got error like this

[2022-09-25 07:48:26,018] ERROR in app: Exception on /graph.svg [GET]
Traceback (most recent call last):
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/lark/parsers/lalr_parser.py", line 59, in get_action
    return states[state][token.type]
KeyError: '__ANON_3'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/blastradius/server/server.py", line 134, in graph_svg
    dot = initalizeDotGraph(content=run_tf_graph(),
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/blastradius/server/server.py", line 215, in initalizeDotGraph
    tf = Terraform(os.getcwd())
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/blastradius/handlers/terraform.py", line 29, in __init__
    self.config = hcl.load(config_io)
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/hcl2/api.py", line 9, in load
    return loads(file.read())
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/hcl2/api.py", line 18, in loads
    return hcl2.parse(text + "\n")
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/lark/lark.py", line 464, in parse
    return self.parser.parse(text, start=start)
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/lark/parser_frontends.py", line 115, in parse
    return self._parse(token_stream, start)
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/lark/parser_frontends.py", line 63, in _parse
    return self.parser.parse(input, start, *args)
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/lark/parsers/lalr_parser.py", line 35, in parse
    return self.parser.parse(*args)
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/lark/parsers/lalr_parser.py", line 88, in parse
    action, arg = get_action(token)
  File "/home/vagrant/venv/terraform/lib/python3.8/site-packages/lark/parsers/lalr_parser.py", line 66, in get_action
    raise UnexpectedToken(token, expected, state=state, puppet=puppet)
lark.exceptions.UnexpectedToken: Unexpected token Token('__ANON_3', 'output') at line 302, column 3.
Expected one of: 
        * __ANON_0
        * __ANON_2
        * __ANON_1

127.0.0.1 - - [25/Sep/2022 07:48:26] "GET /graph.svg HTTP/1.1" 500 -

xiaopeng163 avatar Sep 25 '22 07:09 xiaopeng163

Do you happen to know if you're using HCL or HCL2? I've updated one of the dependencies, python-hcl2 to see if it will help. The problem occurred when parsing HCL files, and it's not the first time someone told me about it. Since I'm not extremely familiar with HCL parsing either, I'm still trying to wrap my head around it

Ianyliu avatar Sep 25 '22 17:09 Ianyliu

another finding, it will work without any issue if there are no modules imported. @Ianyliu

xiaopeng163 avatar Sep 25 '22 19:09 xiaopeng163

Hi @xiaopeng163, Could you try testing out this version of Blast-Radius (fork)?

It should resolve the problems for remote modules I integrated changes from Jrc356/blast-radius

The changes are on my dev branch, so to install it you would have to put: pip install -U git+https://github.com/Ianyliu/blast-radius-fork@dev

If you use Docker and would like me to create a dev or testing image, please let me know as well

Ianyliu avatar Oct 16 '22 04:10 Ianyliu

@Ianyliu seems working with the remote module, for example

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = ">= 3.14.2"

  name           = var.aws_vpc_name
  cidr           = var.aws_vpc_cidr
  azs            = var.aws_availability_zones
  public_subnets = [cidrsubnet(var.aws_vpc_cidr, 8, 1)]

  create_igw = true

  manage_default_security_group  = true
  default_security_group_egress  = var.aws_sg_egress_rules
  default_security_group_ingress = var.aws_sg_ingress_rules
}

image

but to be honest, this is not readable, seems it shows all resources defined in the module?

btw, the code still doesn't work for local modules like:

module "my_vpc" {

  source = "./modules/vpc"
  
  aws_vpc_cidr_block = var.aws_vpc_cidr_block

}

output "vpc_id" {
  
  value = module.my_vpc.id

}

xiaopeng163 avatar Oct 18 '22 18:10 xiaopeng163

@xiaopeng163 Was there a problem before with local modules? I assumed that your problem was just due to the modules being remote. If the source is from another local file, I doubt it will work right now. But perhaps that is something I should work on.

Could you describe the problem in more detail? I don't really have any experience using local modules in Terraform.

Ianyliu avatar Oct 20 '22 03:10 Ianyliu