tf-project 0.2.2__tar.gz → 0.3.0__tar.gz
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.
- {tf_project-0.2.2 → tf_project-0.3.0}/PKG-INFO +79 -71
- {tf_project-0.2.2 → tf_project-0.3.0}/README.md +64 -51
- tf_project-0.3.0/pyproject.toml +70 -0
- tf_project-0.3.0/rust/.config/nextest.toml +6 -0
- tf_project-0.3.0/rust/Cargo.lock +693 -0
- tf_project-0.3.0/rust/Cargo.toml +55 -0
- tf_project-0.3.0/rust/clippy.toml +9 -0
- tf_project-0.3.0/rust/deny.toml +21 -0
- tf_project-0.3.0/rust/rust-toolchain.toml +3 -0
- tf_project-0.3.0/rust/rustfmt.toml +2 -0
- tf_project-0.3.0/rust/src/banner.rs +247 -0
- tf_project-0.3.0/rust/src/bin/tfp.rs +5 -0
- tf_project-0.3.0/rust/src/cli.rs +1671 -0
- tf_project-0.3.0/rust/src/commands.rs +1129 -0
- tf_project-0.3.0/rust/src/config.rs +469 -0
- tf_project-0.3.0/rust/src/lib.rs +288 -0
- tf_project-0.3.0/rust/src/lock.rs +445 -0
- tf_project-0.3.0/rust/src/main.rs +5 -0
- tf_project-0.3.0/rust/src/models.rs +383 -0
- tf_project-0.3.0/rust/src/secrets.rs +142 -0
- tf_project-0.3.0/rust/src/self_commands.rs +592 -0
- tf_project-0.3.0/rust/src/slots.rs +366 -0
- tf_project-0.3.0/rust/src/state.rs +168 -0
- tf_project-0.3.0/rust/src/terraform.rs +210 -0
- tf_project-0.3.0/rust/src/text.rs +49 -0
- tf_project-0.3.0/rust/tests/cli.rs +100 -0
- tf_project-0.3.0/rust/tests/fixtures/last_invocation.json +9 -0
- tf_project-0.3.0/rust/tests/fixtures/my_state.json +16 -0
- tf_project-0.3.0/rust/tests/fixtures/tfplan_meta.json +10 -0
- tf_project-0.2.2/CHANGELOG.md +0 -224
- tf_project-0.2.2/pyproject.toml +0 -248
- tf_project-0.2.2/src/tf_project/__init__.py +0 -18
- tf_project-0.2.2/src/tf_project/__main__.py +0 -4
- tf_project-0.2.2/src/tf_project/__version__.py +0 -20
- tf_project-0.2.2/src/tf_project/banner.py +0 -134
- tf_project-0.2.2/src/tf_project/cli.py +0 -875
- tf_project-0.2.2/src/tf_project/commands.py +0 -864
- tf_project-0.2.2/src/tf_project/config.py +0 -294
- tf_project-0.2.2/src/tf_project/lock.py +0 -281
- tf_project-0.2.2/src/tf_project/migrate.py +0 -142
- tf_project-0.2.2/src/tf_project/models.py +0 -201
- tf_project-0.2.2/src/tf_project/preflight.py +0 -65
- tf_project-0.2.2/src/tf_project/py.typed +0 -0
- tf_project-0.2.2/src/tf_project/secrets.py +0 -78
- tf_project-0.2.2/src/tf_project/self_commands.py +0 -723
- tf_project-0.2.2/src/tf_project/slots.py +0 -256
- tf_project-0.2.2/src/tf_project/state.py +0 -135
- tf_project-0.2.2/src/tf_project/terraform.py +0 -176
- {tf_project-0.2.2 → tf_project-0.3.0}/LICENSE +0 -0
|
@@ -1,42 +1,35 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tf-project
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Terraform / OpenTofu wrapper with named per-tfvars slots, cached `.terraform/`, 1Password secret injection, and apply-safety guards.
|
|
5
|
-
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
|
|
6
|
-
Author-Email: Ilja Orlovs <ilja@release.art>
|
|
7
|
-
Maintainer-Email: Ilja Orlovs <ilja@release.art>
|
|
8
|
-
License-Expression: MIT
|
|
3
|
+
Version: 0.3.0
|
|
9
4
|
Classifier: Development Status :: 4 - Beta
|
|
10
5
|
Classifier: Environment :: Console
|
|
11
6
|
Classifier: Intended Audience :: Developers
|
|
12
7
|
Classifier: Intended Audience :: System Administrators
|
|
13
|
-
Classifier: Operating System :: POSIX
|
|
14
8
|
Classifier: Operating System :: MacOS
|
|
15
|
-
Classifier:
|
|
16
|
-
Classifier:
|
|
17
|
-
Classifier: Programming Language ::
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
9
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Rust
|
|
20
12
|
Classifier: Topic :: Software Development :: Build Tools
|
|
21
13
|
Classifier: Topic :: System :: Installation/Setup
|
|
22
14
|
Classifier: Topic :: System :: Systems Administration
|
|
23
15
|
Classifier: Topic :: Utilities
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
28
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
|
|
29
26
|
Project-URL: Issues, https://github.com/release-art/tf-project/issues
|
|
30
27
|
Project-URL: Releases, https://github.com/release-art/tf-project/releases
|
|
31
|
-
|
|
32
|
-
Requires-Dist: typer>=0.21.2
|
|
33
|
-
Requires-Dist: pydantic>=2.13.4
|
|
34
|
-
Description-Content-Type: text/markdown
|
|
28
|
+
Project-URL: Repository, https://github.com/release-art/tf-project
|
|
35
29
|
|
|
36
30
|
# tf-project
|
|
37
31
|
|
|
38
32
|
[](https://pypi.org/project/tf-project/)
|
|
39
|
-
[](https://pypi.org/project/tf-project/)
|
|
40
33
|
[](https://github.com/release-art/tf-project/blob/main/LICENSE)
|
|
41
34
|
|
|
42
35
|
A thin, opinionated **Terraform / OpenTofu** wrapper for multi-environment
|
|
@@ -56,9 +49,9 @@ time you switch, this tool replaces that ritual with `tfp use dev`.
|
|
|
56
49
|
swapping between them is instant when both are warm.
|
|
57
50
|
- **Shared provider cache** via `TF_PLUGIN_CACHE_DIR`. Providers download
|
|
58
51
|
once and link into every slot's `.terraform/providers/`.
|
|
59
|
-
- **Versioned,
|
|
52
|
+
- **Versioned, strictly validated state files.** Every persisted JSON carries
|
|
60
53
|
`schema_version`; unknown fields fail loudly (except in user-authored
|
|
61
|
-
banners, where they are tolerated and
|
|
54
|
+
banners, where they are tolerated and reported by `tfp self banner check`).
|
|
62
55
|
- Pluggable tfvars preprocessing - defaults to [1Password's `op inject`][op]
|
|
63
56
|
so you can keep `op://...` references in tfvars committed to git.
|
|
64
57
|
|
|
@@ -67,10 +60,19 @@ time you switch, this tool replaces that ritual with `tfp use dev`.
|
|
|
67
60
|
## Install
|
|
68
61
|
|
|
69
62
|
```sh
|
|
70
|
-
pip install tf-project
|
|
63
|
+
pip install tf-project # or: uv tool install tf-project / pipx install tf-project
|
|
71
64
|
```
|
|
72
65
|
|
|
73
|
-
The CLI is exposed as both `tf-project` and the shorter alias `tfp`.
|
|
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
|
|
74
76
|
|
|
75
77
|
## Configure
|
|
76
78
|
|
|
@@ -92,7 +94,8 @@ tfvars_dir = "tfvars" # scanned for slots; used by `tfp fmt`
|
|
|
92
94
|
tmp_dir = "tmp" # slot dirs + plugin cache land here
|
|
93
95
|
state_key_prefix = "terraform/azure/" # remote backend key prefix
|
|
94
96
|
|
|
95
|
-
# Optional. Defaults to `
|
|
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.
|
|
96
99
|
# terraform_binary = "bin/terraform-1.7.5"
|
|
97
100
|
|
|
98
101
|
# Optional. Defaults to `<tmp_dir>/plugin-cache`. Set to "" to disable.
|
|
@@ -135,18 +138,20 @@ Banner fields:
|
|
|
135
138
|
| `header` | Must be `"terraform"`. Identifies the comment line as a tf-project banner. |
|
|
136
139
|
| `project` | Subdirectory under `terraform_dir/` containing the source `.tf` files. |
|
|
137
140
|
| `slot` | Slot name. Defaults to the tfvars filename stem. Must be unique across all tfvars in `tfvars_dir`. |
|
|
138
|
-
| `state_key` | Full remote-state backend key. Overrides the default `<state_key_prefix><tfvars-stem>.tfstate`. Use to share state across files.
|
|
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. |
|
|
139
142
|
| `env` | JSON object of `string → string` env vars passed to terraform when running against this slot. |
|
|
140
143
|
| `backend_config` | JSON object of extra `-backend-config k=v` pairs. Wins over the config-level `[tf_project.backend_config]` table. |
|
|
141
144
|
|
|
142
|
-
Unknown banner fields are tolerated (forward-compatible across tfp versions)
|
|
143
|
-
|
|
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.
|
|
144
147
|
|
|
145
148
|
## Usage
|
|
146
149
|
|
|
147
150
|
```sh
|
|
148
151
|
tfp use dev # switch to slot "dev" (no init if already warm)
|
|
149
|
-
tfp use tfvars/prod.tfvars #
|
|
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)
|
|
150
155
|
tfp ls # list slots; active marked with `*`
|
|
151
156
|
tfp rm staging # remove a slot's on-disk directory
|
|
152
157
|
|
|
@@ -168,7 +173,7 @@ tfp state replace-provider hashicorp/aws registry.acme.local/aws
|
|
|
168
173
|
tfp state identities # 1.10+
|
|
169
174
|
tfp import aws_s3_bucket.foo my-bucket
|
|
170
175
|
# forwards the decrypted tfvars + saved env
|
|
171
|
-
tfp status #
|
|
176
|
+
tfp status # summary of the active slot
|
|
172
177
|
tfp last # last terraform invocation for the active slot
|
|
173
178
|
```
|
|
174
179
|
|
|
@@ -190,10 +195,13 @@ tfp use prod # writes tmp/active (affects all shells without
|
|
|
190
195
|
|
|
191
196
|
### Global flags
|
|
192
197
|
|
|
193
|
-
- `--verbose` - echo the terraform argv to stderr before
|
|
194
|
-
- `--dry-run` - print the argv and
|
|
198
|
+
- `--verbose` - echo the terraform argv to stderr before running it.
|
|
199
|
+
- `--dry-run` - print the argv and run nothing.
|
|
195
200
|
- `-s/--slot <name>` - operate against a specific slot for one invocation.
|
|
196
201
|
|
|
202
|
+
`--verbose` and `--dry-run` are accepted anywhere before a `--`; `-s` goes
|
|
203
|
+
before the subcommand.
|
|
204
|
+
|
|
197
205
|
```sh
|
|
198
206
|
tfp --dry-run plan -t module.foo
|
|
199
207
|
tfp -s prod --verbose apply
|
|
@@ -241,7 +249,7 @@ stale lock on the tfstate. Subsequent runs fail with "state locked".
|
|
|
241
249
|
```sh
|
|
242
250
|
tfp self lock status # lease + lock metadata (exits 2 if locked)
|
|
243
251
|
tfp self lock break # break the lock (prompts for confirmation; -y to skip)
|
|
244
|
-
tfp force-unlock <LOCK_ID>
|
|
252
|
+
tfp tf force-unlock <LOCK_ID> # backend-agnostic, via `tfp tf`
|
|
245
253
|
```
|
|
246
254
|
|
|
247
255
|
`tfp self lock` auto-detects the backend from the active slot's saved state:
|
|
@@ -288,24 +296,27 @@ banner's `project`, `state_key`, `backend_config`, and `env`. `tfp apply`
|
|
|
288
296
|
refuses to run if any of those drift between plan and apply. Pass
|
|
289
297
|
`--force` to override.
|
|
290
298
|
|
|
291
|
-
###
|
|
299
|
+
### Any other Terraform command: `tfp tf`
|
|
292
300
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
slot
|
|
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:
|
|
296
304
|
|
|
297
305
|
```sh
|
|
298
|
-
tfp validate
|
|
299
|
-
tfp workspace list
|
|
300
|
-
tfp providers schema -json
|
|
301
|
-
tfp version
|
|
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
|
|
302
310
|
```
|
|
303
311
|
|
|
304
|
-
|
|
305
|
-
|
|
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:
|
|
306
317
|
|
|
307
318
|
```sh
|
|
308
|
-
tfp plan -t module.foo
|
|
319
|
+
tfp plan -t module.foo -detailed-exitcode -compact-warnings
|
|
309
320
|
tfp apply -- -parallelism=20
|
|
310
321
|
```
|
|
311
322
|
|
|
@@ -324,52 +335,48 @@ tfp self banner check <tfvars> # validate a banner; print resolved slot + f
|
|
|
324
335
|
tfp self snapshot create # `terraform state pull` to <tmp_dir>/snapshots/<slot>/<ts>-manual.tfstate
|
|
325
336
|
tfp self snapshot list # list snapshots for the active slot, newest first
|
|
326
337
|
tfp self snapshot restore [<name>] # `terraform state push -force` the named snapshot (default: newest)
|
|
327
|
-
tfp self trace <subcommand> # print the argv tfp would build;
|
|
338
|
+
tfp self trace <subcommand> # print the argv tfp would build; runs nothing
|
|
328
339
|
tfp self lock status # remote-state lock state (azurerm or s3+dynamodb)
|
|
329
340
|
tfp self lock break # polite-by-default release; --blunt skips terraform
|
|
330
341
|
tfp self providers lock # cross-platform `terraform providers lock`
|
|
331
|
-
tfp force-unlock <LOCK_ID>
|
|
342
|
+
tfp tf force-unlock <LOCK_ID> # backend-agnostic, via `tfp tf`
|
|
332
343
|
```
|
|
333
344
|
|
|
334
|
-
## Migrating from a pre-slot install
|
|
335
|
-
|
|
336
|
-
The first time you run any `tfp` command after upgrading, tf-project detects
|
|
337
|
-
the legacy `tmp/my_terraform_state.json` and promotes it into the new layout
|
|
338
|
-
under `tmp/slots/<slot>/`, sets `tmp/active`, and leaves a one-line
|
|
339
|
-
`tmp/MIGRATED-<UTC-timestamp>.txt` breadcrumb. The first command afterwards
|
|
340
|
-
will repopulate the slot's `.terraform/` from the plugin cache.
|
|
341
|
-
|
|
342
|
-
If the legacy state references a tfvars that has since moved or been deleted,
|
|
343
|
-
migration logs a warning, deletes the legacy file, and asks you to run
|
|
344
|
-
`tfp use <slot>` to start fresh.
|
|
345
|
-
|
|
346
345
|
## Development
|
|
347
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
|
+
|
|
348
351
|
```sh
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
pdm run pytest -m integration # smoke tests (need `terraform` on PATH)
|
|
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)
|
|
354
356
|
```
|
|
355
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
|
+
|
|
356
362
|
## Release
|
|
357
363
|
|
|
358
364
|
Releases are **tag-driven**. The wheel's version comes from the git tag,
|
|
359
|
-
not a code edit
|
|
360
|
-
|
|
361
|
-
bump.
|
|
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.
|
|
362
367
|
|
|
363
368
|
1. Move the `## [Unreleased]` block in `CHANGELOG.md` under a new
|
|
364
369
|
`## [X.Y.Z] - YYYY-MM-DD` heading. Commit to `main`.
|
|
365
370
|
2. Tag the commit: `git tag vX.Y.Z && git push origin vX.Y.Z`.
|
|
366
371
|
3. The **Release** workflow fires on the tag push:
|
|
367
372
|
- Re-runs CI against the tagged commit.
|
|
368
|
-
- Builds
|
|
369
|
-
|
|
370
|
-
-
|
|
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.
|
|
371
377
|
- Creates a GitHub Release with the extracted changelog section and the
|
|
372
|
-
signed artifacts
|
|
378
|
+
signed artifacts attached: the wheels and sdist, plus each platform's
|
|
379
|
+
programs as a standalone `.tar.gz` / `.zip` (`bin/rust/archive.py`).
|
|
373
380
|
|
|
374
381
|
Tags carrying `rc` / `a` / `b` / `dev` suffixes (e.g. `v1.0.0rc1`) are
|
|
375
382
|
auto-marked as pre-releases on GitHub.
|
|
@@ -379,3 +386,4 @@ PyPI trusted-publishing is a one-time setup on
|
|
|
379
386
|
`release` GitHub Environment.
|
|
380
387
|
|
|
381
388
|
[sigstore]: https://www.sigstore.dev/
|
|
389
|
+
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# tf-project
|
|
2
2
|
|
|
3
3
|
[](https://pypi.org/project/tf-project/)
|
|
4
|
-
[](https://pypi.org/project/tf-project/)
|
|
5
4
|
[](https://github.com/release-art/tf-project/blob/main/LICENSE)
|
|
6
5
|
|
|
7
6
|
A thin, opinionated **Terraform / OpenTofu** wrapper for multi-environment
|
|
@@ -21,9 +20,9 @@ time you switch, this tool replaces that ritual with `tfp use dev`.
|
|
|
21
20
|
swapping between them is instant when both are warm.
|
|
22
21
|
- **Shared provider cache** via `TF_PLUGIN_CACHE_DIR`. Providers download
|
|
23
22
|
once and link into every slot's `.terraform/providers/`.
|
|
24
|
-
- **Versioned,
|
|
23
|
+
- **Versioned, strictly validated state files.** Every persisted JSON carries
|
|
25
24
|
`schema_version`; unknown fields fail loudly (except in user-authored
|
|
26
|
-
banners, where they are tolerated and
|
|
25
|
+
banners, where they are tolerated and reported by `tfp self banner check`).
|
|
27
26
|
- Pluggable tfvars preprocessing - defaults to [1Password's `op inject`][op]
|
|
28
27
|
so you can keep `op://...` references in tfvars committed to git.
|
|
29
28
|
|
|
@@ -32,10 +31,19 @@ time you switch, this tool replaces that ritual with `tfp use dev`.
|
|
|
32
31
|
## Install
|
|
33
32
|
|
|
34
33
|
```sh
|
|
35
|
-
pip install tf-project
|
|
34
|
+
pip install tf-project # or: uv tool install tf-project / pipx install tf-project
|
|
36
35
|
```
|
|
37
36
|
|
|
38
|
-
The CLI is exposed as both `tf-project` and the shorter alias `tfp`.
|
|
37
|
+
The CLI is exposed as both `tf-project` and the shorter alias `tfp`. It is a
|
|
38
|
+
single native program; the PyPI wheels (Linux x86_64 / arm64, macOS arm64,
|
|
39
|
+
Windows x86_64) contain nothing else.
|
|
40
|
+
|
|
41
|
+
To install without Python, download
|
|
42
|
+
`tf-project-<version>-<target>.tar.gz` (`.zip` for Windows) from a
|
|
43
|
+
[GitHub Release][releases] and put `tfp` / `tf-project` on your `PATH`. Every
|
|
44
|
+
release file is signed with [Sigstore][sigstore].
|
|
45
|
+
|
|
46
|
+
[releases]: https://github.com/release-art/tf-project/releases
|
|
39
47
|
|
|
40
48
|
## Configure
|
|
41
49
|
|
|
@@ -57,7 +65,8 @@ tfvars_dir = "tfvars" # scanned for slots; used by `tfp fmt`
|
|
|
57
65
|
tmp_dir = "tmp" # slot dirs + plugin cache land here
|
|
58
66
|
state_key_prefix = "terraform/azure/" # remote backend key prefix
|
|
59
67
|
|
|
60
|
-
# Optional. Defaults to `
|
|
68
|
+
# Optional. Defaults to `terraform` as found on PATH. A bare name (`tofu`) is
|
|
69
|
+
# looked up on PATH when run; a path is taken relative to the project root.
|
|
61
70
|
# terraform_binary = "bin/terraform-1.7.5"
|
|
62
71
|
|
|
63
72
|
# Optional. Defaults to `<tmp_dir>/plugin-cache`. Set to "" to disable.
|
|
@@ -100,18 +109,20 @@ Banner fields:
|
|
|
100
109
|
| `header` | Must be `"terraform"`. Identifies the comment line as a tf-project banner. |
|
|
101
110
|
| `project` | Subdirectory under `terraform_dir/` containing the source `.tf` files. |
|
|
102
111
|
| `slot` | Slot name. Defaults to the tfvars filename stem. Must be unique across all tfvars in `tfvars_dir`. |
|
|
103
|
-
| `state_key` | Full remote-state backend key. Overrides the default `<state_key_prefix><tfvars-stem>.tfstate`. Use to share state across files.
|
|
112
|
+
| `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. |
|
|
104
113
|
| `env` | JSON object of `string → string` env vars passed to terraform when running against this slot. |
|
|
105
114
|
| `backend_config` | JSON object of extra `-backend-config k=v` pairs. Wins over the config-level `[tf_project.backend_config]` table. |
|
|
106
115
|
|
|
107
|
-
Unknown banner fields are tolerated (forward-compatible across tfp versions)
|
|
108
|
-
|
|
116
|
+
Unknown banner fields are tolerated (forward-compatible across tfp versions);
|
|
117
|
+
`tfp self banner check` names them, so a typo doesn't disappear silently.
|
|
109
118
|
|
|
110
119
|
## Usage
|
|
111
120
|
|
|
112
121
|
```sh
|
|
113
122
|
tfp use dev # switch to slot "dev" (no init if already warm)
|
|
114
|
-
tfp use tfvars/prod.tfvars #
|
|
123
|
+
tfp use tfvars/prod.tfvars # a tfvars path works too
|
|
124
|
+
tfp init # re-bind the active slot's backend from its banner
|
|
125
|
+
# (run after editing a banner's state_key/backend_config)
|
|
115
126
|
tfp ls # list slots; active marked with `*`
|
|
116
127
|
tfp rm staging # remove a slot's on-disk directory
|
|
117
128
|
|
|
@@ -133,7 +144,7 @@ tfp state replace-provider hashicorp/aws registry.acme.local/aws
|
|
|
133
144
|
tfp state identities # 1.10+
|
|
134
145
|
tfp import aws_s3_bucket.foo my-bucket
|
|
135
146
|
# forwards the decrypted tfvars + saved env
|
|
136
|
-
tfp status #
|
|
147
|
+
tfp status # summary of the active slot
|
|
137
148
|
tfp last # last terraform invocation for the active slot
|
|
138
149
|
```
|
|
139
150
|
|
|
@@ -155,10 +166,13 @@ tfp use prod # writes tmp/active (affects all shells without
|
|
|
155
166
|
|
|
156
167
|
### Global flags
|
|
157
168
|
|
|
158
|
-
- `--verbose` - echo the terraform argv to stderr before
|
|
159
|
-
- `--dry-run` - print the argv and
|
|
169
|
+
- `--verbose` - echo the terraform argv to stderr before running it.
|
|
170
|
+
- `--dry-run` - print the argv and run nothing.
|
|
160
171
|
- `-s/--slot <name>` - operate against a specific slot for one invocation.
|
|
161
172
|
|
|
173
|
+
`--verbose` and `--dry-run` are accepted anywhere before a `--`; `-s` goes
|
|
174
|
+
before the subcommand.
|
|
175
|
+
|
|
162
176
|
```sh
|
|
163
177
|
tfp --dry-run plan -t module.foo
|
|
164
178
|
tfp -s prod --verbose apply
|
|
@@ -206,7 +220,7 @@ stale lock on the tfstate. Subsequent runs fail with "state locked".
|
|
|
206
220
|
```sh
|
|
207
221
|
tfp self lock status # lease + lock metadata (exits 2 if locked)
|
|
208
222
|
tfp self lock break # break the lock (prompts for confirmation; -y to skip)
|
|
209
|
-
tfp force-unlock <LOCK_ID>
|
|
223
|
+
tfp tf force-unlock <LOCK_ID> # backend-agnostic, via `tfp tf`
|
|
210
224
|
```
|
|
211
225
|
|
|
212
226
|
`tfp self lock` auto-detects the backend from the active slot's saved state:
|
|
@@ -253,24 +267,27 @@ banner's `project`, `state_key`, `backend_config`, and `env`. `tfp apply`
|
|
|
253
267
|
refuses to run if any of those drift between plan and apply. Pass
|
|
254
268
|
`--force` to override.
|
|
255
269
|
|
|
256
|
-
###
|
|
270
|
+
### Any other Terraform command: `tfp tf`
|
|
257
271
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
slot
|
|
272
|
+
`tfp tf ...` runs any Terraform command verbatim in the active slot, prefixed
|
|
273
|
+
with `-chdir=<source_root>` and the env from the slot's saved state. With no
|
|
274
|
+
active slot it runs Terraform as is:
|
|
261
275
|
|
|
262
276
|
```sh
|
|
263
|
-
tfp validate
|
|
264
|
-
tfp workspace list
|
|
265
|
-
tfp providers schema -json
|
|
266
|
-
tfp version
|
|
277
|
+
tfp tf validate # terraform -chdir=... validate
|
|
278
|
+
tfp tf workspace list # per-slot workspace state via TF_DATA_DIR
|
|
279
|
+
tfp tf providers schema -json
|
|
280
|
+
tfp tf version # works without an active slot
|
|
267
281
|
```
|
|
268
282
|
|
|
269
|
-
|
|
270
|
-
|
|
283
|
+
Only the subcommands listed in this README are wrapped; every other
|
|
284
|
+
Terraform command goes through `tfp tf`.
|
|
285
|
+
|
|
286
|
+
Wrapped subcommands accept Terraform's own flags anywhere after the
|
|
287
|
+
subcommand, appended to the underlying invocation; `--` works too:
|
|
271
288
|
|
|
272
289
|
```sh
|
|
273
|
-
tfp plan -t module.foo
|
|
290
|
+
tfp plan -t module.foo -detailed-exitcode -compact-warnings
|
|
274
291
|
tfp apply -- -parallelism=20
|
|
275
292
|
```
|
|
276
293
|
|
|
@@ -289,52 +306,48 @@ tfp self banner check <tfvars> # validate a banner; print resolved slot + f
|
|
|
289
306
|
tfp self snapshot create # `terraform state pull` to <tmp_dir>/snapshots/<slot>/<ts>-manual.tfstate
|
|
290
307
|
tfp self snapshot list # list snapshots for the active slot, newest first
|
|
291
308
|
tfp self snapshot restore [<name>] # `terraform state push -force` the named snapshot (default: newest)
|
|
292
|
-
tfp self trace <subcommand> # print the argv tfp would build;
|
|
309
|
+
tfp self trace <subcommand> # print the argv tfp would build; runs nothing
|
|
293
310
|
tfp self lock status # remote-state lock state (azurerm or s3+dynamodb)
|
|
294
311
|
tfp self lock break # polite-by-default release; --blunt skips terraform
|
|
295
312
|
tfp self providers lock # cross-platform `terraform providers lock`
|
|
296
|
-
tfp force-unlock <LOCK_ID>
|
|
313
|
+
tfp tf force-unlock <LOCK_ID> # backend-agnostic, via `tfp tf`
|
|
297
314
|
```
|
|
298
315
|
|
|
299
|
-
## Migrating from a pre-slot install
|
|
300
|
-
|
|
301
|
-
The first time you run any `tfp` command after upgrading, tf-project detects
|
|
302
|
-
the legacy `tmp/my_terraform_state.json` and promotes it into the new layout
|
|
303
|
-
under `tmp/slots/<slot>/`, sets `tmp/active`, and leaves a one-line
|
|
304
|
-
`tmp/MIGRATED-<UTC-timestamp>.txt` breadcrumb. The first command afterwards
|
|
305
|
-
will repopulate the slot's `.terraform/` from the plugin cache.
|
|
306
|
-
|
|
307
|
-
If the legacy state references a tfvars that has since moved or been deleted,
|
|
308
|
-
migration logs a warning, deletes the legacy file, and asks you to run
|
|
309
|
-
`tfp use <slot>` to start fresh.
|
|
310
|
-
|
|
311
316
|
## Development
|
|
312
317
|
|
|
318
|
+
The program lives in `rust/`. You need the toolchain pinned in
|
|
319
|
+
`rust/rust-toolchain.toml` (rustup installs it on first use) plus
|
|
320
|
+
`cargo-nextest`, `cargo-llvm-cov` and `cargo-deny`.
|
|
321
|
+
|
|
313
322
|
```sh
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
pdm run pytest -m integration # smoke tests (need `terraform` on PATH)
|
|
323
|
+
bin/rust/check.sh # fmt, clippy, docs, licences, tests, 100% coverage
|
|
324
|
+
bin/rust/check.sh --fix # format and apply clippy's fixes first
|
|
325
|
+
bin/run.sh status # run tfp from the source tree
|
|
326
|
+
pip install . # build and install the wheel locally (maturin)
|
|
319
327
|
```
|
|
320
328
|
|
|
329
|
+
Tests use fake `terraform` / `az` / `aws` scripts, so they run on macOS and
|
|
330
|
+
Linux without any of those installed. Run them with nextest (as check.sh
|
|
331
|
+
does): each test gets its own process.
|
|
332
|
+
|
|
321
333
|
## Release
|
|
322
334
|
|
|
323
335
|
Releases are **tag-driven**. The wheel's version comes from the git tag,
|
|
324
|
-
not a code edit
|
|
325
|
-
|
|
326
|
-
bump.
|
|
336
|
+
not a code edit: `rust/Cargo.toml` says `0.0.0`, and the release workflow
|
|
337
|
+
writes the tag into it (`bin/rust/set-version.sh`) before building.
|
|
327
338
|
|
|
328
339
|
1. Move the `## [Unreleased]` block in `CHANGELOG.md` under a new
|
|
329
340
|
`## [X.Y.Z] - YYYY-MM-DD` heading. Commit to `main`.
|
|
330
341
|
2. Tag the commit: `git tag vX.Y.Z && git push origin vX.Y.Z`.
|
|
331
342
|
3. The **Release** workflow fires on the tag push:
|
|
332
343
|
- Re-runs CI against the tagged commit.
|
|
333
|
-
- Builds
|
|
334
|
-
|
|
335
|
-
-
|
|
344
|
+
- Builds a wheel per platform (Linux x86_64 + arm64, macOS arm64,
|
|
345
|
+
Windows x86_64) and the sdist, with the version set from the tag.
|
|
346
|
+
- Signs everything with [Sigstore][sigstore] (keyless, transparency-logged).
|
|
347
|
+
- Publishes to PyPI via OIDC trusted publishing.
|
|
336
348
|
- Creates a GitHub Release with the extracted changelog section and the
|
|
337
|
-
signed artifacts
|
|
349
|
+
signed artifacts attached: the wheels and sdist, plus each platform's
|
|
350
|
+
programs as a standalone `.tar.gz` / `.zip` (`bin/rust/archive.py`).
|
|
338
351
|
|
|
339
352
|
Tags carrying `rc` / `a` / `b` / `dev` suffixes (e.g. `v1.0.0rc1`) are
|
|
340
353
|
auto-marked as pre-releases on GitHub.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
# PEP 621 project metadata
|
|
3
|
+
# See https://www.python.org/dev/peps/pep-0621/
|
|
4
|
+
name = "tf-project"
|
|
5
|
+
description = "Terraform / OpenTofu wrapper with named per-tfvars slots, cached `.terraform/`, 1Password secret injection, and apply-safety guards."
|
|
6
|
+
keywords = [
|
|
7
|
+
"terraform",
|
|
8
|
+
"opentofu",
|
|
9
|
+
"tofu",
|
|
10
|
+
"infrastructure-as-code",
|
|
11
|
+
"iac",
|
|
12
|
+
"devops",
|
|
13
|
+
"cli",
|
|
14
|
+
"wrapper",
|
|
15
|
+
"tfvars",
|
|
16
|
+
"multi-environment",
|
|
17
|
+
"workspaces",
|
|
18
|
+
"1password",
|
|
19
|
+
"op-cli",
|
|
20
|
+
"secrets",
|
|
21
|
+
"azurerm",
|
|
22
|
+
"s3-backend",
|
|
23
|
+
"terraform-state",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
authors = [
|
|
27
|
+
{name = "Ilja Orlovs", email = "ilja@release.art"},
|
|
28
|
+
]
|
|
29
|
+
maintainers = [
|
|
30
|
+
{name = "Ilja Orlovs", email = "ilja@release.art"},
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
dynamic = ["version"]
|
|
34
|
+
|
|
35
|
+
license = "MIT"
|
|
36
|
+
|
|
37
|
+
readme = "README.md"
|
|
38
|
+
|
|
39
|
+
classifiers = [
|
|
40
|
+
"Development Status :: 4 - Beta",
|
|
41
|
+
"Environment :: Console",
|
|
42
|
+
"Intended Audience :: Developers",
|
|
43
|
+
"Intended Audience :: System Administrators",
|
|
44
|
+
"Operating System :: MacOS",
|
|
45
|
+
"Operating System :: Microsoft :: Windows",
|
|
46
|
+
"Operating System :: POSIX :: Linux",
|
|
47
|
+
"Programming Language :: Rust",
|
|
48
|
+
"Topic :: Software Development :: Build Tools",
|
|
49
|
+
"Topic :: System :: Installation/Setup",
|
|
50
|
+
"Topic :: System :: Systems Administration",
|
|
51
|
+
"Topic :: Utilities",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[project.urls]
|
|
55
|
+
Homepage = "https://github.com/release-art/tf-project"
|
|
56
|
+
Repository = "https://github.com/release-art/tf-project"
|
|
57
|
+
Documentation = "https://github.com/release-art/tf-project#readme"
|
|
58
|
+
Changelog = "https://github.com/release-art/tf-project/blob/main/CHANGELOG.md"
|
|
59
|
+
Issues = "https://github.com/release-art/tf-project/issues"
|
|
60
|
+
Releases = "https://github.com/release-art/tf-project/releases"
|
|
61
|
+
|
|
62
|
+
[build-system]
|
|
63
|
+
requires = ["maturin>=1.9.4,<2"]
|
|
64
|
+
build-backend = "maturin"
|
|
65
|
+
|
|
66
|
+
# The wheel holds the two programs `tf-project` and `tfp`, built from rust/ (no Python inside). Its version is
|
|
67
|
+
# rust/Cargo.toml's: 0.0.0 in the tree, set from the release tag (v1.2.3) by bin/rust/set-version.sh.
|
|
68
|
+
[tool.maturin]
|
|
69
|
+
manifest-path = "rust/Cargo.toml"
|
|
70
|
+
bindings = "bin"
|