tf-project 0.3.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,389 @@
1
+ Metadata-Version: 2.4
2
+ Name: tf-project
3
+ Version: 0.3.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Environment :: Console
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Intended Audience :: System Administrators
8
+ Classifier: Operating System :: MacOS
9
+ Classifier: Operating System :: Microsoft :: Windows
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Programming Language :: Rust
12
+ Classifier: Topic :: Software Development :: Build Tools
13
+ Classifier: Topic :: System :: Installation/Setup
14
+ Classifier: Topic :: System :: Systems Administration
15
+ Classifier: Topic :: Utilities
16
+ License-File: LICENSE
17
+ Summary: Terraform / OpenTofu wrapper with named per-tfvars slots, cached `.terraform/`, 1Password secret injection, and apply-safety guards.
18
+ Keywords: terraform,opentofu,tofu,infrastructure-as-code,iac,devops,cli,wrapper,tfvars,multi-environment,workspaces,1password,op-cli,secrets,azurerm,s3-backend,terraform-state
19
+ Author-email: Ilja Orlovs <ilja@release.art>
20
+ Maintainer-email: Ilja Orlovs <ilja@release.art>
21
+ License-Expression: MIT
22
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
23
+ Project-URL: Changelog, https://github.com/release-art/tf-project/blob/main/CHANGELOG.md
24
+ Project-URL: Documentation, https://github.com/release-art/tf-project#readme
25
+ Project-URL: Homepage, https://github.com/release-art/tf-project
26
+ Project-URL: Issues, https://github.com/release-art/tf-project/issues
27
+ Project-URL: Releases, https://github.com/release-art/tf-project/releases
28
+ Project-URL: Repository, https://github.com/release-art/tf-project
29
+
30
+ # tf-project
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/tf-project.svg)](https://pypi.org/project/tf-project/)
33
+ [![License](https://img.shields.io/github/license/release-art/tf-project.svg)](https://github.com/release-art/tf-project/blob/main/LICENSE)
34
+
35
+ A thin, opinionated **Terraform / OpenTofu** wrapper for multi-environment
36
+ projects. Provides a single `tf-project` (aka `tfp`) CLI built around
37
+ **named slots** - each tfvars file binds to a slot, and switching between
38
+ slots is a pointer write, not a re-`terraform init`.
39
+
40
+ If you maintain one tfvars per environment (`dev.tfvars`, `staging.tfvars`,
41
+ `prod.tfvars`, …) and you're tired of re-initialising the backend every
42
+ time you switch, this tool replaces that ritual with `tfp use dev`.
43
+
44
+ - **Slots, not paths.** Banner-declared (or filename-derived) names refer to
45
+ tfvars files. `tfp use dev` flips the active slot; `tfp plan` / `tfp apply`
46
+ operate against it.
47
+ - **One `.terraform/` per slot** via `TF_DATA_DIR`. Two slots pointing at the
48
+ same project keep independent provider/module/backend bindings on disk -
49
+ swapping between them is instant when both are warm.
50
+ - **Shared provider cache** via `TF_PLUGIN_CACHE_DIR`. Providers download
51
+ once and link into every slot's `.terraform/providers/`.
52
+ - **Versioned, strictly validated state files.** Every persisted JSON carries
53
+ `schema_version`; unknown fields fail loudly (except in user-authored
54
+ banners, where they are tolerated and reported by `tfp self banner check`).
55
+ - Pluggable tfvars preprocessing - defaults to [1Password's `op inject`][op]
56
+ so you can keep `op://...` references in tfvars committed to git.
57
+
58
+ [op]: https://developer.1password.com/docs/cli/secrets-template-syntax/
59
+
60
+ ## Install
61
+
62
+ ```sh
63
+ pip install tf-project # or: uv tool install tf-project / pipx install tf-project
64
+ ```
65
+
66
+ The CLI is exposed as both `tf-project` and the shorter alias `tfp`. It is a
67
+ single native program; the PyPI wheels (Linux x86_64 / arm64, macOS arm64,
68
+ Windows x86_64) contain nothing else.
69
+
70
+ To install without Python, download
71
+ `tf-project-<version>-<target>.tar.gz` (`.zip` for Windows) from a
72
+ [GitHub Release][releases] and put `tfp` / `tf-project` on your `PATH`. Every
73
+ release file is signed with [Sigstore][sigstore].
74
+
75
+ [releases]: https://github.com/release-art/tf-project/releases
76
+
77
+ ## Configure
78
+
79
+ ```sh
80
+ cd path/to/your-terraform-repo
81
+ tfp self init
82
+ ```
83
+
84
+ This drops a `tf_project.toml` at the repo root, or - if a `pyproject.toml`
85
+ is already present - appends a `[tool.tf_project]` section to it. It refuses
86
+ to overwrite an existing config.
87
+
88
+ You can also write the file yourself:
89
+
90
+ ```toml
91
+ [tf_project]
92
+ terraform_dir = "terraform" # where your <project>/ subdirs live
93
+ tfvars_dir = "tfvars" # scanned for slots; used by `tfp fmt`
94
+ tmp_dir = "tmp" # slot dirs + plugin cache land here
95
+ state_key_prefix = "terraform/azure/" # remote backend key prefix
96
+
97
+ # Optional. Defaults to `terraform` as found on PATH. A bare name (`tofu`) is
98
+ # looked up on PATH when run; a path is taken relative to the project root.
99
+ # terraform_binary = "bin/terraform-1.7.5"
100
+
101
+ # Optional. Defaults to `<tmp_dir>/plugin-cache`. Set to "" to disable.
102
+ # plugin_cache_dir = "tmp/plugin-cache"
103
+
104
+ # Optional. Static `-backend-config` k/v pairs applied to every slot init.
105
+ [tf_project.backend_config]
106
+ # resource_group_name = "tfstate-rg"
107
+ # storage_account_name = "tfstate0001"
108
+ # container_name = "tfstate"
109
+
110
+ # Optional. Defaults to `op inject`. Set `command = []` to disable.
111
+ [tf_project.secrets]
112
+ command = ["op", "inject", "--in-file", "{in}", "--out-file", "{out}"]
113
+ ```
114
+
115
+ Unknown fields in `tf_project.toml` are rejected at load time.
116
+
117
+ ### Tfvars banner
118
+
119
+ Each tfvars file carries a one-line JSON banner that identifies its project
120
+ and (optionally) names its slot:
121
+
122
+ ```hcl
123
+ # {"header": "terraform", "project": "demo"}
124
+ foo = "bar"
125
+ ```
126
+
127
+ The slot name defaults to the tfvars filename stem (`tfvars/dev.tfvars` →
128
+ slot `dev`). Override with a `slot` field:
129
+
130
+ ```hcl
131
+ # {"header": "terraform", "project": "demo", "slot": "production"}
132
+ ```
133
+
134
+ Banner fields:
135
+
136
+ | Field | Purpose |
137
+ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------- |
138
+ | `header` | Must be `"terraform"`. Identifies the comment line as a tf-project banner. |
139
+ | `project` | Subdirectory under `terraform_dir/` containing the source `.tf` files. |
140
+ | `slot` | Slot name. Defaults to the tfvars filename stem. Must be unique across all tfvars in `tfvars_dir`. |
141
+ | `state_key` | Full remote-state backend key. Overrides the default `<state_key_prefix><tfvars-stem>.tfstate`. Must be an absolute, normalised pure POSIX path (`/shared/global.tfstate`); relative keys, `.`/`..`, `//`, trailing `/`, and backslashes are rejected. The single leading slash is stripped before use (azurerm prepends the container, so a leading slash would double it). Use to share state across files. |
142
+ | `env` | JSON object of `string → string` env vars passed to terraform when running against this slot. |
143
+ | `backend_config` | JSON object of extra `-backend-config k=v` pairs. Wins over the config-level `[tf_project.backend_config]` table. |
144
+
145
+ Unknown banner fields are tolerated (forward-compatible across tfp versions);
146
+ `tfp self banner check` names them, so a typo doesn't disappear silently.
147
+
148
+ ## Usage
149
+
150
+ ```sh
151
+ tfp use dev # switch to slot "dev" (no init if already warm)
152
+ tfp use tfvars/prod.tfvars # a tfvars path works too
153
+ tfp init # re-bind the active slot's backend from its banner
154
+ # (run after editing a banner's state_key/backend_config)
155
+ tfp ls # list slots; active marked with `*`
156
+ tfp rm staging # remove a slot's on-disk directory
157
+
158
+ tfp plan # plan using the active slot
159
+ tfp plan -t module.foo.bar # targeted plan (repeatable)
160
+ tfp plan -r module.foo.bar # force-replace (repeatable)
161
+ tfp apply # apply the saved plan
162
+ tfp refresh # apply directly (no saved plan)
163
+ tfp destroy -t module.foo.bar # targeted destroy
164
+ tfp fmt # terraform fmt -recursive over terraform/ + tfvars/
165
+ tfp output # terraform output -json
166
+ tfp state list # list resources in state
167
+ tfp state show aws_x.foo
168
+ tfp state mv aws_x.a aws_x.b
169
+ tfp state rm aws_x.foo aws_x.bar
170
+ tfp state pull # tfstate JSON to stdout
171
+ tfp state push backup.tfstate
172
+ tfp state replace-provider hashicorp/aws registry.acme.local/aws
173
+ tfp state identities # 1.10+
174
+ tfp import aws_s3_bucket.foo my-bucket
175
+ # forwards the decrypted tfvars + saved env
176
+ tfp status # summary of the active slot
177
+ tfp last # last terraform invocation for the active slot
178
+ ```
179
+
180
+ ### Choosing the active slot
181
+
182
+ Three precedence levels - the most specific wins:
183
+
184
+ | Source | Wins over | Lifetime |
185
+ | ------------------ | ------------ | ----------------------------------------- |
186
+ | `-s/--slot <name>` | everything | single invocation only (does NOT save) |
187
+ | `TFP_SLOT=<name>` | saved file | current shell |
188
+ | `tmp/active` file | - | persistent until next `tfp use` |
189
+
190
+ ```sh
191
+ tfp -s prod plan # one-off, doesn't touch the saved active
192
+ TFP_SLOT=prod tfp plan # current shell only
193
+ tfp use prod # writes tmp/active (affects all shells without TFP_SLOT)
194
+ ```
195
+
196
+ ### Global flags
197
+
198
+ - `--verbose` - echo the terraform argv to stderr before running it.
199
+ - `--dry-run` - print the argv and run nothing.
200
+ - `-s/--slot <name>` - operate against a specific slot for one invocation.
201
+
202
+ `--verbose` and `--dry-run` are accepted anywhere before a `--`; `-s` goes
203
+ before the subcommand.
204
+
205
+ ```sh
206
+ tfp --dry-run plan -t module.foo
207
+ tfp -s prod --verbose apply
208
+ ```
209
+
210
+ ### Plugin cache and the lock file
211
+
212
+ `tfp` enables Terraform's shared plugin cache by default at
213
+ `<tmp_dir>/plugin-cache/`. Providers download once and link into every
214
+ slot's `.terraform/providers/`, so the second slot's first init is seconds.
215
+
216
+ The trade-off: `TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE=1` is set so
217
+ Terraform tolerates the cache's missing per-platform hashes. To keep
218
+ `.terraform.lock.hcl` portable across machines, every `tfp use` that runs
219
+ `terraform init` chases it with `terraform providers lock` for
220
+ `linux_amd64` + `linux_arm64` (the common CI / runtime targets) plus the
221
+ host's own platform - so on an Apple Silicon Mac you get three sets of
222
+ hashes (the two Linux ones + `darwin_arm64`), on Linux you just get the
223
+ two Linux ones, etc.
224
+
225
+ Teams that span multiple host platforms can extend the auto-lock set via
226
+ `tf_project.toml` so everyone's hashes land in the same lockfile regardless
227
+ of who ran `tfp use` last:
228
+
229
+ ```toml
230
+ [tf_project]
231
+ # linux_amd64, linux_arm64, and the host's own platform are always included;
232
+ # anything listed here is added on top.
233
+ extra_lock_platforms = ["windows_amd64", "darwin_amd64"]
234
+ ```
235
+
236
+ To re-lock against a custom platform set (e.g. add `windows_amd64`):
237
+
238
+ ```sh
239
+ tfp self providers lock -p linux_amd64 -p windows_amd64
240
+ ```
241
+
242
+ Disable the cache by setting `plugin_cache_dir = ""` in the config.
243
+
244
+ ### Recovering from a stuck Azure / S3 tfstate lock
245
+
246
+ When terraform is killed mid-operation, the remote backend can leave a
247
+ stale lock on the tfstate. Subsequent runs fail with "state locked".
248
+
249
+ ```sh
250
+ tfp self lock status # lease + lock metadata (exits 2 if locked)
251
+ tfp self lock break # break the lock (prompts for confirmation; -y to skip)
252
+ tfp tf force-unlock <LOCK_ID> # backend-agnostic, via `tfp tf`
253
+ ```
254
+
255
+ `tfp self lock` auto-detects the backend from the active slot's saved state:
256
+
257
+ - **azurerm** - `storage_account_name` + `container_name` present. Shells out
258
+ to `az storage blob`.
259
+ - **s3** - `bucket` + `dynamodb_table` present. Shells out to `aws dynamodb`.
260
+
261
+ Both need the respective CLI installed and authenticated.
262
+
263
+ `tfp self lock break` is **polite by default**: it discovers the lock ID and
264
+ runs `terraform force-unlock <ID>` first, falling back to a backend-level
265
+ lease break only if the polite path fails. Pass `--blunt` to skip terraform
266
+ entirely.
267
+
268
+ ### Auto-snapshot before state-mutating ops
269
+
270
+ `tfp state rm`, `tfp state mv`, `tfp state replace-provider`, and `tfp
271
+ import` each run `terraform state pull` first and save the result to
272
+ `<tmp_dir>/snapshots/<slot>/<ts>-pre-<op>.tfstate` before the mutating
273
+ command runs. If the pull fails (auth blip, network) the whole op aborts -
274
+ no point destroying state you can't roll back to. Recovery:
275
+
276
+ ```sh
277
+ tfp self snapshot list
278
+ tfp self snapshot restore # newest, with confirmation
279
+ tfp self snapshot restore <name> -y # specific snapshot, no prompt
280
+ ```
281
+
282
+ Restoration uses `terraform state push -force`, which overwrites the
283
+ remote state regardless of serial - by definition you're undoing a change,
284
+ so the serial check is exactly what you want to skip.
285
+
286
+ The retention budget is `snapshot_retention` in `tf_project.toml` (default
287
+ **200** per slot, pruned newest-first on every write). Set it to `0` to
288
+ disable auto-snapshotting entirely; `tfp self snapshot create` still works
289
+ either way.
290
+
291
+ ### Apply safety
292
+
293
+ `tfp plan` records a SHA-256 of the decrypted tfvars + every `.tf` under
294
+ `source_root` in `slots/<slot>/tfplan.meta.json`, alongside the active
295
+ banner's `project`, `state_key`, `backend_config`, and `env`. `tfp apply`
296
+ refuses to run if any of those drift between plan and apply. Pass
297
+ `--force` to override.
298
+
299
+ ### Any other Terraform command: `tfp tf`
300
+
301
+ `tfp tf ...` runs any Terraform command verbatim in the active slot, prefixed
302
+ with `-chdir=<source_root>` and the env from the slot's saved state. With no
303
+ active slot it runs Terraform as is:
304
+
305
+ ```sh
306
+ tfp tf validate # terraform -chdir=... validate
307
+ tfp tf workspace list # per-slot workspace state via TF_DATA_DIR
308
+ tfp tf providers schema -json
309
+ tfp tf version # works without an active slot
310
+ ```
311
+
312
+ Only the subcommands listed in this README are wrapped; every other
313
+ Terraform command goes through `tfp tf`.
314
+
315
+ Wrapped subcommands accept Terraform's own flags anywhere after the
316
+ subcommand, appended to the underlying invocation; `--` works too:
317
+
318
+ ```sh
319
+ tfp plan -t module.foo -detailed-exitcode -compact-warnings
320
+ tfp apply -- -parallelism=20
321
+ ```
322
+
323
+ ### Self-management
324
+
325
+ ```sh
326
+ tfp self init # bootstrap tf_project.toml or [tool.tf_project]
327
+ tfp self config print # show effective config (--json for JSON)
328
+ tfp self config path # show which file the config came from
329
+ tfp self state show # active slot's saved state as JSON
330
+ tfp self state show --all # every slot's state
331
+ tfp self state clear # delete the active slot's saved state
332
+ tfp self state clear --all # nuke every slot's saved state
333
+ tfp self doctor # sanity-check the environment (PATH, dirs, slot uniqueness, orphans)
334
+ tfp self banner check <tfvars> # validate a banner; print resolved slot + fields
335
+ tfp self snapshot create # `terraform state pull` to <tmp_dir>/snapshots/<slot>/<ts>-manual.tfstate
336
+ tfp self snapshot list # list snapshots for the active slot, newest first
337
+ tfp self snapshot restore [<name>] # `terraform state push -force` the named snapshot (default: newest)
338
+ tfp self trace <subcommand> # print the argv tfp would build; runs nothing
339
+ tfp self lock status # remote-state lock state (azurerm or s3+dynamodb)
340
+ tfp self lock break # polite-by-default release; --blunt skips terraform
341
+ tfp self providers lock # cross-platform `terraform providers lock`
342
+ tfp tf force-unlock <LOCK_ID> # backend-agnostic, via `tfp tf`
343
+ ```
344
+
345
+ ## Development
346
+
347
+ The program lives in `rust/`. You need the toolchain pinned in
348
+ `rust/rust-toolchain.toml` (rustup installs it on first use) plus
349
+ `cargo-nextest`, `cargo-llvm-cov` and `cargo-deny`.
350
+
351
+ ```sh
352
+ bin/rust/check.sh # fmt, clippy, docs, licences, tests, 100% coverage
353
+ bin/rust/check.sh --fix # format and apply clippy's fixes first
354
+ bin/run.sh status # run tfp from the source tree
355
+ pip install . # build and install the wheel locally (maturin)
356
+ ```
357
+
358
+ Tests use fake `terraform` / `az` / `aws` scripts, so they run on macOS and
359
+ Linux without any of those installed. Run them with nextest (as check.sh
360
+ does): each test gets its own process.
361
+
362
+ ## Release
363
+
364
+ Releases are **tag-driven**. The wheel's version comes from the git tag,
365
+ not a code edit: `rust/Cargo.toml` says `0.0.0`, and the release workflow
366
+ writes the tag into it (`bin/rust/set-version.sh`) before building.
367
+
368
+ 1. Move the `## [Unreleased]` block in `CHANGELOG.md` under a new
369
+ `## [X.Y.Z] - YYYY-MM-DD` heading. Commit to `main`.
370
+ 2. Tag the commit: `git tag vX.Y.Z && git push origin vX.Y.Z`.
371
+ 3. The **Release** workflow fires on the tag push:
372
+ - Re-runs CI against the tagged commit.
373
+ - Builds a wheel per platform (Linux x86_64 + arm64, macOS arm64,
374
+ Windows x86_64) and the sdist, with the version set from the tag.
375
+ - Signs everything with [Sigstore][sigstore] (keyless, transparency-logged).
376
+ - Publishes to PyPI via OIDC trusted publishing.
377
+ - Creates a GitHub Release with the extracted changelog section and the
378
+ signed artifacts attached: the wheels and sdist, plus each platform's
379
+ programs as a standalone `.tar.gz` / `.zip` (`bin/rust/archive.py`).
380
+
381
+ Tags carrying `rc` / `a` / `b` / `dev` suffixes (e.g. `v1.0.0rc1`) are
382
+ auto-marked as pre-releases on GitHub.
383
+
384
+ PyPI trusted-publishing is a one-time setup on
385
+ `pypi.org → Manage project → Publishing`, tied to this repo and the
386
+ `release` GitHub Environment.
387
+
388
+ [sigstore]: https://www.sigstore.dev/
389
+
@@ -0,0 +1,7 @@
1
+ tf_project-0.3.0.data/scripts/tf-project.exe,sha256=-h9a3-92RNsHQvAHjb9JSGbwmkcDZAhdz82y3roV684,2198528
2
+ tf_project-0.3.0.data/scripts/tfp.exe,sha256=zatsrlE_obaknL9n_3DaiI8donNUMPsTvQfJKmXFZ5s,2198528
3
+ tf_project-0.3.0.dist-info/METADATA,sha256=rkaRiPp8ia28NK3M9Fvd3NsrtQssMCWV0iufrv3YSdk,18289
4
+ tf_project-0.3.0.dist-info/WHEEL,sha256=Uvw7WSmy7Kj2FBk8Va4L_dq4MDW8X5Ynby-pOX3ZNS0,94
5
+ tf_project-0.3.0.dist-info/licenses/LICENSE,sha256=fj5jROMpgfAV65ibRYz7cEAlmtRMhscZCYmTGLRW5U0,1089
6
+ tf_project-0.3.0.dist-info/sboms/tf-project.cyclonedx.json,sha256=Lj9BFrsIjYBJBxzeyBy4XS4kYX3Wi73ChG9T2ZiQyL8,68646
7
+ tf_project-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.16.0)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ilja Orlovs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.