netherframe.cli 0.2.1__py3-none-any.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.
- netherframe/cli/__init__.py +1 -0
- netherframe/cli/__main__.py +4 -0
- netherframe/cli/commands/__init__.py +93 -0
- netherframe/cli/commands/backend.py +305 -0
- netherframe/cli/commands/config_command.py +98 -0
- netherframe/cli/commands/convert.py +40 -0
- netherframe/cli/commands/discover.py +679 -0
- netherframe/cli/commands/drift.py +499 -0
- netherframe/cli/commands/encode.py +130 -0
- netherframe/cli/commands/generation.py +861 -0
- netherframe/cli/commands/graph_state.py +439 -0
- netherframe/cli/commands/hybrid.py +461 -0
- netherframe/cli/commands/idiff.py +493 -0
- netherframe/cli/commands/infrastructure.py +1182 -0
- netherframe/cli/commands/init_command.py +11 -0
- netherframe/cli/commands/lint.py +49 -0
- netherframe/cli/commands/providers.py +315 -0
- netherframe/cli/commands/shell_command.py +17 -0
- netherframe/cli/commands/skill.py +167 -0
- netherframe/cli/commands/synthesis.py +732 -0
- netherframe/cli/commands/terraform_command.py +17 -0
- netherframe/cli/commands/watch_command.py +117 -0
- netherframe/cli/entrypoint.py +18 -0
- netherframe/cli/logging.py +33 -0
- netherframe/cli/main.py +177 -0
- netherframe/cli/options.py +32 -0
- netherframe/cli/py.typed +0 -0
- netherframe/cli/services/__init__.py +1 -0
- netherframe/cli/services/app_loader.py +62 -0
- netherframe/cli/services/app_resolver.py +205 -0
- netherframe/cli/services/graph_onboarding.py +144 -0
- netherframe/cli/services/legacy_cli.py +51 -0
- netherframe/cli/services/project_config.py +107 -0
- netherframe/cli/services/provider_batch.py +620 -0
- netherframe/cli/services/stack_inventory.py +342 -0
- netherframe/cli/skills/netherframe/SKILL.md +53 -0
- netherframe/cli/skills/netherframe/agents/openai.yaml +3 -0
- netherframe/cli/skills/netherframe/references/authoring.md +77 -0
- netherframe/cli/skills/netherframe/references/execution.md +70 -0
- netherframe/cli/skills/netherframe/references/migration.md +69 -0
- netherframe/cli/state_migration.py +111 -0
- netherframe/cli/tui/__init__.py +1 -0
- netherframe/cli/tui/plan_filters.py +200 -0
- netherframe/cli/tui/plan_models.py +51 -0
- netherframe/cli/tui/plan_viewer.py +745 -0
- netherframe/cli/ui.py +25 -0
- netherframe_cli-0.2.1.dist-info/METADATA +86 -0
- netherframe_cli-0.2.1.dist-info/RECORD +92 -0
- netherframe_cli-0.2.1.dist-info/WHEEL +4 -0
- netherframe_cli-0.2.1.dist-info/entry_points.txt +3 -0
- netherframe_cli-0.2.1.dist-info/licenses/LICENSE +21 -0
- nf/cli/__init__.py +4 -0
- nf/cli/__main__.py +4 -0
- nf/cli/commands/__init__.py +4 -0
- nf/cli/commands/backend.py +4 -0
- nf/cli/commands/config_command.py +4 -0
- nf/cli/commands/convert.py +4 -0
- nf/cli/commands/discover.py +4 -0
- nf/cli/commands/drift.py +4 -0
- nf/cli/commands/encode.py +4 -0
- nf/cli/commands/generation.py +4 -0
- nf/cli/commands/graph_state.py +4 -0
- nf/cli/commands/hybrid.py +4 -0
- nf/cli/commands/idiff.py +4 -0
- nf/cli/commands/infrastructure.py +4 -0
- nf/cli/commands/init_command.py +4 -0
- nf/cli/commands/lint.py +4 -0
- nf/cli/commands/providers.py +4 -0
- nf/cli/commands/shell_command.py +4 -0
- nf/cli/commands/skill.py +4 -0
- nf/cli/commands/synthesis.py +4 -0
- nf/cli/commands/terraform_command.py +4 -0
- nf/cli/commands/watch_command.py +4 -0
- nf/cli/entrypoint.py +4 -0
- nf/cli/logging.py +4 -0
- nf/cli/main.py +4 -0
- nf/cli/options.py +4 -0
- nf/cli/py.typed +0 -0
- nf/cli/services/__init__.py +4 -0
- nf/cli/services/app_loader.py +4 -0
- nf/cli/services/app_resolver.py +4 -0
- nf/cli/services/graph_onboarding.py +4 -0
- nf/cli/services/legacy_cli.py +4 -0
- nf/cli/services/project_config.py +4 -0
- nf/cli/services/provider_batch.py +4 -0
- nf/cli/services/stack_inventory.py +4 -0
- nf/cli/state_migration.py +4 -0
- nf/cli/tui/__init__.py +4 -0
- nf/cli/tui/plan_filters.py +4 -0
- nf/cli/tui/plan_models.py +4 -0
- nf/cli/tui/plan_viewer.py +4 -0
- nf/cli/ui.py +4 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"""Stack and app inventory helpers for synthesized output trees."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from collections import defaultdict
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import click
|
|
10
|
+
import questionary
|
|
11
|
+
from netherframe.cli.ui import console
|
|
12
|
+
from netherframe.cli.services.project_config import load_project_config
|
|
13
|
+
from netherframe.core.config import find_pyproject_toml, get_cached_tool_nf_config
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def configured_outdir_from_pyproject() -> Path | None:
|
|
17
|
+
"""Read [tool.nf].outdir from pyproject.toml if configured."""
|
|
18
|
+
pyproject = find_pyproject_toml()
|
|
19
|
+
if not pyproject:
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
config = get_cached_tool_nf_config(pyproject)
|
|
24
|
+
except Exception:
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
outdir = config.get("outdir")
|
|
28
|
+
if not isinstance(outdir, str) or not outdir.strip():
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
outdir_path = Path(outdir)
|
|
32
|
+
if outdir_path.is_absolute():
|
|
33
|
+
return outdir_path
|
|
34
|
+
return (pyproject.parent / outdir_path).resolve()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def normalize_path(path: str | Path) -> Path:
|
|
38
|
+
"""Convert path input to absolute path using current working directory."""
|
|
39
|
+
path_obj = Path(path)
|
|
40
|
+
if not path_obj.is_absolute():
|
|
41
|
+
path_obj = Path.cwd() / path_obj
|
|
42
|
+
return path_obj.resolve()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def candidate_outdirs(configured_outdir: str | None = None) -> list[Path]:
|
|
46
|
+
"""Build ordered list of possible synthesis output directories."""
|
|
47
|
+
candidates: list[Path] = []
|
|
48
|
+
|
|
49
|
+
if configured_outdir:
|
|
50
|
+
candidates.append(normalize_path(configured_outdir))
|
|
51
|
+
else:
|
|
52
|
+
env_outdir = os.getenv("NF_OUTDIR")
|
|
53
|
+
if env_outdir:
|
|
54
|
+
candidates.append(normalize_path(env_outdir))
|
|
55
|
+
|
|
56
|
+
pyproject_outdir = configured_outdir_from_pyproject()
|
|
57
|
+
if pyproject_outdir:
|
|
58
|
+
candidates.append(pyproject_outdir)
|
|
59
|
+
|
|
60
|
+
current_dir = Path.cwd()
|
|
61
|
+
for parent in [current_dir] + list(current_dir.parents):
|
|
62
|
+
candidates.extend(
|
|
63
|
+
[
|
|
64
|
+
parent / ".nf.out",
|
|
65
|
+
parent / "nf.out",
|
|
66
|
+
parent / "nf.out" / "stacks",
|
|
67
|
+
],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
unique: list[Path] = []
|
|
71
|
+
seen: set[str] = set()
|
|
72
|
+
for candidate in candidates:
|
|
73
|
+
key = str(candidate)
|
|
74
|
+
if key in seen:
|
|
75
|
+
continue
|
|
76
|
+
seen.add(key)
|
|
77
|
+
unique.append(candidate)
|
|
78
|
+
return unique
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def is_stack_dir(path: Path) -> bool:
|
|
82
|
+
"""Check if a directory looks like a synthesized stack directory."""
|
|
83
|
+
if not path.is_dir():
|
|
84
|
+
return False
|
|
85
|
+
|
|
86
|
+
if (path / "nf.tf.json").exists():
|
|
87
|
+
return True
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
return any(item.is_dir() and item.name.startswith("phase") for item in path.iterdir())
|
|
91
|
+
except OSError:
|
|
92
|
+
return False
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def has_legacy_phased_artifacts(path: Path) -> bool:
|
|
96
|
+
"""Return whether a stack directory contains phased Terraform artifacts."""
|
|
97
|
+
if not path.is_dir():
|
|
98
|
+
return False
|
|
99
|
+
|
|
100
|
+
if (path / "export-manifest.json").exists() or (path / "PHASED_EXECUTION.md").exists():
|
|
101
|
+
return True
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
return any(item.is_dir() and item.name.startswith("phase") for item in path.iterdir())
|
|
105
|
+
except OSError:
|
|
106
|
+
return False
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def discover_stacks(
|
|
110
|
+
configured_outdir: str | None = None,
|
|
111
|
+
) -> tuple[dict[str, Path], dict[str, list[Path]], list[Path]]:
|
|
112
|
+
"""Discover stack directories and build selector map."""
|
|
113
|
+
searched_locations = candidate_outdirs(configured_outdir)
|
|
114
|
+
stacks_by_name: dict[str, list[Path]] = defaultdict(list)
|
|
115
|
+
|
|
116
|
+
for outdir in searched_locations:
|
|
117
|
+
if not outdir.exists() or not outdir.is_dir():
|
|
118
|
+
continue
|
|
119
|
+
|
|
120
|
+
if outdir.name == "stacks" and outdir.parent.name == "nf.out":
|
|
121
|
+
try:
|
|
122
|
+
for maybe_stack in outdir.iterdir():
|
|
123
|
+
if maybe_stack.is_dir():
|
|
124
|
+
stacks_by_name[maybe_stack.name].append(maybe_stack)
|
|
125
|
+
except OSError:
|
|
126
|
+
continue
|
|
127
|
+
continue
|
|
128
|
+
|
|
129
|
+
try:
|
|
130
|
+
app_dirs = list(outdir.iterdir())
|
|
131
|
+
except OSError:
|
|
132
|
+
continue
|
|
133
|
+
|
|
134
|
+
for app_dir in app_dirs:
|
|
135
|
+
if not app_dir.is_dir():
|
|
136
|
+
continue
|
|
137
|
+
try:
|
|
138
|
+
for maybe_stack in app_dir.iterdir():
|
|
139
|
+
if is_stack_dir(maybe_stack):
|
|
140
|
+
stacks_by_name[maybe_stack.name].append(maybe_stack)
|
|
141
|
+
except OSError:
|
|
142
|
+
continue
|
|
143
|
+
|
|
144
|
+
selector_map: dict[str, Path] = {}
|
|
145
|
+
for stack_name, paths in sorted(stacks_by_name.items()):
|
|
146
|
+
if len(paths) == 1:
|
|
147
|
+
selector_map[stack_name] = paths[0]
|
|
148
|
+
continue
|
|
149
|
+
|
|
150
|
+
for stack_path in sorted(paths):
|
|
151
|
+
app_name = stack_path.parent.name
|
|
152
|
+
selector_map[f"{app_name}/{stack_name}"] = stack_path
|
|
153
|
+
|
|
154
|
+
return selector_map, stacks_by_name, searched_locations
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def is_app_output_dir(path: Path) -> bool:
|
|
158
|
+
"""Check if a directory looks like a synthesized app output directory."""
|
|
159
|
+
if not path.is_dir():
|
|
160
|
+
return False
|
|
161
|
+
|
|
162
|
+
if (path / "nf.tf.json").exists():
|
|
163
|
+
return True
|
|
164
|
+
|
|
165
|
+
try:
|
|
166
|
+
return any(is_stack_dir(item) for item in path.iterdir() if item.is_dir())
|
|
167
|
+
except OSError:
|
|
168
|
+
return False
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def discover_synthesized_apps(configured_outdir: str | None = None) -> dict[str, Path]:
|
|
172
|
+
"""Discover synthesized app directories in current-layout output trees."""
|
|
173
|
+
app_dirs: dict[str, Path] = {}
|
|
174
|
+
|
|
175
|
+
for outdir in candidate_outdirs(configured_outdir):
|
|
176
|
+
if not outdir.exists() or not outdir.is_dir():
|
|
177
|
+
continue
|
|
178
|
+
|
|
179
|
+
if outdir.name == "stacks" and outdir.parent.name == "nf.out":
|
|
180
|
+
continue
|
|
181
|
+
|
|
182
|
+
try:
|
|
183
|
+
children = list(outdir.iterdir())
|
|
184
|
+
except OSError:
|
|
185
|
+
continue
|
|
186
|
+
|
|
187
|
+
for maybe_app in children:
|
|
188
|
+
if maybe_app.name in app_dirs:
|
|
189
|
+
continue
|
|
190
|
+
if maybe_app.is_dir() and is_app_output_dir(maybe_app):
|
|
191
|
+
app_dirs[maybe_app.name] = maybe_app
|
|
192
|
+
|
|
193
|
+
return app_dirs
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def app_has_export_only_stacks(app_dir: Path) -> bool:
|
|
197
|
+
"""Return whether an app output directory contains phased export-only stacks."""
|
|
198
|
+
if not app_dir.is_dir():
|
|
199
|
+
return False
|
|
200
|
+
try:
|
|
201
|
+
return any(child.is_dir() and has_legacy_phased_artifacts(child) for child in app_dir.iterdir())
|
|
202
|
+
except OSError:
|
|
203
|
+
return False
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def load_project_config_for_inventory() -> object | None:
|
|
207
|
+
"""Load project config when available without making inventory commands brittle."""
|
|
208
|
+
try:
|
|
209
|
+
return load_project_config(allow_empty_apps=True)
|
|
210
|
+
except click.ClickException:
|
|
211
|
+
return None
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def print_no_stacks_message(outdir: str | None) -> None:
|
|
215
|
+
"""Print a helpful message when no synthesized legacy stacks are available."""
|
|
216
|
+
console.print("[bold red]No synthesized legacy stacks found.[/bold red]")
|
|
217
|
+
if outdir:
|
|
218
|
+
console.print(f"Searched outdir: {outdir}")
|
|
219
|
+
else:
|
|
220
|
+
console.print(
|
|
221
|
+
"Set NF_OUTDIR, configure [tool.nf].outdir, or pass --outdir explicitly.",
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
project_config = load_project_config_for_inventory()
|
|
225
|
+
if project_config is None:
|
|
226
|
+
return
|
|
227
|
+
|
|
228
|
+
legacy_apps = getattr(project_config, "legacy_apps", {})
|
|
229
|
+
hybrid_apps = getattr(project_config, "hybrid_apps", {})
|
|
230
|
+
|
|
231
|
+
if legacy_apps:
|
|
232
|
+
console.print(
|
|
233
|
+
"Configured legacy apps exist, but no synthesized stack output was found. Run 'nf synth' first or check the selected --outdir.",
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
if hybrid_apps:
|
|
237
|
+
console.print("")
|
|
238
|
+
if not legacy_apps:
|
|
239
|
+
console.print(
|
|
240
|
+
"This project only configures hybrid apps, so `nf list-stacks` has nothing to show.",
|
|
241
|
+
)
|
|
242
|
+
console.print("Configured hybrid apps:")
|
|
243
|
+
for selector in sorted(hybrid_apps):
|
|
244
|
+
console.print(f" • {selector}")
|
|
245
|
+
console.print(
|
|
246
|
+
"Use 'nf list-apps' for the full inventory, or run 'nf plan --app <name>', 'nf apply --app <name>', 'nf destroy --app <name>', or 'nf deploy --app <name>'.",
|
|
247
|
+
)
|
|
248
|
+
return
|
|
249
|
+
|
|
250
|
+
console.print("Make sure you've run 'nf synth' and selected the correct --outdir.")
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def find_stack_directory(stack_name: str, outdir: str | None = None) -> Path:
|
|
254
|
+
"""Find the directory for a specific stack."""
|
|
255
|
+
explicit_path = Path(stack_name)
|
|
256
|
+
if explicit_path.exists() and explicit_path.is_dir():
|
|
257
|
+
return explicit_path.resolve()
|
|
258
|
+
|
|
259
|
+
selector_map, stacks_by_name, searched_locations = discover_stacks(outdir)
|
|
260
|
+
|
|
261
|
+
if stack_name in selector_map:
|
|
262
|
+
return selector_map[stack_name]
|
|
263
|
+
|
|
264
|
+
if stack_name in stacks_by_name and len(stacks_by_name[stack_name]) > 1:
|
|
265
|
+
console.print(f"[bold red]Stack name '{stack_name}' is ambiguous.[/bold red]")
|
|
266
|
+
console.print("Use one of these selectors instead:")
|
|
267
|
+
for stack_path in sorted(stacks_by_name[stack_name]):
|
|
268
|
+
app_name = stack_path.parent.name
|
|
269
|
+
console.print(f" • {app_name}/{stack_name}")
|
|
270
|
+
raise click.ClickException(f"Ambiguous stack name: {stack_name}")
|
|
271
|
+
|
|
272
|
+
if selector_map:
|
|
273
|
+
console.print(f"[bold red]Stack '{stack_name}' not found.[/bold red]")
|
|
274
|
+
console.print("Available stacks:")
|
|
275
|
+
for selector in sorted(selector_map):
|
|
276
|
+
console.print(f" • {selector}")
|
|
277
|
+
raise click.ClickException(f"Stack '{stack_name}' not found")
|
|
278
|
+
|
|
279
|
+
console.print("[bold red]No synthesized stacks found.[/bold red]")
|
|
280
|
+
if outdir:
|
|
281
|
+
console.print(f"Searched outdir: {outdir}")
|
|
282
|
+
else:
|
|
283
|
+
console.print("Searched output locations:")
|
|
284
|
+
for location in searched_locations:
|
|
285
|
+
console.print(f" • {location}")
|
|
286
|
+
console.print("Make sure you've run 'nf synth' and selected the correct --outdir.")
|
|
287
|
+
raise click.ClickException("No stacks available")
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def list_available_stacks(outdir: str | None = None) -> list[str]:
|
|
291
|
+
"""List all available stack selectors."""
|
|
292
|
+
selector_map, _, _ = discover_stacks(outdir)
|
|
293
|
+
return sorted(selector_map.keys())
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def get_stack_name(stack_name: str | None, outdir: str | None = None) -> str:
|
|
297
|
+
"""Get stack selector from argument or interactive selection."""
|
|
298
|
+
if stack_name:
|
|
299
|
+
return stack_name
|
|
300
|
+
|
|
301
|
+
stacks = list_available_stacks(outdir)
|
|
302
|
+
if not stacks:
|
|
303
|
+
console.print("[bold red]No stacks found.[/bold red]")
|
|
304
|
+
if outdir:
|
|
305
|
+
console.print(f"Searched outdir: {outdir}")
|
|
306
|
+
else:
|
|
307
|
+
console.print(
|
|
308
|
+
"Set NF_OUTDIR, configure [tool.nf].outdir, or pass --outdir explicitly.",
|
|
309
|
+
)
|
|
310
|
+
raise click.ClickException("No stacks available")
|
|
311
|
+
|
|
312
|
+
if len(stacks) == 1:
|
|
313
|
+
console.print(
|
|
314
|
+
f"[dim]Auto-selecting the only available stack: {stacks[0]}[/dim]",
|
|
315
|
+
)
|
|
316
|
+
return stacks[0]
|
|
317
|
+
|
|
318
|
+
try:
|
|
319
|
+
selected_stack = questionary.select(
|
|
320
|
+
"Select a stack:",
|
|
321
|
+
choices=stacks,
|
|
322
|
+
style=questionary.Style(
|
|
323
|
+
[
|
|
324
|
+
("question", "bold"),
|
|
325
|
+
("answer", "fg:#ff9d00 bold"),
|
|
326
|
+
("pointer", "fg:#ff9d00 bold"),
|
|
327
|
+
("highlighted", "fg:#ff9d00 bold"),
|
|
328
|
+
("selected", "fg:#cc5454"),
|
|
329
|
+
("separator", "fg:#cc5454"),
|
|
330
|
+
("instruction", ""),
|
|
331
|
+
("text", ""),
|
|
332
|
+
("disabled", "fg:#858585 italic"),
|
|
333
|
+
],
|
|
334
|
+
),
|
|
335
|
+
).ask()
|
|
336
|
+
|
|
337
|
+
if selected_stack is None:
|
|
338
|
+
raise click.Abort()
|
|
339
|
+
|
|
340
|
+
return selected_stack
|
|
341
|
+
except KeyboardInterrupt as e:
|
|
342
|
+
raise click.Abort() from e
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: netherframe
|
|
3
|
+
description: Author, test, convert, and operate Netherframe (nf) Python infrastructure apps using Terraform providers. Use for nf app code, provider bindings, plan/apply workflows, adoption, or nf failures.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Netherframe
|
|
7
|
+
|
|
8
|
+
Use this skill for an application's nf workflow. Follow the project's existing instructions,
|
|
9
|
+
execution mode and user authorization. Reading this skill does not authorize an apply,
|
|
10
|
+
destroy, import or package upload beyond the user's task.
|
|
11
|
+
|
|
12
|
+
## Establish the execution boundary
|
|
13
|
+
|
|
14
|
+
Inspect `pyproject.toml` (`[tool.nf]`), app entry points and the existing backend. Use the
|
|
15
|
+
project's Python environment, usually `uv run nf`. `nf list-apps` shows configured selectors;
|
|
16
|
+
`nf <command> --help` is the command contract for the installed CLI version.
|
|
17
|
+
|
|
18
|
+
Netherframe requires Python 3.14+. An app entry such as `infra:app` names a Python module and
|
|
19
|
+
an App instance or factory, not its nf ID.
|
|
20
|
+
|
|
21
|
+
- `nf synth` writes Terraform JSON for configured synthesis apps. It does not apply resources.
|
|
22
|
+
- `nf plan --app app` and `nf apply --app app` use direct provider execution, with nf state.
|
|
23
|
+
- A configured synthesis app's `--stack platform/network` can also use direct execution.
|
|
24
|
+
- An explicit filesystem stack path such as `.nf.out/platform/network` selects the external
|
|
25
|
+
Terraform/OpenTofu CLI path. Raw Terraform passthrough arguments also select that path.
|
|
26
|
+
- `legacy_apps` alone does not mean a command runs Terraform. Do not switch engines or state
|
|
27
|
+
locations simply to make a command succeed. Hybrid app commands operate on the whole app.
|
|
28
|
+
|
|
29
|
+
## Choose the relevant reference
|
|
30
|
+
|
|
31
|
+
- [Authoring](references/authoring.md): constructors, provider bindings and runtime values.
|
|
32
|
+
Read with `nf skill show --topic authoring` when using the terminal-only skill.
|
|
33
|
+
- [Execution](references/execution.md): saved plans, credentials, deferred work and recovery.
|
|
34
|
+
Read with `nf skill show --topic execution` before changing a run procedure.
|
|
35
|
+
- [Migration](references/migration.md): conversion, discovery and explicit adoption.
|
|
36
|
+
Read with `nf skill show --topic migration` when taking over existing infrastructure.
|
|
37
|
+
|
|
38
|
+
## Make and verify the requested change
|
|
39
|
+
|
|
40
|
+
Keep resource IDs and backend paths stable for existing objects. Use the generated provider's
|
|
41
|
+
actual constructor and reference properties; do not invent argument names from Terraform's
|
|
42
|
+
schema spelling. For an authoring task, verify the changed app through focused tests and
|
|
43
|
+
synthesis or a reviewed provider-backed plan, as appropriate to the chosen engine.
|
|
44
|
+
|
|
45
|
+
Planning can read providers and needs their credentials. Applying, destroying and adoption
|
|
46
|
+
can change infrastructure or state. Prepare a concrete plan for review when mutation needs
|
|
47
|
+
approval; continue with actions already authorized by the user. Avoid retrying a failed apply
|
|
48
|
+
until its completed changes and recovery notes are understood.
|
|
49
|
+
|
|
50
|
+
The skill is bundled with this CLI release. Re-read `nf skill` after upgrading nf, and use
|
|
51
|
+
command help and installed source when a project runs a different version. To export this
|
|
52
|
+
folder for an agent, run `nf skill install --path PATH`. Installation only writes guidance;
|
|
53
|
+
it does not configure an app, change agent settings or perform an infrastructure operation.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Authoring nf apps
|
|
2
|
+
|
|
3
|
+
## Use the real constructor contract
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from nf.core import App, Output, Stack
|
|
7
|
+
from nf.providers.hashicorp.random import Pet, RandomProvider
|
|
8
|
+
|
|
9
|
+
app = App(nf_id="demo")
|
|
10
|
+
stack = Stack(nf_scope=app, nf_id="names")
|
|
11
|
+
provider = RandomProvider(nf_scope=stack, nf_id="random")
|
|
12
|
+
pet = Pet(nf_scope=stack, nf_id="example", nf_provider=provider, length=2)
|
|
13
|
+
Output(nf_scope=stack, nf_id="name", value=pet.ref_id_)
|
|
14
|
+
app.enable_hybrid_execution_local(path=".nf.out/demo.tfstate")
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For direct execution:
|
|
18
|
+
|
|
19
|
+
```toml
|
|
20
|
+
[tool.nf]
|
|
21
|
+
python = ["uv", "run", "python"]
|
|
22
|
+
hybrid_apps = ["app:app"]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Use `legacy_apps` for synthesis. Resources and provider configurations belong to a stack;
|
|
26
|
+
pass explicit `nf_scope` and `nf_id`. `Stack(app=..., name=...)` and `Resource(stack=...)`
|
|
27
|
+
are not the API. Keep the user's existing scope/ID conventions when editing an app.
|
|
28
|
+
|
|
29
|
+
## Distinguish bindings from provider binaries
|
|
30
|
+
|
|
31
|
+
The distribution `netherframe.providers.hashicorp.random` is imported as
|
|
32
|
+
`nf.providers.hashicorp.random`. `nf.*` and `netherframe.*` are runtime aliases.
|
|
33
|
+
Application examples use `nf.*`; Netherframe's own source uses `netherframe.*`.
|
|
34
|
+
|
|
35
|
+
Generate and install bindings when the project needs them:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
uv run nf generate providers hashicorp/random --version 3.9.1 --yes
|
|
39
|
+
uv add --editable ./providers/hashicorp/random
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Inside nf's monorepo, generated providers are workspace members: use `uv sync` after
|
|
43
|
+
generation instead of adding a dependency to the virtual workspace root. Retain pinned
|
|
44
|
+
inputs when generated output is ignored by version control.
|
|
45
|
+
|
|
46
|
+
A generated provider class pins its source and binary version. A Python binding revision
|
|
47
|
+
such as `3.9.1.1` still uses provider `3.9.1`; do not pass the fourth component as a Terraform
|
|
48
|
+
provider version. With `--binding-revision N`, use the same revision on regeneration.
|
|
49
|
+
|
|
50
|
+
Provider arguments avoid Python reserved words (`type_`), and output references can have
|
|
51
|
+
adjusted names (`ref_id_`). Inspect generated constructors and properties. Generic resources
|
|
52
|
+
use the Terraform type and schema-shaped arguments but still need an explicit provider
|
|
53
|
+
configuration for direct execution, even if Terraform permitted an implicit default.
|
|
54
|
+
|
|
55
|
+
## Preserve deferred values
|
|
56
|
+
|
|
57
|
+
A reference is not a cloud API lookup. `pet.ref_id_` is an eventual value; carry it into
|
|
58
|
+
other resource arguments instead of converting it to an eager Python value. f-strings can
|
|
59
|
+
retain nf expression tokens. Runtime comparisons use `.eq()`/`.ne()`; do not use Python
|
|
60
|
+
`if` or `bool()` to decide from a value only a provider can know. Use nf expression/functions
|
|
61
|
+
or a runtime check for those decisions.
|
|
62
|
+
|
|
63
|
+
A reference establishes a dependency. Use `depends_on` for an ordering requirement not
|
|
64
|
+
represented by values. Terraform `count` and `for_each` are not supported by the direct
|
|
65
|
+
engine: create explicit constructs with stable IDs in Python loops. Do not silently remove
|
|
66
|
+
lifecycle requirements to get a plan to pass; check direct-engine support for that feature.
|
|
67
|
+
|
|
68
|
+
## Test without deploying
|
|
69
|
+
|
|
70
|
+
Construct the app and synthesize into a temporary directory; assert important resource
|
|
71
|
+
arguments, provider wiring and output references in `nf.tf.json`. This needs installed
|
|
72
|
+
bindings but no cloud credentials. A provider-backed plan tests additional behavior and can
|
|
73
|
+
require credentials. Use disposable local resources or the project's emulator for apply tests.
|
|
74
|
+
|
|
75
|
+
`GeneratedValue` supplies stateful in-process values (including password and TLS generators)
|
|
76
|
+
without another provider binary. Its outputs are sensitive; mark corresponding `Output`s
|
|
77
|
+
`sensitive=True` and protect state/plan files, which can contain the underlying values.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Execution, review and recovery
|
|
2
|
+
|
|
3
|
+
## Review the same plan that will be applied
|
|
4
|
+
|
|
5
|
+
For a configured hybrid app:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uv run nf plan --app app --out reviewed-plan.json
|
|
9
|
+
uv run nf show --plan-file reviewed-plan.json
|
|
10
|
+
uv run nf apply --app app --plan-file reviewed-plan.json
|
|
11
|
+
uv run nf plan --app app
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Saving a plan does not approve it. Use existing project approval procedures. For authorized
|
|
15
|
+
unattended execution, `--auto-approve` skips the interactive prompt; imports and deferred
|
|
16
|
+
changes have their own explicit settings. Do not add those settings merely to bypass a stop.
|
|
17
|
+
|
|
18
|
+
Retain the plan with the code revision, dependency lock and environment/backend selection.
|
|
19
|
+
A saved plan is a whole-app artifact and nf checks its state/provider fingerprints. If it
|
|
20
|
+
is stale, generate a new plan for review. Do not edit a saved plan to override its checks.
|
|
21
|
+
Use the same backend at review and apply; a local state file on another runner is not a
|
|
22
|
+
shared backend. Plans, checkpoints and state may contain secrets even when summaries mask them.
|
|
23
|
+
|
|
24
|
+
## Credentials and long runs
|
|
25
|
+
|
|
26
|
+
Use the provider's supported credential chain or existing project credential mechanism.
|
|
27
|
+
Do not put secrets into app source, skill files or command arguments. Credentials available
|
|
28
|
+
to the Python backend and credentials available inside a provider process can differ.
|
|
29
|
+
Do not assume that changing the parent shell's environment refreshes a running provider.
|
|
30
|
+
Inspect the actual chain before proposing a solution for expiring credentials.
|
|
31
|
+
|
|
32
|
+
Direct provider apply has no fixed deadline by default (`NF_PROVIDER_APPLY_TIMEOUT` unset
|
|
33
|
+
or zero). Stopping the client does not prove the provider stopped changing infrastructure.
|
|
34
|
+
A credential or transport failure can follow partial success: inspect objects and state.
|
|
35
|
+
|
|
36
|
+
## Deferred work is not convergence
|
|
37
|
+
|
|
38
|
+
Providers can depend on outputs created earlier in the run. The first plan can therefore
|
|
39
|
+
contain deferred changes rather than a fully resolved provider-backed plan.
|
|
40
|
+
|
|
41
|
+
- `--apply-deferred` permits later rounds in the same run.
|
|
42
|
+
- `--deferred-approval` controls whether each round is reviewed; the default is `once`.
|
|
43
|
+
- `--approve-imports` is separately required to approve imports during unattended execution.
|
|
44
|
+
- A successful apply can remain incomplete; the default incomplete CLI exit code is 2.
|
|
45
|
+
|
|
46
|
+
Confirm the project's desired approval policy before changing these settings. Inspect the
|
|
47
|
+
run's completeness and deferred work as well as its success/failure message.
|
|
48
|
+
|
|
49
|
+
## Recover from a failed apply
|
|
50
|
+
|
|
51
|
+
Read the original resource error, completed operations, state persistence errors and recovery
|
|
52
|
+
notes before another mutation. Prefer a fresh plan after correcting the cause.
|
|
53
|
+
|
|
54
|
+
| Strategy | What a failed run leaves |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| CHECKPOINT (default) | Completed changes in state, plus a pre-apply checkpoint |
|
|
57
|
+
| ROLLBACK | Attempts to delete objects created by that run; completed updates/deletes/replacements cannot be reversed |
|
|
58
|
+
| NONE | Completed changes in state; no checkpoint or rollback attempt |
|
|
59
|
+
|
|
60
|
+
A checkpoint restores state only, not cloud infrastructure. `restore_checkpoint(location)`
|
|
61
|
+
is appropriate only after reconciling the infrastructure to match that state. Remote backends
|
|
62
|
+
may retain checkpoints beside state; use the location reported by the run.
|
|
63
|
+
|
|
64
|
+
Preserve `<outdir>/errored.tfstate` if storing state failed. Investigate ownership/locking
|
|
65
|
+
conflicts rather than forcibly replacing another run's state. Rollback skips deletions if
|
|
66
|
+
another run took over state, and reports changes it could not reverse.
|
|
67
|
+
|
|
68
|
+
Live progress logs show elapsed time and node counts, not a completion-time estimate.
|
|
69
|
+
Increase logs around the failing boundary (`NF_LOG_LEVEL=DEBUG`) and inspect a plan before
|
|
70
|
+
retrying an apply. Avoid broad deploy retries as a diagnostic shortcut.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Conversion and adoption
|
|
2
|
+
|
|
3
|
+
## Translate source before taking ownership
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
uv run nf convert ./terraform-project --output . --package imported --report conversion-report.txt
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The converter writes `imported/`, exporting `ImportedStack`, and `imported.adopt.json`.
|
|
10
|
+
It translates local modules, variables, supported expressions and resource address changes.
|
|
11
|
+
Read its report and `TODO(nf convert)` markers: successful conversion/import of Python does
|
|
12
|
+
not establish that every Terraform feature can execute directly.
|
|
13
|
+
|
|
14
|
+
With `--fetch-modules`, public registry modules, GitHub sources and HTTP(S) archives can
|
|
15
|
+
be converted recursively. Pin versions/revisions. Private registries and arbitrary Git
|
|
16
|
+
transports are not supported by that flag.
|
|
17
|
+
|
|
18
|
+
Installed bindings produce typed constructors; unavailable bindings fall back to generic
|
|
19
|
+
constructs. Check provider declarations, aliases and source/version pins. A Terraform module
|
|
20
|
+
with an implicit default provider needs an explicit configuration for direct nf execution.
|
|
21
|
+
|
|
22
|
+
## Match objects through a reviewed manifest
|
|
23
|
+
|
|
24
|
+
Export Terraform state with its existing backend and engine (`terraform state pull`). Keep
|
|
25
|
+
that snapshot separate from the destination nf backend. Coordinate ownership so the old
|
|
26
|
+
engine does not keep writing the same resource group after cutover.
|
|
27
|
+
|
|
28
|
+
Instantiate the generated stack with `nf_id="imported"` so the manifest's stack matches.
|
|
29
|
+
If the actual ID differs, use `"stack_map": {"imported": "actual_id"}` in the manifest.
|
|
30
|
+
Required module variables become constructor keyword arguments; inspect the generated class.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
uv run nf plan --app app --adopt-from imported.adopt.json \
|
|
34
|
+
--terraform-state terraform-state.json --adopt-missing error --out reviewed-import.json
|
|
35
|
+
uv run nf apply --app app --plan-file reviewed-import.json
|
|
36
|
+
uv run nf plan --app app
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The plan shows imports plus any updates/replacements needed to match the configuration.
|
|
40
|
+
`--adopt-missing error` refuses missing targets instead of creating them. A saved plan keeps
|
|
41
|
+
those policies and source-state data. An authorized unattended import needs both
|
|
42
|
+
`--auto-approve` and `--approve-imports`.
|
|
43
|
+
|
|
44
|
+
A `terraform_address` manifest entry adopts from the exported state, including provider
|
|
45
|
+
private data and identity, with schema upgrade and refresh. It does not depend on the
|
|
46
|
+
resource having a working import RPC.
|
|
47
|
+
|
|
48
|
+
## Existing objects without Terraform state
|
|
49
|
+
|
|
50
|
+
Use `.import_from(remote_id)` on a declared resource, an identity-based
|
|
51
|
+
`LifecycleRules(adopt=True | "required")`, or a run-supplied adoption manifest. `adopt=True`
|
|
52
|
+
allows a create when no matching object is found; `"required"` refuses that case.
|
|
53
|
+
Nothing is adopted simply because a configured resource has the same name.
|
|
54
|
+
|
|
55
|
+
Discovery integrations can inventory and codify supported objects:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
uv run nf discover list-providers
|
|
59
|
+
uv run nf discover list-resources aws --filter "aws_*"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Read each integration's coverage and omission report. Availability of a schema does not
|
|
63
|
+
prove that a resource supports import or a safe reviewed create. For example, upstream
|
|
64
|
+
Keycloak bindings omit some objects that a patched provider can adopt; do not synthesize
|
|
65
|
+
creates for unsupported imports just to clear the report.
|
|
66
|
+
|
|
67
|
+
Deferred providers retain adoption requests until lookup is possible. A missing provider
|
|
68
|
+
configuration, failed lookup or duplicate adoption is not permission to recreate the object.
|
|
69
|
+
After adoption, a fresh plan should converge and old import requests can be removed.
|