{"id":14128623,"url":"https://github.com/beelit94/python-terraform","last_synced_at":"2025-05-15T08:03:45.524Z","repository":{"id":7309458,"uuid":"48794719","full_name":"beelit94/python-terraform","owner":"beelit94","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-07T20:37:47.000Z","size":174,"stargazers_count":479,"open_issues_count":51,"forks_count":176,"subscribers_count":22,"default_branch":"develop","last_synced_at":"2025-04-11T18:25:25.032Z","etag":null,"topics":["python","terraform"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beelit94.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-30T10:02:41.000Z","updated_at":"2025-04-06T13:38:48.000Z","dependencies_parsed_at":"2024-11-27T22:03:31.336Z","dependency_job_id":"e629d5f6-14bc-43e1-bfaf-92ab1c7ab37b","html_url":"https://github.com/beelit94/python-terraform","commit_stats":{"total_commits":187,"total_committers":21,"mean_commits":8.904761904761905,"dds":0.6417112299465241,"last_synced_commit":"8a3451c54ce011c91a105b84b18498a0d615473c"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beelit94%2Fpython-terraform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beelit94%2Fpython-terraform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beelit94%2Fpython-terraform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beelit94%2Fpython-terraform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beelit94","download_url":"https://codeload.github.com/beelit94/python-terraform/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254301420,"owners_count":22047901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","terraform"],"created_at":"2024-08-15T16:01:57.299Z","updated_at":"2025-05-15T08:03:45.484Z","avatar_url":"https://github.com/beelit94.png","language":"Python","readme":"## Introduction\n\npython-terraform is a python module provide a wrapper of `terraform` command line tool.\n`terraform` is a tool made by Hashicorp, please refer to https://terraform.io/\n\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white)](https://github.com/pre-commit/pre-commit)\n\n### Status\n[![Build Status](https://travis-ci.org/aubustou/python-terraform.svg?branch=develop)](https://travis-ci.org/aubustou/python-terraform)\n\n## Installation\n    pip install python-terraform\n\n## Usage\n#### For any terraform command\n\n    from python_terraform import *\n    t = Terraform()\n    return_code, stdout, stderr = t.\u003ccmd_name\u003e(*arguments, **options)\n\n**Note**: method name same as reserved keyword like `import` won't be accepted by python interpreter,\nto be able to call the method, you could call cmd_name by adding `_cmd` after command name, for example,\n`import` here could be called by\n\n    from python_terraform import *\n    t = Terraform()\n    return_code, stdout, stderr = t.import_cmd(*arguments, **options)\n\nor just call cmd method directly\n\n    from python_terraform import *\n    t = Terraform()\n    return_code, stdout, stderr = t.cmd(\u003ccmd_name\u003e, *arguments, **options)\n\n#### For any argument\nsimply pass the string to arguments of the method, for example,\n\n    terraform apply target_dir\n        --\u003e \u003cinstance\u003e.apply('target_dir')\n    terraform import aws_instance.foo i-abcd1234\n        --\u003e \u003cinstance\u003e.import('aws_instance.foo', 'i-abcd1234')\n\n#### For any options\n\n* dash to underscore\n\n    remove first dash, and then use underscore to replace dash symbol as option name\n\n        ex. -no-color --\u003e no_color\n\n* for a simple flag option\n\n    use ```IsFlagged/None``` as value for raising/not raising flag, for example,\n\n        terraform taint -allow-missing\n           --\u003e \u003cinstance\u003e.taint(allow＿missing=IsFlagged)\n        terraform taint\n           --\u003e \u003cinstance\u003e.taint(allow＿missing=None) or \u003cinstance\u003e.taint()\n        terraform apply -no-color\n           --\u003e \u003cinstance\u003e.apply(no_color=IsFlagged)\n\n* for a boolean value option\n\n    assign True or False, for example,\n\n        terraform apply -refresh=true --\u003e \u003cinstance\u003e.apply(refresh=True)\n\n* if a flag could be used multiple times, assign a list to it's value\n\n        terraform apply -target=aws_instance.foo[1] -target=aws_instance.foo[2]\n        ---\u003e\n        \u003cinstance\u003e.apply(target=['aws_instance.foo[1]', 'aws_instance.foo[2]'])\n* for the \"var\" flag, assign dictionary to it\n\n        terraform apply -var='a=b' -var='c=d'\n        --\u003e tf.apply(var={'a':'b', 'c':'d'})\n* if an option with None as value, it won't be used\n\n#### Terraform Output\n\nBy default, stdout and stderr are captured and returned. This causes the application to appear to hang. To print terraform output in real time, provide the `capture_output` option with any value other than `None`. This will cause the output of terraform to be printed to the terminal in real time. The value of `stdout` and `stderr` below will be `None`.\n\n\n    from python_terraform import Terraform\n    t = Terraform()\n    return_code, stdout, stderr = t.\u003ccmd_name\u003e(capture_output=False)\n\n## Examples\n### Have a test.tf file under folder \"/home/test\"\n#### 1. apply with variables a=b, c=d, refresh=false, no color in the output\nIn shell:\n\n    cd /home/test\n    terraform apply -var='a=b' -var='c=d' -refresh=false -no-color\n\nIn python-terraform:\n\n    from python_terraform import *\n    tf = Terraform(working_dir='/home/test')\n    tf.apply(no_color=IsFlagged, refresh=False, var={'a':'b', 'c':'d'})\n\nor\n\n    from python_terraform import *\n    tf = Terraform()\n    tf.apply('/home/test', no_color=IsFlagged, refresh=False, var={'a':'b', 'c':'d'})\n\nor\n\n    from python_terraform import *\n    tf = Terraform(working_dir='/home/test', variables={'a':'b', 'c':'d'})\n    tf.apply(no_color=IsFlagged, refresh=False)\n\n#### 2. fmt command, diff=true\nIn shell:\n\n    cd /home/test\n    terraform fmt -diff=true\n\nIn python-terraform:\n\n    from python_terraform import *\n    tf = terraform(working_dir='/home/test')\n    tf.fmt(diff=True)\n\n\n## default values\nfor apply/plan/destroy command, assign with following default value to make\ncaller easier in python\n\n1. ```input=False```, in this case process won't hang because you missing a variable\n1. ```no_color=IsFlagged```, in this case, stdout of result is easier for parsing\n\n## Implementation\nIMHO, how terraform design boolean options is confusing.\nTake `input=True` and `-no-color` option of `apply` command for example,\nthey're all boolean value but with different option type.\nThis make api caller don't have a general rule to follow but to do\na exhaustive method implementation which I don't prefer to.\nTherefore I end-up with using `IsFlagged` or `IsNotFlagged` as value of option\nlike `-no-color` and `True/False` value reserved for option like `refresh=true`\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeelit94%2Fpython-terraform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeelit94%2Fpython-terraform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeelit94%2Fpython-terraform/lists"}