tf-project 0.2.2__tar.gz → 0.2.3__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.2.3}/CHANGELOG.md +34 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/PKG-INFO +5 -3
- {tf_project-0.2.2 → tf_project-0.2.3}/README.md +3 -1
- {tf_project-0.2.2 → tf_project-0.2.3}/pyproject.toml +2 -2
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/banner.py +32 -2
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/cli.py +39 -15
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/commands.py +56 -9
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/self_commands.py +6 -5
- {tf_project-0.2.2 → tf_project-0.2.3}/LICENSE +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/__init__.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/__main__.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/__version__.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/config.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/lock.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/migrate.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/models.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/preflight.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/py.typed +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/secrets.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/slots.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/state.py +0 -0
- {tf_project-0.2.2 → tf_project-0.2.3}/src/tf_project/terraform.py +0 -0
|
@@ -4,6 +4,40 @@ 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
|
+
## [0.2.3] - 2026-06-26
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- **Raised the minimum `typer` to `>=0.26.0`** (was `>=0.21.2`). That series
|
|
11
|
+
vendors its own click fork (`typer._click`) and drops the standalone
|
|
12
|
+
`click` dependency. Shell-completion callbacks are now wired through
|
|
13
|
+
typer's native `autocompletion=` API returning `(value, help)` tuples, so
|
|
14
|
+
`tfp` no longer imports the `click` package directly - matching the
|
|
15
|
+
environment we lock and test against.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- **`tfp init` now re-binds the backend instead of reusing a stale one.**
|
|
19
|
+
Previously `tfp init` fell through to a bare `terraform init`, which
|
|
20
|
+
silently reused the backend already cached in `.terraform/` from the last
|
|
21
|
+
`tfp use` - so editing a banner's `state_key` / `backend_config` and
|
|
22
|
+
running `tfp init` left the slot pinned to the *old* remote state key
|
|
23
|
+
with no warning (and `tfp status` kept reporting the stale key). `init`
|
|
24
|
+
is now a wrapped command that re-resolves the live banner, runs
|
|
25
|
+
`terraform init -reconfigure` with the freshly-resolved `-backend-config`,
|
|
26
|
+
re-locks providers, and refreshes the saved slot state - the same backend
|
|
27
|
+
binding `tfp use` performs. Unlike `use`, it operates on the active slot
|
|
28
|
+
(honouring `-s` / `TFP_SLOT`) and does not move the active-slot pointer.
|
|
29
|
+
`tfp self trace init` traces the resulting argv.
|
|
30
|
+
- **Banner `state_key` must be an absolute, normalised pure POSIX path.**
|
|
31
|
+
tf-project is opinionated here: a `state_key` has to start with `/` and be
|
|
32
|
+
already normalised. Relative keys, backslashes, `.`/`..` segments,
|
|
33
|
+
redundant `//`, and trailing slashes are now rejected with a clear banner
|
|
34
|
+
error rather than silently rewritten - so the remote-state blob a banner
|
|
35
|
+
targets is unambiguous from the text alone. The one transformation applied
|
|
36
|
+
to a valid key is stripping its single leading slash: the azurerm backend
|
|
37
|
+
prepends the container name, so `/site-monitor.tfstate` previously produced
|
|
38
|
+
a double-slashed blob name (`.../tfstates//site-monitor.tfstate`) and now
|
|
39
|
+
resolves to `site-monitor.tfstate`.
|
|
40
|
+
|
|
7
41
|
## [0.2.2] - 2026-05-24
|
|
8
42
|
|
|
9
43
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tf-project
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
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>
|
|
@@ -29,7 +29,7 @@ Project-URL: Changelog, https://github.com/release-art/tf-project/blob/main/CHAN
|
|
|
29
29
|
Project-URL: Issues, https://github.com/release-art/tf-project/issues
|
|
30
30
|
Project-URL: Releases, https://github.com/release-art/tf-project/releases
|
|
31
31
|
Requires-Python: >=3.11
|
|
32
|
-
Requires-Dist: typer>=0.
|
|
32
|
+
Requires-Dist: typer>=0.26.0
|
|
33
33
|
Requires-Dist: pydantic>=2.13.4
|
|
34
34
|
Description-Content-Type: text/markdown
|
|
35
35
|
|
|
@@ -135,7 +135,7 @@ Banner fields:
|
|
|
135
135
|
| `header` | Must be `"terraform"`. Identifies the comment line as a tf-project banner. |
|
|
136
136
|
| `project` | Subdirectory under `terraform_dir/` containing the source `.tf` files. |
|
|
137
137
|
| `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.
|
|
138
|
+
| `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
139
|
| `env` | JSON object of `string → string` env vars passed to terraform when running against this slot. |
|
|
140
140
|
| `backend_config` | JSON object of extra `-backend-config k=v` pairs. Wins over the config-level `[tf_project.backend_config]` table. |
|
|
141
141
|
|
|
@@ -147,6 +147,8 @@ but logged to stderr - so a typo doesn't disappear silently.
|
|
|
147
147
|
```sh
|
|
148
148
|
tfp use dev # switch to slot "dev" (no init if already warm)
|
|
149
149
|
tfp use tfvars/prod.tfvars # path also accepted (useful with shell completion)
|
|
150
|
+
tfp init # re-bind the active slot's backend from its banner
|
|
151
|
+
# (run after editing a banner's state_key/backend_config)
|
|
150
152
|
tfp ls # list slots; active marked with `*`
|
|
151
153
|
tfp rm staging # remove a slot's on-disk directory
|
|
152
154
|
|
|
@@ -100,7 +100,7 @@ Banner fields:
|
|
|
100
100
|
| `header` | Must be `"terraform"`. Identifies the comment line as a tf-project banner. |
|
|
101
101
|
| `project` | Subdirectory under `terraform_dir/` containing the source `.tf` files. |
|
|
102
102
|
| `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.
|
|
103
|
+
| `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
104
|
| `env` | JSON object of `string → string` env vars passed to terraform when running against this slot. |
|
|
105
105
|
| `backend_config` | JSON object of extra `-backend-config k=v` pairs. Wins over the config-level `[tf_project.backend_config]` table. |
|
|
106
106
|
|
|
@@ -112,6 +112,8 @@ but logged to stderr - so a typo doesn't disappear silently.
|
|
|
112
112
|
```sh
|
|
113
113
|
tfp use dev # switch to slot "dev" (no init if already warm)
|
|
114
114
|
tfp use tfvars/prod.tfvars # path also accepted (useful with shell completion)
|
|
115
|
+
tfp init # re-bind the active slot's backend from its banner
|
|
116
|
+
# (run after editing a banner's state_key/backend_config)
|
|
115
117
|
tfp ls # list slots; active marked with `*`
|
|
116
118
|
tfp rm staging # remove a slot's on-disk directory
|
|
117
119
|
|
|
@@ -32,7 +32,7 @@ dynamic = []
|
|
|
32
32
|
requires-python = ">=3.11"
|
|
33
33
|
license = "MIT"
|
|
34
34
|
dependencies = [
|
|
35
|
-
"typer>=0.
|
|
35
|
+
"typer>=0.26.0",
|
|
36
36
|
"pydantic>=2.13.4",
|
|
37
37
|
]
|
|
38
38
|
readme = "README.md"
|
|
@@ -54,7 +54,7 @@ classifiers = [
|
|
|
54
54
|
"Topic :: Utilities",
|
|
55
55
|
"Typing :: Typed",
|
|
56
56
|
]
|
|
57
|
-
version = "0.2.
|
|
57
|
+
version = "0.2.3"
|
|
58
58
|
|
|
59
59
|
[project.scripts]
|
|
60
60
|
tf-project = "tf_project.cli:main"
|
|
@@ -81,7 +81,8 @@ def resolve_backend_config(
|
|
|
81
81
|
(only if `state_key_prefix` is set).
|
|
82
82
|
2. `[tf_project.backend_config]` from config.
|
|
83
83
|
3. `backend_config` from the banner.
|
|
84
|
-
4. `state_key` from the banner - final word on `key
|
|
84
|
+
4. `state_key` from the banner - final word on `key`, normalised via
|
|
85
|
+
`_normalize_state_key`.
|
|
85
86
|
"""
|
|
86
87
|
merged: dict[str, str] = {}
|
|
87
88
|
if config.state_key_prefix:
|
|
@@ -89,10 +90,39 @@ def resolve_backend_config(
|
|
|
89
90
|
merged.update(config.backend_config)
|
|
90
91
|
merged.update(banner.backend_config)
|
|
91
92
|
if banner.state_key is not None:
|
|
92
|
-
merged["key"] = banner.state_key
|
|
93
|
+
merged["key"] = _normalize_state_key(banner.state_key, tfvars=tfvars)
|
|
93
94
|
return merged
|
|
94
95
|
|
|
95
96
|
|
|
97
|
+
def _normalize_state_key(state_key: str, *, tfvars: pathlib.Path) -> str:
|
|
98
|
+
"""Validate a banner `state_key` and return the backend `key`.
|
|
99
|
+
|
|
100
|
+
tf-project is opinionated: a `state_key` MUST be an absolute, already-
|
|
101
|
+
normalised pure POSIX path. Anything else - a relative key, a backslash,
|
|
102
|
+
a `.`/`..` segment, a redundant `//`, or a trailing `/` - is rejected
|
|
103
|
+
rather than silently rewritten, so the remote-state blob a banner targets
|
|
104
|
+
is unambiguous from the text alone.
|
|
105
|
+
|
|
106
|
+
The one transformation applied to a valid key is stripping its single
|
|
107
|
+
leading slash: the azurerm backend prepends the container name to the
|
|
108
|
+
key, so a leading slash would produce a double-slashed blob name
|
|
109
|
+
(`.../tfstates//foo.tfstate`).
|
|
110
|
+
"""
|
|
111
|
+
if "\\" in state_key:
|
|
112
|
+
raise BannerError(tfvars, f"state_key {state_key!r} must be a pure POSIX path (no backslashes).")
|
|
113
|
+
if not state_key.startswith("/"):
|
|
114
|
+
raise BannerError(tfvars, f"state_key {state_key!r} must be an absolute POSIX path (start with '/').")
|
|
115
|
+
key = state_key[1:] # strip exactly one leading slash
|
|
116
|
+
if not key:
|
|
117
|
+
raise BannerError(tfvars, f"state_key {state_key!r} resolves to an empty backend key.")
|
|
118
|
+
pure = pathlib.PurePosixPath(key)
|
|
119
|
+
if any(seg in (".", "..") for seg in pure.parts):
|
|
120
|
+
raise BannerError(tfvars, f"state_key {state_key!r} must not contain '.' or '..' segments.")
|
|
121
|
+
if pure.is_absolute() or str(pure) != key:
|
|
122
|
+
raise BannerError(tfvars, f"state_key {state_key!r} must be a normalised path (no '//' or trailing '/').")
|
|
123
|
+
return key
|
|
124
|
+
|
|
125
|
+
|
|
96
126
|
def resolve_slot_name(banner: Banner, *, tfvars: pathlib.Path) -> tuple[str, bool]:
|
|
97
127
|
"""Return (slot_name, is_explicit). Defaults to tfvars stem if banner has no `slot`."""
|
|
98
128
|
if banner.slot is not None:
|
|
@@ -5,11 +5,9 @@ from __future__ import annotations
|
|
|
5
5
|
import json
|
|
6
6
|
import pathlib
|
|
7
7
|
import sys
|
|
8
|
-
from typing import Annotated
|
|
8
|
+
from typing import Annotated, NamedTuple
|
|
9
9
|
|
|
10
|
-
import click
|
|
11
10
|
import typer
|
|
12
|
-
from click.shell_completion import CompletionItem
|
|
13
11
|
|
|
14
12
|
from tf_project import banner, commands, migrate, preflight, self_commands, slots, terraform
|
|
15
13
|
from tf_project.__version__ import __version__
|
|
@@ -64,13 +62,25 @@ app = typer.Typer(
|
|
|
64
62
|
)
|
|
65
63
|
|
|
66
64
|
|
|
67
|
-
|
|
65
|
+
# Shell-completion callbacks, wired via typer's native `autocompletion=` (not
|
|
66
|
+
# click's `shell_complete=`, which typer deprecates). typer invokes each as
|
|
67
|
+
# `cb(ctx, args, incomplete)` and turns a returned `(value, help)` tuple into a
|
|
68
|
+
# completion with help text (typer/core.py). `_Completion` is that tuple as a
|
|
69
|
+
# NamedTuple, so the items also expose `.value` / `.help` for tests - and we
|
|
70
|
+
# avoid importing the standalone `click` package, which is not a dependency
|
|
71
|
+
# (typer vendors its own click as `typer._click`).
|
|
72
|
+
class _Completion(NamedTuple):
|
|
73
|
+
value: str
|
|
74
|
+
help: str
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _complete_tfvars(ctx: typer.Context, args: list[str], incomplete: str) -> list[_Completion]:
|
|
68
78
|
"""Tab-completion: list tfvars files under config.tfvars_dir, labelled by project."""
|
|
69
79
|
try:
|
|
70
80
|
cfg = Config.discover()
|
|
71
81
|
except Exception: # noqa: BLE001
|
|
72
82
|
return []
|
|
73
|
-
out: list[
|
|
83
|
+
out: list[_Completion] = []
|
|
74
84
|
if not cfg.tfvars_dir.is_dir():
|
|
75
85
|
return out
|
|
76
86
|
cwd = pathlib.Path.cwd()
|
|
@@ -86,26 +96,26 @@ def _complete_tfvars(ctx: click.Context, param: click.Parameter, incomplete: str
|
|
|
86
96
|
label = b.project
|
|
87
97
|
except (banner.ProjectInfoNotFoundError, banner.BannerError, OSError):
|
|
88
98
|
label = "(no banner)"
|
|
89
|
-
out.append(
|
|
99
|
+
out.append(_Completion(display, f"project={label}"))
|
|
90
100
|
return out
|
|
91
101
|
|
|
92
102
|
|
|
93
|
-
def _complete_slot(ctx:
|
|
103
|
+
def _complete_slot(ctx: typer.Context, args: list[str], incomplete: str) -> list[_Completion]:
|
|
94
104
|
"""Tab-completion: slot names from the tfvars dir."""
|
|
95
105
|
try:
|
|
96
106
|
cfg = Config.discover()
|
|
97
107
|
except Exception: # noqa: BLE001
|
|
98
108
|
return []
|
|
99
|
-
out: list[
|
|
109
|
+
out: list[_Completion] = []
|
|
100
110
|
for slot in slots.list_slots(cfg):
|
|
101
111
|
if slot.name.startswith(incomplete):
|
|
102
|
-
out.append(
|
|
112
|
+
out.append(_Completion(slot.name, f"project={slot.project}"))
|
|
103
113
|
return out
|
|
104
114
|
|
|
105
115
|
|
|
106
|
-
def _complete_use_arg(ctx:
|
|
116
|
+
def _complete_use_arg(ctx: typer.Context, args: list[str], incomplete: str) -> list[_Completion]:
|
|
107
117
|
"""Tab-completion for `tfp use`: slot names + tfvars paths."""
|
|
108
|
-
return _complete_slot(ctx,
|
|
118
|
+
return _complete_slot(ctx, args, incomplete) + _complete_tfvars(ctx, args, incomplete)
|
|
109
119
|
|
|
110
120
|
|
|
111
121
|
def _version_callback(value: bool) -> None:
|
|
@@ -123,7 +133,7 @@ def root(
|
|
|
123
133
|
"--slot",
|
|
124
134
|
"-s",
|
|
125
135
|
help="Operate against a specific slot for this invocation (does not change the saved active).",
|
|
126
|
-
|
|
136
|
+
autocompletion=_complete_slot,
|
|
127
137
|
),
|
|
128
138
|
] = None,
|
|
129
139
|
version: Annotated[
|
|
@@ -171,6 +181,20 @@ def use(
|
|
|
171
181
|
raise typer.Exit(code=1) from exc
|
|
172
182
|
|
|
173
183
|
|
|
184
|
+
@app.command(
|
|
185
|
+
"init",
|
|
186
|
+
context_settings=PASSTHROUGH_CTX,
|
|
187
|
+
help=(
|
|
188
|
+
"Re-resolve the active slot's banner and re-bind the backend "
|
|
189
|
+
"(terraform init -reconfigure with the banner's -backend-config), "
|
|
190
|
+
"refreshing the saved slot state. Run this after editing a banner's "
|
|
191
|
+
"state_key / backend_config. Does not change which slot is active."
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
def init(ctx: typer.Context) -> None:
|
|
195
|
+
commands.do_init(_config(ctx), slot=_slot_flag(ctx), extra=ctx.args)
|
|
196
|
+
|
|
197
|
+
|
|
174
198
|
@app.command("ls", help="List all slots derived from tfvars banners.")
|
|
175
199
|
def ls(
|
|
176
200
|
ctx: typer.Context,
|
|
@@ -220,7 +244,7 @@ def ls(
|
|
|
220
244
|
@app.command("rm", help="Remove a slot directory (does not touch the tfvars file).")
|
|
221
245
|
def rm(
|
|
222
246
|
ctx: typer.Context,
|
|
223
|
-
slot: Annotated[str, typer.Argument(help="Slot name to remove.",
|
|
247
|
+
slot: Annotated[str, typer.Argument(help="Slot name to remove.", autocompletion=_complete_slot)],
|
|
224
248
|
force: Annotated[bool, typer.Option("--force", help="Allow removing the active slot.")] = False,
|
|
225
249
|
) -> None:
|
|
226
250
|
cfg = _config(ctx)
|
|
@@ -562,7 +586,7 @@ def self_trace(
|
|
|
562
586
|
ctx: typer.Context,
|
|
563
587
|
subcommand: Annotated[
|
|
564
588
|
str,
|
|
565
|
-
typer.Argument(help="One of: use, plan, apply, refresh, destroy, output, import."),
|
|
589
|
+
typer.Argument(help="One of: use, init, plan, apply, refresh, destroy, output, import."),
|
|
566
590
|
],
|
|
567
591
|
targets: TargetsOption = None,
|
|
568
592
|
replaces: ReplacesOption = None,
|
|
@@ -593,7 +617,7 @@ def self_banner_check(
|
|
|
593
617
|
file_okay=True,
|
|
594
618
|
dir_okay=False,
|
|
595
619
|
readable=True,
|
|
596
|
-
|
|
620
|
+
autocompletion=_complete_tfvars,
|
|
597
621
|
),
|
|
598
622
|
],
|
|
599
623
|
) -> None:
|
|
@@ -83,6 +83,7 @@ def default_lock_platforms(extras: Sequence[str] = ()) -> tuple[str, ...]:
|
|
|
83
83
|
WRAPPED_SUBCOMMANDS: frozenset[str] = frozenset(
|
|
84
84
|
{
|
|
85
85
|
"use",
|
|
86
|
+
"init",
|
|
86
87
|
"ls",
|
|
87
88
|
"rm",
|
|
88
89
|
"plan",
|
|
@@ -480,15 +481,61 @@ def do_use(config: Config, *, arg: str, extra: Sequence[str] | None = None) -> R
|
|
|
480
481
|
if arg != resolved.name and slots_mod.looks_like_path(arg):
|
|
481
482
|
print(f"resolved {arg} → slot {resolved.name!r}", file=sys.stderr)
|
|
482
483
|
|
|
484
|
+
_bind_slot(config, resolved, force_init=False, set_active=True, extra=extra)
|
|
485
|
+
return resolved
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def do_init(config: Config, *, slot: str | None = None, extra: Sequence[str] | None = None) -> ResolvedSlot:
|
|
489
|
+
"""Re-resolve the active slot's banner and re-bind its backend.
|
|
490
|
+
|
|
491
|
+
Unlike a bare `terraform init` (which `do_passthrough` would have run,
|
|
492
|
+
silently reusing the backend already cached in `.terraform/`), this
|
|
493
|
+
re-reads the live tfvars banner, runs `terraform init -reconfigure` with
|
|
494
|
+
the freshly-resolved `-backend-config`, and refreshes the saved slot
|
|
495
|
+
state. This is the command to run after editing a banner's `state_key`
|
|
496
|
+
or `backend_config` - it keeps `tfp status` and subsequent plan/apply
|
|
497
|
+
pointed at the backend the banner actually describes.
|
|
498
|
+
|
|
499
|
+
Operates on the active slot (`-s` / TFP_SLOT / active file) but, unlike
|
|
500
|
+
`do_use`, does not move the active-slot pointer. Always runs
|
|
501
|
+
`terraform init` even when the backend signature is unchanged, matching
|
|
502
|
+
the explicit-`init` contract (provider upgrades, backend reconfigure).
|
|
503
|
+
"""
|
|
504
|
+
validate_uniqueness(config)
|
|
505
|
+
active = _require_active(config, flag=slot)
|
|
506
|
+
resolved = slots_mod.resolve_slot(active.name, config=config)
|
|
507
|
+
_bind_slot(config, resolved, force_init=True, set_active=False, extra=extra)
|
|
508
|
+
return resolved
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
def _bind_slot(
|
|
512
|
+
config: Config,
|
|
513
|
+
resolved: ResolvedSlot,
|
|
514
|
+
*,
|
|
515
|
+
force_init: bool,
|
|
516
|
+
set_active: bool,
|
|
517
|
+
extra: Sequence[str] | None = None,
|
|
518
|
+
) -> None:
|
|
519
|
+
"""Init (when needed) and persist `resolved` as the slot's saved state.
|
|
520
|
+
|
|
521
|
+
Shared core of `do_use` and `do_init`. `force_init` runs `terraform
|
|
522
|
+
init` even when the backend signature is unchanged (the explicit `tfp
|
|
523
|
+
init` contract); `do_use` leaves it False so a warm switch is a pointer
|
|
524
|
+
write. `set_active` writes the active-slot pointer (`do_use`); `do_init`
|
|
525
|
+
skips it - re-binding the backend should not change which slot bare
|
|
526
|
+
commands target.
|
|
527
|
+
"""
|
|
483
528
|
decision = _decide_init(config, resolved, config.terraform_binary)
|
|
529
|
+
needs_init = decision.needs_init or force_init
|
|
530
|
+
reason = decision.reason if decision.needs_init else "explicit re-init"
|
|
484
531
|
first_init = not resolved.slot_dir.exists()
|
|
485
532
|
resolved.slot_dir.mkdir(parents=True, exist_ok=True)
|
|
486
533
|
plugin_cache_dir = config.effective_plugin_cache_dir
|
|
487
534
|
if plugin_cache_dir is not None:
|
|
488
535
|
plugin_cache_dir.mkdir(parents=True, exist_ok=True)
|
|
489
536
|
|
|
490
|
-
if
|
|
491
|
-
print(f"==== PROJECT: {resolved.project} (slot {resolved.name!r}, {
|
|
537
|
+
if needs_init:
|
|
538
|
+
print(f"==== PROJECT: {resolved.project} (slot {resolved.name!r}, {reason}) ====")
|
|
492
539
|
init_env = terraform.merged_env(
|
|
493
540
|
resolved.env,
|
|
494
541
|
data_dir=resolved.data_dir,
|
|
@@ -530,13 +577,12 @@ def do_use(config: Config, *, arg: str, extra: Sequence[str] | None = None) -> R
|
|
|
530
577
|
backend_config=dict(resolved.backend_config),
|
|
531
578
|
)
|
|
532
579
|
save_state(state, config)
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
return resolved
|
|
580
|
+
if set_active:
|
|
581
|
+
write_active(config, resolved.name)
|
|
582
|
+
print(
|
|
583
|
+
f"active slot → {resolved.name} (file: {config.active_file}; affects all shells without TFP_SLOT set)",
|
|
584
|
+
file=sys.stderr,
|
|
585
|
+
)
|
|
540
586
|
|
|
541
587
|
|
|
542
588
|
def validate_uniqueness(config: Config) -> None:
|
|
@@ -847,6 +893,7 @@ __all__ = [
|
|
|
847
893
|
"build_plan_argv",
|
|
848
894
|
"build_refresh_argv",
|
|
849
895
|
"build_state_argv",
|
|
896
|
+
"do_init",
|
|
850
897
|
"do_rm",
|
|
851
898
|
"do_use",
|
|
852
899
|
"do_apply",
|
|
@@ -283,9 +283,10 @@ def do_self_banner_check(config: Config, *, tfvars: pathlib.Path) -> dict[str, A
|
|
|
283
283
|
|
|
284
284
|
_TRACE_PLACEHOLDER = "<DECRYPTED_TFVARS>"
|
|
285
285
|
|
|
286
|
-
TraceSubcommand = Literal["use", "plan", "apply", "refresh", "destroy", "output", "import"]
|
|
286
|
+
TraceSubcommand = Literal["use", "init", "plan", "apply", "refresh", "destroy", "output", "import"]
|
|
287
287
|
TRACE_SUBCOMMANDS: tuple[TraceSubcommand, ...] = (
|
|
288
288
|
"use",
|
|
289
|
+
"init",
|
|
289
290
|
"plan",
|
|
290
291
|
"apply",
|
|
291
292
|
"refresh",
|
|
@@ -314,10 +315,10 @@ def do_self_trace(
|
|
|
314
315
|
|
|
315
316
|
name = _resolve_slot_name(config, slot=slot)
|
|
316
317
|
|
|
317
|
-
# `use`
|
|
318
|
-
# state, so don't require it. Other subcommands need state because
|
|
319
|
-
# argv depends on saved tfvars / source_root / etc.
|
|
320
|
-
if subcommand
|
|
318
|
+
# `use` / `init` trace an init from the current banner - they don't read
|
|
319
|
+
# saved state, so don't require it. Other subcommands need state because
|
|
320
|
+
# their argv depends on saved tfvars / source_root / etc.
|
|
321
|
+
if subcommand in ("use", "init"):
|
|
321
322
|
try:
|
|
322
323
|
resolved = slots_mod.resolve_slot(name, config=config)
|
|
323
324
|
except slots_mod.SlotError as exc:
|
|
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
|