From 5da994cb21cf8b61de64c8ac35347c063bc20ba2 Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Fri, 22 Aug 2025 18:38:44 +0530 Subject: [PATCH 01/13] chore: add Pipfile and .gitignore --- .gitignore | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Pipfile | 11 +++++ 2 files changed, 147 insertions(+) create mode 100644 .gitignore create mode 100644 Pipfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..60a7c8f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,136 @@ +# Mac specific +.DS_Store + +# python specific +__pycache__ +.coverage +coverage_results +.coverage* +coverage.xml +htmlcov +.venv +.pyre +.pytest_cache/ + +# Visual Studio Code +.vscode/ +.env + +# build artifacts +**/test-results/** +blu-server-coverage.tgz +.artifacts/** +dist/** +**/sqlite_test.db +.container-id +docker-artifacts/** +portal.zip +analyzer.zip +ngrok.log + +# portal copy +static/server-version.txt + +# other cloned repos +.repos/** + + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +.idea/ +*.iml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +# Database stuff +database/postgresql-*.jar + +# OS stuff +*.pid + +# Profile files +profiles + +# Pyenv +# .python-version is needed by setup-python GH action +# .python-version + +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Cached build artifacts from the Go build system +.cache + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# OS-specific files +.DS_Store + +# Repo-specific +bin/ + +# Generated protoset files +*.protoset + +# Root vendor directory generated from the Go build system +/vendor + +### Visual Studio Code ### +.vscode/* +!.vscode/settings.json +!.vscode/launch.json +!.vscode/extensions.json + +# Ignore code-workspaces +*.code-workspace +/app/__pycache__/ + +# Terraform +terraform/local/.terraform/** +poc-terraform/.terraform +poc-terraform/terraform.tfstate* + +# Proto bin generated files +protos.bin + +# Local RSA keys +.local/* diff --git a/Pipfile b/Pipfile new file mode 100644 index 00000000..d61ea531 --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.13" From 525e9ab0c25fdbdad1bb569558a1cab74d2a3bc8 Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Fri, 22 Aug 2025 18:49:33 +0530 Subject: [PATCH 02/13] chore: Add ISSUE_TEMPLATE --- .github/ISSUE_TEMPLATE/bug_report.md | 54 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 8 ++++ .github/ISSUE_TEMPLATE/feature_request.md | 43 ++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..cf223dbc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,54 @@ +--- +name: Bug report +about: Let us know about an unexpected error, a crash, or an incorrect behavior. +labels: bug +--- + + + +#### python-tfe version + +```plaintext +... +``` + +## Description + + +## Testing plan + +```plaintext +... +``` + +#### Expected Behavior + + +#### Actual Behavior + + +#### Additional Context + diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..f6782d3b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: HCP Terraform and Terraform Enterprise Troubleshooting and Feature Requests + url: https://support.hashicorp.com/hc/en-us/requests/new + about: For issues and feature requests concerning the HCP Terraform and Terraform Enterprise platform itself, please submit a HashiCorp support request or email tf-cloud@hashicorp.support + - name: Terraform Language or Workflow Questions + url: https://discuss.hashicorp.com + about: Please ask Terraform language or workflow related questions through the HashiCorp Discuss forum diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..07f602ad --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,43 @@ +--- +name: Feature request +about: Suggest a new feature or other enhancement. +labels: feature-request +--- + + + + +#### Use-cases + + +#### Attempted Solutions + + +#### Proposal + From cdcb329bb890a6bf70c3350912b2223e13a18939 Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Fri, 22 Aug 2025 18:52:55 +0530 Subject: [PATCH 03/13] chore: Add dependabot and pull_request_template --- .github/dependabot.yml | 8 ++++ .github/pull_request_template.md | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..0534f448 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +--- +version: 2 + +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..9d614dc2 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,64 @@ + + +## Description + + + +## Testing plan + + + +## External links + + + +## Output from tests +Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against. + + +``` +... +``` + + +## Rollback Plan + + + +## Changes to Security Controls + + From 634152fee7bd7db8b4d86e57844486d0c464c6e6 Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Fri, 22 Aug 2025 22:41:20 +0530 Subject: [PATCH 04/13] chore: add codeowners --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..198a1181 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @hashicorp/tf-ansible-integration \ No newline at end of file From fc317df6fc05381397fb16704dc323d9195d433b Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Fri, 22 Aug 2025 22:42:06 +0530 Subject: [PATCH 05/13] chore: move CODEOWNERS file --- CODEOWNERS => .github/CODEOWNERS | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CODEOWNERS => .github/CODEOWNERS (100%) diff --git a/CODEOWNERS b/.github/CODEOWNERS similarity index 100% rename from CODEOWNERS rename to .github/CODEOWNERS From 6253c06e5d649f1665603e6eed1653172ceaa6ed Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Fri, 22 Aug 2025 22:44:51 +0530 Subject: [PATCH 06/13] chore: update codeowners --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 198a1181..ec07fb81 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @hashicorp/tf-ansible-integration \ No newline at end of file +* @hashicorp/team-tf-ansible-integration \ No newline at end of file From 77a709b532ddd247a3d3261c69b03910759d794c Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Mon, 25 Aug 2025 14:01:48 +0530 Subject: [PATCH 07/13] chore: Add code ql workflow --- .github/workflows/codeql-analysis.yml | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..26b3ea8e --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,69 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [main] + pull_request: + schedule: + - cron: "15 2 * * 2" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["python"] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@9a866ed4524fc3422c3af1e446dab8efa3503411 # codeql-bundle-20230418 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@9a866ed4524fc3422c3af1e446dab8efa3503411 # codeql-bundle-20230418 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@9a866ed4524fc3422c3af1e446dab8efa3503411 # codeql-bundle-20230418 From 9519b0d131c4210b4b264d9aab8d3d34fd21f222 Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Mon, 25 Aug 2025 17:16:14 +0530 Subject: [PATCH 08/13] chore: Add CI config items and project dependency management --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/lint.yml | 38 ++++++++++ .github/workflows/test.yml | 34 +++++++++ Makefile | 48 ++++++++++++ Pipfile | 11 --- pyproject.toml | 101 ++++++++++++++++++++++++++ src/python_tfe/__init__.py | 7 ++ src/python_tfe/client.py | 3 + tests/__init__.py | 1 + 9 files changed, 233 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml create mode 100644 Makefile delete mode 100644 Pipfile create mode 100644 pyproject.toml create mode 100644 src/python_tfe/__init__.py create mode 100644 src/python_tfe/client.py create mode 100644 tests/__init__.py diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 26b3ea8e..14539d84 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -36,7 +36,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4.1.6 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..31b5489e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,38 @@ +name: Lint + +on: + push: + branches: [main] + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.13"] + + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 + with: + python-version: ${{ matrix.python-version }} + + - name: Install pipenv + run: | + python -m pip install --upgrade pip + pip install pipenv + + - name: Install dependencies + run: | + make dev-install + + - name: Check code formatting + run: | + pipenv run ruff format --check . + + - name: Run linting + run: | + make lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..500d7d13 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: test + +on: + push: + branches: [main] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 + with: + python-version: ${{ matrix.python-version }} + + - name: Install pipenv + run: | + python -m pip install --upgrade pip + pip install pipenv + + - name: Install dependencies + run: | + make dev-install + + - name: Run tests + run: | + make test diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..60321de0 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +.PHONY: help vet fmt lint test install dev-install type-check clean all + +PYTHON := python3 +PIPENV := pipenv +SRC_DIR := src +TEST_DIR := tests + +help: + @echo "Available targets:" + @echo " install Install package dependencies" + @echo " dev-install Install package and development dependencies" + @echo " fmt Format code with ruff" + @echo " lint Run linting (ruff + mypy)" + @echo " type-check Run type checking with mypy" + @echo " test Run unit tests" + @echo " clean Clean build artifacts and cache" + @echo " all Run clean + dev-install + fmt + lint + test" + +install: + $(PIPENV) install -e . + +dev-install: + $(PIPENV) install -e ".[dev]" + +fmt: + $(PIPENV) run ruff format . + $(PIPENV) run ruff check --fix . + +lint: + $(PIPENV) run ruff check . + $(PIPENV) run mypy $(SRC_DIR) + +type-check: + $(PIPENV) run mypy $(SRC_DIR) + +test: + $(PIPENV) run pytest + +clean: + find . -type f -name "*.pyc" -delete + find . -type d -name "__pycache__" -delete + find . -type d -name "*.egg-info" -exec rm -rf {} + + find . -type d -name ".pytest_cache" -exec rm -rf {} + + find . -type d -name ".mypy_cache" -exec rm -rf {} + + find . -type d -name ".ruff_cache" -exec rm -rf {} + + rm -rf build/ dist/ + +all: clean dev-install fmt lint test diff --git a/Pipfile b/Pipfile deleted file mode 100644 index d61ea531..00000000 --- a/Pipfile +++ /dev/null @@ -1,11 +0,0 @@ -[[source]] -url = "https://pypi.org/simple" -verify_ssl = true -name = "pypi" - -[packages] - -[dev-packages] - -[requires] -python_version = "3.13" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..9bbdec57 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,101 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "python-tfe" +version = "0.1.0" +description = "Python client library for Terraform Enterprise/Cloud API" +readme = "README.md" +license = {text = "MPL-2.0"} +authors = [{name = "HashiCorp"}] +requires-python = ">=3.13" +dependencies = [ + "requests>=2.25.0", +] + +[project.optional-dependencies] +dev = [ + "pytest>=7.0.0", + "mypy>=1.17.1", + "ruff>=0.12.10", +] + +[project.urls] +Repository = "https://github.com/hashicorp/python-tfe" + +[tool.setuptools.packages.find] +where = ["src"] + +[tool.setuptools.package-dir] +"" = "src" + +# Ruff configuration +[tool.ruff] +target-version = "py313" +line-length = 88 +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + "I", # isort + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "UP", # pyupgrade +] +ignore = [ + "E501", # line too long, handled by formatter +] +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", +] + +[tool.ruff.format] +quote-style = "double" +indent-style = "space" +skip-magic-trailing-comma = false +line-ending = "auto" + +[tool.ruff.lint.isort] +known-first-party = ["python_tfe"] + +# MyPy configuration +[tool.mypy] +python_version = "3.13" +warn_return_any = true +warn_unused_configs = true +disallow_untyped_defs = true +disallow_incomplete_defs = true +check_untyped_defs = true +disallow_untyped_decorators = true +no_implicit_optional = true +warn_redundant_casts = true +warn_unused_ignores = true +warn_no_return = true +warn_unreachable = true +strict_equality = true +show_error_codes = true + +[[tool.mypy.overrides]] +module = "tests.*" +disallow_untyped_defs = false diff --git a/src/python_tfe/__init__.py b/src/python_tfe/__init__.py new file mode 100644 index 00000000..c9fa6c7b --- /dev/null +++ b/src/python_tfe/__init__.py @@ -0,0 +1,7 @@ +""" +Python client library for Terraform Enterprise/Cloud API. + +This package provides a Python interface to the Terraform Enterprise +and Terraform Cloud APIs, allowing you to programmatically manage +workspaces, runs, state files, and other TFE/TFC resources. +""" \ No newline at end of file diff --git a/src/python_tfe/client.py b/src/python_tfe/client.py new file mode 100644 index 00000000..190cfb0c --- /dev/null +++ b/src/python_tfe/client.py @@ -0,0 +1,3 @@ +""" +Main client class for Terraform Enterprise/Cloud API. +""" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..2cfc4486 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +"""Tests for the python-tfe package.""" From f2a4bdfb78abefbd913b50783d7adbe39002f343 Mon Sep 17 00:00:00 2001 From: Taru Garg Date: Mon, 25 Aug 2025 17:51:47 +0530 Subject: [PATCH 09/13] chore: update actions and makefile to run properly in ci/cd --- .github/pull_request_template.md | 3 ++- .github/workflows/lint.yml | 10 +++----- .github/workflows/test.yml | 6 +---- .gitignore | 2 ++ Makefile | 43 +++++++++++++++++++------------- pyproject.toml | 26 ++++++++++--------- src/python_tfe/__init__.py | 2 +- 7 files changed, 49 insertions(+), 43 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 9d614dc2..bb42a15c 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -39,16 +39,17 @@ _Include any links here that might be helpful for people reviewing your PR. If t --> ## Output from tests + Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against. + ``` ... ``` - ## Rollback Plan