professional-services: SyntaxError in gcpviz

I was trying to run gcpviz example from the documents: docker run --rm -v $PWD/cai:/gcpviz/cai IMAGE_ID gcpviz.sh network --query-file queries/data.js

And getting the following error: Failed to create graph: SyntaxError: (anonymous): Line 103:16 Unexpected token ILLEGAL (and 2 more errors)

To reproduce:

gcloud asset export --content-type=resource --output-path="gs://PATH" --project=PROJECT
# Download result to folder name cai
cd tools/gcpviz
docker build .
docker run --rm -v $PWD/cai:/gcpviz/cai IMAGE_ID gcpviz.sh network --query-file queries/data.js

Docker version:Docker version 19.03.13, build 4484c46d9d

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Yes, that did the trick, thanks, I only now saw the glcoud example in README. Now the “dot” command runs for two hours, no sure if it’s normal. IMO the issue could be closed, but I’m not the OP.

Just add --content-type resource to the gcloud asset export command and you should get the resource objects 😃

I think the message has to do with that you don’t have an organization resource in your resource_inventory.json. Have you done an export of the entire organization? You can check if you have the organization resource by running:

$ grep 'cloudresourcemanager.googleapis.com/Organization' resource_inventory.json | python -mjson.tool
{
    "ancestors": [
        "organizations/1234567890"
    ],
    "asset_type": "cloudresourcemanager.googleapis.com/Organization",
    "name": "//cloudresourcemanager.googleapis.com/organizations/1234567890",
    "resource": {
        "data": {
            "creationTime": "2019-09-08T12:44:26.196Z",
            "displayName": "example.com",
            "lifecycleState": "ACTIVE",
            "name": "organizations/1234567890",
            "owner": {
                "directoryCustomerId": "C00000000"
            }
        },
        "discovery_document_uri": "https://cloudresourcemanager.googleapis.com/$discovery/rest?version=v1",
        "discovery_name": "Organization",
        "version": "v1"
    },
    "update_time": "2019-10-22T04:09:06.757Z"
}

If you don’t have it, you probably have exported only one project (gcloud asset export with --project flag). Try to export the entire organization by specifying the --organization flag to gcloud asset export.

If you want to visualize 1 project only, you could change the queries/data.js on line 103 from:

var root = g.V("{{ index .Organizations 0 }}");

to

var root = g.V("//cloudresourcemanager.googleapis.com/projects/123456789"); // change to your project number

You can also see the queries/one-project-example.js on how to pass the project ID via command line.

Have same problem. Basically it fails on this step:

./gcpviz -mode visualize --query-file queries/data.js > cai/network.gv

Same docker image builded locally.