Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/wfctl/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func runInfra(args []string) error {
return runInfraImport(args[1:])
case "state":
return runInfraState(args[1:])
case "logs":
return runInfraLogs(args[1:])
case "bootstrap":
return runInfraBootstrap(args[1:])
case "outputs":
Expand Down Expand Up @@ -122,6 +124,7 @@ Actions:
destroy Tear down infrastructure
import Import an existing cloud resource into state
state Manage IaC state (list, export, import)
logs Capture provider logs for an infrastructure resource
outputs Print captured resource outputs from state
refresh-outputs Read live outputs and reconcile state (no cloud writes)
align Validate IaC config + plan alignment (8 rule families)
Expand Down
1 change: 1 addition & 0 deletions cmd/wfctl/infra_env_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestInfraUsageDocumentsConfigAwareImportFlags(t *testing.T) {
"--env <name>",
"--name <resource>",
"--id <provider-id>",
"logs",
} {
if !strings.Contains(out, want) {
t.Fatalf("infra usage missing %q:\n%s", want, out)
Expand Down
7 changes: 7 additions & 0 deletions cmd/wfctl/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func runLogsWithOutput(args []string, out io.Writer) error {
}
}

func runInfraLogs(args []string) error {
if len(args) > 0 && args[0] == "capture" {
args = args[1:]
}
return runLogsCapture(args, os.Stdout)
}

func logsUsage() error {
fmt.Fprintf(flag.CommandLine.Output(), `Usage: wfctl logs <action> [options]

Expand Down
47 changes: 47 additions & 0 deletions cmd/wfctl/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,53 @@ modules:
}
}

func TestInfraLogsAliasUsesProviderLogCapture(t *testing.T) {
tmp := t.TempDir()
cfg := filepath.Join(tmp, "app.yaml")
if err := os.WriteFile(cfg, []byte(`
version: "1"
modules:
- name: do
type: iac.provider
config:
provider: digitalocean
- name: web
type: infra.container_service
config:
provider: do
app_name: bmw-staging
`), 0o600); err != nil {
t.Fatal(err)
}

provider := &fakeLogProvider{}
orig := resolveIaCProvider
resolveIaCProvider = func(_ context.Context, _ string, _ map[string]any) (interfaces.IaCProvider, io.Closer, error) {
return provider, nil, nil
}
t.Cleanup(func() { resolveIaCProvider = orig })

err := runInfra([]string{
"logs",
"--config", cfg,
"--resource", "web",
"--component", "api",
"--tail", "7",
})
if err != nil {
t.Fatalf("runInfra logs: %v", err)
}
if provider.req.ResourceName != "bmw-staging" {
t.Fatalf("ResourceName = %q, want bmw-staging", provider.req.ResourceName)
}
if provider.req.ComponentName != "api" {
t.Fatalf("ComponentName = %q, want api", provider.req.ComponentName)
}
if provider.req.TailLines != 7 {
t.Fatalf("TailLines = %d, want 7", provider.req.TailLines)
}
}

func TestLogsCaptureFollowSetsDuration(t *testing.T) {
tmp := t.TempDir()
cfg := filepath.Join(tmp, "app.yaml")
Expand Down
Loading