Giter VIP home page Giter VIP logo

tfquery's People

Contributors

mazen160 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tfquery's Issues

run_query does not initialise SQLHandler correctly

This looks like a really cool project that might help us answer some really interesting questions, thanks for starting it! If we end up using a lot I will endeavour to contribute.

With tfquery installed from both pypi and git, running the below:

import tfquery

def main():
    state_path = "terraform.tfstate"
    result = tfquery.tfstate.run_query(state_path, "select count(*) from resources")
    print(result)

if __name__ == "__main__":
    main()

was giving me this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ben/scratch/tfquery/venv/lib/python3.8/site-packages/tfquery/tfstate.py", line 114, in run_query
    s.insert_resources(resources)
  File "/home/ben/scratch/tfquery/venv/lib/python3.8/site-packages/tfquery/sql_handler.py", line 85, in insert_resources
    self.insert_resource(resource)
  File "/home/ben/scratch/tfquery/venv/lib/python3.8/site-packages/tfquery/sql_handler.py", line 99, in insert_resource
    resource["tfstate_file"] = os.path.basename(self.tfstate_file)
  File "/usr/lib/python3.8/posixpath.py", line 142, in basename
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

It looks like the line that initialises SQLHandler in run_query should pass the tfstate_file like so:

    s = SQLHandler(in_memory=True, tfstate_file=tfstate_file)

Having made that change locally I can then run queries as expected.

Invalid terraform state error

Hi ๐Ÿ‘‹ , thanks for doing this.

I got this error reporting invalid terraform state file:

 9, in validate_tfstate
    raise ValueError("Invalid tfstate file")
ValueError: Invalid tfstate file

and the terraform state file:

{
    "version": 3,
    "serial": 1,
    "lineage": "<uuid>",
    "backend": {
        "type": "s3",
        "config": {
            "access_key": null,
            "acl": "private",
            "assume_role_policy": null,

my understanding is the error comes from the validation expecting a key named "terraform_version" instead of "version". However every reference after that seems to be looking for "version", e.g:

def validate_tfstate(tfstate):
    if "terraform_version" not in tfstate.keys():
        raise ValueError("Invalid tfstate file")
        return False
    if tfstate["version"] < 3:
        raise ValueError("Unsupported tfstate version")
        return False
    return True

Do you think this could be a version issue and should accept both?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.