tf-project 0.2.0__tar.gz → 0.2.1__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.0 → tf_project-0.2.1}/CHANGELOG.md +11 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/PKG-INFO +2 -2
- {tf_project-0.2.0 → tf_project-0.2.1}/README.md +1 -1
- {tf_project-0.2.0 → tf_project-0.2.1}/pyproject.toml +1 -1
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/cli.py +4 -1
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/commands.py +13 -0
- tf_project-0.2.1/src/tf_project/preflight.py +88 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/LICENSE +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/__init__.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/__main__.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/__version__.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/banner.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/config.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/lock.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/migrate.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/models.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/py.typed +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/secrets.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/self_commands.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/slots.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/state.py +0 -0
- {tf_project-0.2.0 → tf_project-0.2.1}/src/tf_project/terraform.py +0 -0
|
@@ -4,6 +4,17 @@ All notable changes to this project are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **Recovery preflight.** Wrapped commands now bail out with an actionable
|
|
11
|
+
message when on-disk state is half-deleted, instead of forwarding a
|
|
12
|
+
cryptic terraform error: a missing `.terraform/` data dir tells the user
|
|
13
|
+
to `tfp use <slot>`, and a half-deleted `tfplan`/`tfplan.meta.json` pair
|
|
14
|
+
tells the user to re-run `tfp plan`. `tfp use` additionally warns when
|
|
15
|
+
`.terraform.lock.hcl` is missing while the plugin cache is on, pointing
|
|
16
|
+
at `tfp self providers lock` to repopulate cross-platform hashes.
|
|
17
|
+
|
|
7
18
|
## [0.2.0] — 2026-05-22
|
|
8
19
|
|
|
9
20
|
### Release pipeline
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tf-project
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Terraform / OpenTofu wrapper with named per-tfvars slots, cached `.terraform/`, 1Password secret injection, and apply-safety guards.
|
|
5
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
6
|
Author-Email: Ilja Orlovs <ilja@release.art>
|
|
@@ -37,7 +37,7 @@ Description-Content-Type: text/markdown
|
|
|
37
37
|
|
|
38
38
|
[](https://pypi.org/project/tf-project/)
|
|
39
39
|
[](https://pypi.org/project/tf-project/)
|
|
40
|
-
[](https://github.com/release-art/tf-project/blob/main/LICENSE)
|
|
41
41
|
|
|
42
42
|
A thin, opinionated **Terraform / OpenTofu** wrapper for multi-environment
|
|
43
43
|
projects. Provides a single `tf-project` (aka `tfp`) CLI built around
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://pypi.org/project/tf-project/)
|
|
4
4
|
[](https://pypi.org/project/tf-project/)
|
|
5
|
-
[](https://github.com/release-art/tf-project/blob/main/LICENSE)
|
|
6
6
|
|
|
7
7
|
A thin, opinionated **Terraform / OpenTofu** wrapper for multi-environment
|
|
8
8
|
projects. Provides a single `tf-project` (aka `tfp`) CLI built around
|
|
@@ -11,7 +11,7 @@ import click
|
|
|
11
11
|
import typer
|
|
12
12
|
from click.shell_completion import CompletionItem
|
|
13
13
|
|
|
14
|
-
from tf_project import banner, commands, migrate, self_commands, slots, terraform
|
|
14
|
+
from tf_project import banner, commands, migrate, preflight, self_commands, slots, terraform
|
|
15
15
|
from tf_project.__version__ import __version__
|
|
16
16
|
from tf_project.commands import WRAPPED_SUBCOMMANDS
|
|
17
17
|
from tf_project.config import Config, ConfigError
|
|
@@ -788,6 +788,9 @@ def main() -> None:
|
|
|
788
788
|
except commands.StaleTfplanError as exc:
|
|
789
789
|
typer.echo(str(exc), err=True)
|
|
790
790
|
sys.exit(1)
|
|
791
|
+
except preflight.RecoveryError as exc:
|
|
792
|
+
typer.echo(str(exc), err=True)
|
|
793
|
+
sys.exit(1)
|
|
791
794
|
except slots.SlotConflictError as exc:
|
|
792
795
|
typer.echo(str(exc), err=True)
|
|
793
796
|
sys.exit(1)
|
|
@@ -15,6 +15,7 @@ import sys
|
|
|
15
15
|
from collections.abc import Sequence
|
|
16
16
|
|
|
17
17
|
from tf_project import (
|
|
18
|
+
preflight,
|
|
18
19
|
slots as slots_mod,
|
|
19
20
|
terraform,
|
|
20
21
|
)
|
|
@@ -429,6 +430,9 @@ def do_use(config: Config, *, arg: str, extra: Sequence[str] | None = None) -> R
|
|
|
429
430
|
plugin_cache_dir.mkdir(parents=True, exist_ok=True)
|
|
430
431
|
|
|
431
432
|
if decision.needs_init:
|
|
433
|
+
warning = preflight.dep_lock_warning(resolved.source_root, plugin_cache_enabled=plugin_cache_dir is not None)
|
|
434
|
+
if warning is not None:
|
|
435
|
+
print(f"warning: {warning}", file=sys.stderr)
|
|
432
436
|
print(f"==== PROJECT: {resolved.project} (slot {resolved.name!r}, {decision.reason}) ====")
|
|
433
437
|
try:
|
|
434
438
|
terraform.run(
|
|
@@ -508,6 +512,7 @@ def do_plan(
|
|
|
508
512
|
extra: Sequence[str] | None = None,
|
|
509
513
|
) -> None:
|
|
510
514
|
resolved, state, banner_present = _resolve_active_slot(config, flag=slot)
|
|
515
|
+
preflight.check_data_dir(config, state.slot)
|
|
511
516
|
with _provider(config).materialize(state.tfvars) as decrypted:
|
|
512
517
|
terraform.run(
|
|
513
518
|
build_plan_argv(
|
|
@@ -531,6 +536,8 @@ def do_apply(
|
|
|
531
536
|
extra: Sequence[str] | None = None,
|
|
532
537
|
) -> None:
|
|
533
538
|
resolved, state, banner_present = _resolve_active_slot(config, flag=slot)
|
|
539
|
+
preflight.check_data_dir(config, state.slot)
|
|
540
|
+
preflight.check_apply_plan(config, state.slot)
|
|
534
541
|
with try_exclusive_lock(_apply_lock_path(config, state.slot)):
|
|
535
542
|
with _provider(config).materialize(state.tfvars) as decrypted:
|
|
536
543
|
if not force:
|
|
@@ -557,6 +564,7 @@ def do_refresh(
|
|
|
557
564
|
extra: Sequence[str] | None = None,
|
|
558
565
|
) -> None:
|
|
559
566
|
_, state, _ = _resolve_active_slot(config, flag=slot)
|
|
567
|
+
preflight.check_data_dir(config, state.slot)
|
|
560
568
|
with try_exclusive_lock(_apply_lock_path(config, state.slot)):
|
|
561
569
|
with _provider(config).materialize(state.tfvars) as decrypted:
|
|
562
570
|
terraform.run(
|
|
@@ -573,6 +581,7 @@ def do_destroy(
|
|
|
573
581
|
extra: Sequence[str] | None = None,
|
|
574
582
|
) -> None:
|
|
575
583
|
_, state, _ = _resolve_active_slot(config, flag=slot)
|
|
584
|
+
preflight.check_data_dir(config, state.slot)
|
|
576
585
|
with try_exclusive_lock(_apply_lock_path(config, state.slot)):
|
|
577
586
|
with _provider(config).materialize(state.tfvars) as decrypted:
|
|
578
587
|
terraform.run(
|
|
@@ -599,6 +608,7 @@ def do_output(
|
|
|
599
608
|
extra: Sequence[str] | None = None,
|
|
600
609
|
) -> None:
|
|
601
610
|
_, state, _ = _resolve_active_slot(config, flag=slot)
|
|
611
|
+
preflight.check_data_dir(config, state.slot)
|
|
602
612
|
terraform.run(build_output_argv(config, state=state, extra=extra), env=_env_for(config, state))
|
|
603
613
|
|
|
604
614
|
|
|
@@ -611,6 +621,7 @@ def do_import(
|
|
|
611
621
|
extra: Sequence[str] | None = None,
|
|
612
622
|
) -> None:
|
|
613
623
|
_, state, _ = _resolve_active_slot(config, flag=slot)
|
|
624
|
+
preflight.check_data_dir(config, state.slot)
|
|
614
625
|
with _provider(config).materialize(state.tfvars) as decrypted:
|
|
615
626
|
terraform.run(
|
|
616
627
|
build_import_argv(
|
|
@@ -634,6 +645,7 @@ def do_state(
|
|
|
634
645
|
extra: Sequence[str] | None = None,
|
|
635
646
|
) -> None:
|
|
636
647
|
_, state, _ = _resolve_active_slot(config, flag=slot)
|
|
648
|
+
preflight.check_data_dir(config, state.slot)
|
|
637
649
|
terraform.run(
|
|
638
650
|
build_state_argv(config, state=state, subcommand=subcommand, args=args, extra=extra),
|
|
639
651
|
env=_env_for(config, state),
|
|
@@ -667,6 +679,7 @@ def do_passthrough(
|
|
|
667
679
|
# Use the same helper as the wrapped commands so the error message
|
|
668
680
|
# distinguishes "no such slot" from "slot exists, never inited".
|
|
669
681
|
state = _require_slot_state(config, active.name)
|
|
682
|
+
preflight.check_data_dir(config, state.slot)
|
|
670
683
|
cmd.append(f"-chdir={state.source_root}")
|
|
671
684
|
env = _env_for(config, state)
|
|
672
685
|
cmd.extend(args)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Pre-execution checks that turn predictable disk-state damage into
|
|
2
|
+
actionable recovery messages.
|
|
3
|
+
|
|
4
|
+
Catches things like a deleted `.terraform/` data dir or a half-deleted
|
|
5
|
+
`tfplan`/`tfplan.meta.json` pair — situations where terraform would
|
|
6
|
+
otherwise exit with a cryptic error and the user wouldn't know which
|
|
7
|
+
`tfp` command repairs the state.
|
|
8
|
+
|
|
9
|
+
`do_use` is the recovery entry point: every check that flags a missing
|
|
10
|
+
on-disk artifact suggests rerunning `tfp use <slot>`, which is the
|
|
11
|
+
single command that re-runs `terraform init` and rebuilds the wrapper's
|
|
12
|
+
sidecar files.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import pathlib
|
|
18
|
+
|
|
19
|
+
from tf_project.config import Config
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RecoveryError(RuntimeError):
|
|
23
|
+
"""A pre-flight check failed with a concrete recovery suggestion."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def check_data_dir(config: Config, slot: str) -> None:
|
|
27
|
+
"""Refuse to run terraform under a slot whose `.terraform/` is gone.
|
|
28
|
+
|
|
29
|
+
Mirrors the signal `_decide_init` uses: missing `.terraform/` means
|
|
30
|
+
terraform considers itself uninitialized, regardless of whether the
|
|
31
|
+
wrapper's `state.json` and `backend.hash` are still present.
|
|
32
|
+
"""
|
|
33
|
+
data_dir = config.data_dir_for(slot)
|
|
34
|
+
if not data_dir.is_dir():
|
|
35
|
+
raise RecoveryError(
|
|
36
|
+
f"slot {slot!r}: terraform data dir is missing at {data_dir}. "
|
|
37
|
+
f"It was probably deleted. Run `tfp use {slot}` to reinitialize."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def check_apply_plan(config: Config, slot: str) -> None:
|
|
42
|
+
"""Refuse `apply` if the saved plan or its safety sidecar is gone.
|
|
43
|
+
|
|
44
|
+
Both files are written together by `tfp plan` and removed together
|
|
45
|
+
by a successful `tfp apply`. A half-present pair means the user
|
|
46
|
+
deleted one by hand; running `apply` would either fail cryptically
|
|
47
|
+
(plan missing) or silently skip the apply-safety drift check (meta
|
|
48
|
+
missing). Force them to re-plan instead.
|
|
49
|
+
"""
|
|
50
|
+
plan = config.tfplan_file_for(slot)
|
|
51
|
+
meta = config.tfplan_meta_for(slot)
|
|
52
|
+
if not plan.exists() and not meta.exists():
|
|
53
|
+
raise RecoveryError(f"slot {slot!r}: no saved tfplan at {plan}. Run `tfp plan` first.")
|
|
54
|
+
if plan.exists() != meta.exists():
|
|
55
|
+
present = plan if plan.exists() else meta
|
|
56
|
+
missing = meta if plan.exists() else plan
|
|
57
|
+
raise RecoveryError(
|
|
58
|
+
f"slot {slot!r}: saved plan is half-deleted ({present.name} present, "
|
|
59
|
+
f"{missing.name} missing). Re-run `tfp plan` to regenerate both."
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def dep_lock_warning(source_root: pathlib.Path, *, plugin_cache_enabled: bool) -> str | None:
|
|
64
|
+
"""Return a heads-up if the dependency lock file is missing.
|
|
65
|
+
|
|
66
|
+
Not a hard error: terraform will regenerate `.terraform.lock.hcl` on
|
|
67
|
+
init. But with the plugin cache enabled the regenerated file only
|
|
68
|
+
carries hashes for the current platform, so we nudge the user to
|
|
69
|
+
re-run `tfp self providers lock` afterwards to repopulate the
|
|
70
|
+
cross-platform hashes they previously had.
|
|
71
|
+
"""
|
|
72
|
+
lock = source_root / ".terraform.lock.hcl"
|
|
73
|
+
if lock.exists() or not plugin_cache_enabled:
|
|
74
|
+
return None
|
|
75
|
+
return (
|
|
76
|
+
f".terraform.lock.hcl is missing under {source_root}. Terraform will "
|
|
77
|
+
f"regenerate it during init, but because the plugin cache is enabled "
|
|
78
|
+
f"the new file will only carry hashes for the current platform. Run "
|
|
79
|
+
f"`tfp self providers lock` afterwards to repopulate cross-platform hashes."
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
__all__ = [
|
|
84
|
+
"RecoveryError",
|
|
85
|
+
"check_apply_plan",
|
|
86
|
+
"check_data_dir",
|
|
87
|
+
"dep_lock_warning",
|
|
88
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|