tf-project 0.3.0rc1__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,386 @@
1
+ Metadata-Version: 2.4
2
+ Name: tf-project
3
+ Version: 0.3.0rc1
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,sops,azurerm,s3-backend,terraform-state,sigstore
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 (written in Rust); the PyPI package only delivers it.
68
+ Wheels are published for Linux (x86_64, arm64), macOS (arm64) and Windows
69
+ (x86_64), and work with any Python 3.
70
+
71
+ Without Python: each [GitHub Release][releases] also carries the two programs
72
+ as `tf-project-<version>-<target>.tar.gz` (`.zip` for Windows), signed with
73
+ Sigstore like the wheels. Unpack it and put `tfp` / `tf-project` on your `PATH`.
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 # path also accepted (useful with shell completion)
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 # one-line 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 skip execution.
200
+ - `-s/--slot <name>` - operate against a specific slot for one invocation.
201
+
202
+ ```sh
203
+ tfp --dry-run plan -t module.foo
204
+ tfp -s prod --verbose apply
205
+ ```
206
+
207
+ ### Plugin cache and the lock file
208
+
209
+ `tfp` enables Terraform's shared plugin cache by default at
210
+ `<tmp_dir>/plugin-cache/`. Providers download once and link into every
211
+ slot's `.terraform/providers/`, so the second slot's first init is seconds.
212
+
213
+ The trade-off: `TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE=1` is set so
214
+ Terraform tolerates the cache's missing per-platform hashes. To keep
215
+ `.terraform.lock.hcl` portable across machines, every `tfp use` that runs
216
+ `terraform init` chases it with `terraform providers lock` for
217
+ `linux_amd64` + `linux_arm64` (the common CI / runtime targets) plus the
218
+ host's own platform - so on an Apple Silicon Mac you get three sets of
219
+ hashes (the two Linux ones + `darwin_arm64`), on Linux you just get the
220
+ two Linux ones, etc.
221
+
222
+ Teams that span multiple host platforms can extend the auto-lock set via
223
+ `tf_project.toml` so everyone's hashes land in the same lockfile regardless
224
+ of who ran `tfp use` last:
225
+
226
+ ```toml
227
+ [tf_project]
228
+ # linux_amd64, linux_arm64, and the host's own platform are always included;
229
+ # anything listed here is added on top.
230
+ extra_lock_platforms = ["windows_amd64", "darwin_amd64"]
231
+ ```
232
+
233
+ To re-lock against a custom platform set (e.g. add `windows_amd64`):
234
+
235
+ ```sh
236
+ tfp self providers lock -p linux_amd64 -p windows_amd64
237
+ ```
238
+
239
+ Disable the cache by setting `plugin_cache_dir = ""` in the config.
240
+
241
+ ### Recovering from a stuck Azure / S3 tfstate lock
242
+
243
+ When terraform is killed mid-operation, the remote backend can leave a
244
+ stale lock on the tfstate. Subsequent runs fail with "state locked".
245
+
246
+ ```sh
247
+ tfp self lock status # lease + lock metadata (exits 2 if locked)
248
+ tfp self lock break # break the lock (prompts for confirmation; -y to skip)
249
+ tfp tf force-unlock <LOCK_ID> # backend-agnostic, via `tfp tf`
250
+ ```
251
+
252
+ `tfp self lock` auto-detects the backend from the active slot's saved state:
253
+
254
+ - **azurerm** - `storage_account_name` + `container_name` present. Shells out
255
+ to `az storage blob`.
256
+ - **s3** - `bucket` + `dynamodb_table` present. Shells out to `aws dynamodb`.
257
+
258
+ Both need the respective CLI installed and authenticated.
259
+
260
+ `tfp self lock break` is **polite by default**: it discovers the lock ID and
261
+ runs `terraform force-unlock <ID>` first, falling back to a backend-level
262
+ lease break only if the polite path fails. Pass `--blunt` to skip terraform
263
+ entirely.
264
+
265
+ ### Auto-snapshot before state-mutating ops
266
+
267
+ `tfp state rm`, `tfp state mv`, `tfp state replace-provider`, and `tfp
268
+ import` each run `terraform state pull` first and save the result to
269
+ `<tmp_dir>/snapshots/<slot>/<ts>-pre-<op>.tfstate` before the mutating
270
+ command runs. If the pull fails (auth blip, network) the whole op aborts -
271
+ no point destroying state you can't roll back to. Recovery:
272
+
273
+ ```sh
274
+ tfp self snapshot list
275
+ tfp self snapshot restore # newest, with confirmation
276
+ tfp self snapshot restore <name> -y # specific snapshot, no prompt
277
+ ```
278
+
279
+ Restoration uses `terraform state push -force`, which overwrites the
280
+ remote state regardless of serial - by definition you're undoing a change,
281
+ so the serial check is exactly what you want to skip.
282
+
283
+ The retention budget is `snapshot_retention` in `tf_project.toml` (default
284
+ **200** per slot, pruned newest-first on every write). Set it to `0` to
285
+ disable auto-snapshotting entirely; `tfp self snapshot create` still works
286
+ either way.
287
+
288
+ ### Apply safety
289
+
290
+ `tfp plan` records a SHA-256 of the decrypted tfvars + every `.tf` under
291
+ `source_root` in `slots/<slot>/tfplan.meta.json`, alongside the active
292
+ banner's `project`, `state_key`, `backend_config`, and `env`. `tfp apply`
293
+ refuses to run if any of those drift between plan and apply. Pass
294
+ `--force` to override.
295
+
296
+ ### Any other Terraform command: `tfp tf`
297
+
298
+ `tfp tf ...` runs any Terraform command verbatim in the active slot, prefixed
299
+ with `-chdir=<source_root>` and the env from the slot's saved state. With no
300
+ active slot it runs Terraform as is:
301
+
302
+ ```sh
303
+ tfp tf validate # terraform -chdir=... validate
304
+ tfp tf workspace list # per-slot workspace state via TF_DATA_DIR
305
+ tfp tf providers schema -json
306
+ tfp tf version # works without an active slot
307
+ ```
308
+
309
+ Unknown subcommands are not forwarded: `tfp validate` is an error, so a typo
310
+ never reaches Terraform by accident.
311
+
312
+ Wrapped subcommands accept Terraform's own flags anywhere after the
313
+ subcommand, appended to the underlying invocation; `--` works too:
314
+
315
+ ```sh
316
+ tfp plan -t module.foo -detailed-exitcode -compact-warnings
317
+ tfp apply -- -parallelism=20
318
+ ```
319
+
320
+ ### Self-management
321
+
322
+ ```sh
323
+ tfp self init # bootstrap tf_project.toml or [tool.tf_project]
324
+ tfp self config print # show effective config (--json for JSON)
325
+ tfp self config path # show which file the config came from
326
+ tfp self state show # active slot's saved state as JSON
327
+ tfp self state show --all # every slot's state
328
+ tfp self state clear # delete the active slot's saved state
329
+ tfp self state clear --all # nuke every slot's saved state
330
+ tfp self doctor # sanity-check the environment (PATH, dirs, slot uniqueness, orphans)
331
+ tfp self banner check <tfvars> # validate a banner; print resolved slot + fields
332
+ tfp self snapshot create # `terraform state pull` to <tmp_dir>/snapshots/<slot>/<ts>-manual.tfstate
333
+ tfp self snapshot list # list snapshots for the active slot, newest first
334
+ tfp self snapshot restore [<name>] # `terraform state push -force` the named snapshot (default: newest)
335
+ tfp self trace <subcommand> # print the argv tfp would build; no exec
336
+ tfp self lock status # remote-state lock state (azurerm or s3+dynamodb)
337
+ tfp self lock break # polite-by-default release; --blunt skips terraform
338
+ tfp self providers lock # cross-platform `terraform providers lock`
339
+ tfp tf force-unlock <LOCK_ID> # backend-agnostic, via `tfp tf`
340
+ ```
341
+
342
+ ## Development
343
+
344
+ The program lives in `rust/`. You need the toolchain pinned in
345
+ `rust/rust-toolchain.toml` (rustup installs it on first use) plus
346
+ `cargo-nextest`, `cargo-llvm-cov` and `cargo-deny`.
347
+
348
+ ```sh
349
+ bin/rust/check.sh # fmt, clippy, docs, licences, tests, 100% coverage
350
+ bin/rust/check.sh --fix # format and apply clippy's fixes first
351
+ bin/run.sh status # run tfp from the source tree
352
+ pip install . # build and install the wheel locally (maturin)
353
+ ```
354
+
355
+ Tests use fake `terraform` / `az` / `aws` scripts, so they run on macOS and
356
+ Linux without any of those installed. Run them with nextest (as check.sh
357
+ does): each test gets its own process.
358
+
359
+ ## Release
360
+
361
+ Releases are **tag-driven**. The wheel's version comes from the git tag,
362
+ not a code edit: `rust/Cargo.toml` says `0.0.0`, and the release workflow
363
+ writes the tag into it (`bin/rust/set-version.sh`) before building.
364
+
365
+ 1. Move the `## [Unreleased]` block in `CHANGELOG.md` under a new
366
+ `## [X.Y.Z] - YYYY-MM-DD` heading. Commit to `main`.
367
+ 2. Tag the commit: `git tag vX.Y.Z && git push origin vX.Y.Z`.
368
+ 3. The **Release** workflow fires on the tag push:
369
+ - Re-runs CI against the tagged commit.
370
+ - Builds a wheel per platform (Linux x86_64 + arm64, macOS arm64,
371
+ Windows x86_64) and the sdist, with the version set from the tag.
372
+ - Signs both with [Sigstore][sigstore] (keyless, transparency-logged).
373
+ - Publishes to PyPI via OIDC trusted publishing.
374
+ - Creates a GitHub Release with the extracted changelog section and the
375
+ signed artifacts attached: the wheels and sdist, plus each platform's
376
+ programs as a standalone `.tar.gz` / `.zip` (`bin/rust/archive.py`).
377
+
378
+ Tags carrying `rc` / `a` / `b` / `dev` suffixes (e.g. `v1.0.0rc1`) are
379
+ auto-marked as pre-releases on GitHub.
380
+
381
+ PyPI trusted-publishing is a one-time setup on
382
+ `pypi.org → Manage project → Publishing`, tied to this repo and the
383
+ `release` GitHub Environment.
384
+
385
+ [sigstore]: https://www.sigstore.dev/
386
+
@@ -0,0 +1,7 @@
1
+ tf_project-0.3.0rc1.data/scripts/tf-project.exe,sha256=iAqmJl24iPyJOTUD1DF5fTL8rkpogZQDdUGNHf2WRIo,2198016
2
+ tf_project-0.3.0rc1.data/scripts/tfp.exe,sha256=nSQffQTcAZcc7JNiaZ962A3Jv1UaKWs6UVKwcxIihSA,2198016
3
+ tf_project-0.3.0rc1.dist-info/METADATA,sha256=xO4-571558EC55NJIF6ObNI9e8hmfp2i4Iw2JbWxKD4,18315
4
+ tf_project-0.3.0rc1.dist-info/WHEEL,sha256=Uvw7WSmy7Kj2FBk8Va4L_dq4MDW8X5Ynby-pOX3ZNS0,94
5
+ tf_project-0.3.0rc1.dist-info/licenses/LICENSE,sha256=fj5jROMpgfAV65ibRYz7cEAlmtRMhscZCYmTGLRW5U0,1089
6
+ tf_project-0.3.0rc1.dist-info/sboms/tf-project.cyclonedx.json,sha256=VC53r1I5nL4GhIOMcp5qnekfVfTndNIkFjXH_zN3nUg,68711
7
+ tf_project-0.3.0rc1.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.