Skip to content

Commit 18a5159

Browse files
authored
Add az alias for lstk setup azure (#357)
1 parent 3dc42b9 commit 18a5159

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ There is no `--offline` flag. Instead `container.Start` degrades gracefully when
101101

102102
Use `lstk setup <emulator>` to set up CLI integration for an emulator type:
103103
- `lstk setup aws` — Sets up AWS CLI profile in `~/.aws/config` and `~/.aws/credentials`. Runs interactively (Y/n prompt) on a TTY; in non-interactive mode (CI / piped / `--non-interactive`) it writes the profile with defaults and exits 0 without prompting. Overwriting an existing `localstack` profile whose values differ requires `--force` (which also skips the prompt interactively); a fresh profile, completing a partial one, or an already-correct profile never needs it. Unlike the interactive path (which warns and continues on a failed write), the non-interactive path returns write/check failures as errors so automation exits non-zero. The shared host resolution lives in `awsconfig.ResolveProfileHost`; the non-interactive write is `awsconfig.SetupNonInteractive` (no `UserInputRequestEvent`), while `awsconfig.Setup(..., skipConfirm)` keeps the interactive prompt.
104-
- `lstk setup azure` — Prepares an isolated Azure CLI config dir (under the lstk config dir, via `AZURE_CONFIG_DIR`): registers a custom Azure cloud (`LocalStack`) whose endpoints point at the LocalStack Azure emulator, activates it, disables Azure CLI instance discovery and telemetry, and performs a one-time dummy service-principal login. The user's global `~/.azure` is left untouched. Requires the `az` CLI and a running Azure emulator.
104+
- `lstk setup azure` (alias `lstk setup az`, matching the `lstk az` proxy command) — Prepares an isolated Azure CLI config dir (under the lstk config dir, via `AZURE_CONFIG_DIR`): registers a custom Azure cloud (`LocalStack`) whose endpoints point at the LocalStack Azure emulator, activates it, disables Azure CLI instance discovery and telemetry, and performs a one-time dummy service-principal login. The user's global `~/.azure` is left untouched. Requires the `az` CLI and a running Azure emulator.
105105
- `lstk az <args>` — Runs `az <args>` against that isolated config dir, so the Azure CLI talks to LocalStack for Azure service URLs and to the real internet for everything else (extension downloads, etc.).
106106
- `lstk az start-interception` / `lstk az stop-interception` — Opt-in second mode: instead of the isolated dir, these mutate the user's **global** `~/.azure` so plain `az` (any terminal/script) targets LocalStack, then switch back. `start-interception` runs the same register → activate → `instance_discovery=false` → dummy-login flow against the global config (but does not touch global telemetry/survey prefs) and is independent of `lstk setup azure`. `stop-interception` switches the active cloud back to `AzureCloud` (override with `--cloud <name>`, validated against the live `az cloud list`) and re-enables instance discovery — but only if `LocalStack` is still the active cloud, to avoid clobbering an unrelated selection.
107107

cmd/setup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func newSetupAWSCmd(cfg *env.Env) *cobra.Command {
6565
func newSetupAzureCmd(cfg *env.Env) *cobra.Command {
6666
return &cobra.Command{
6767
Use: "azure",
68+
Aliases: []string{"az"},
6869
Short: "Set up Azure CLI integration with LocalStack",
6970
Long: "Prepare an isolated Azure CLI config directory that routes 'lstk az' commands to the LocalStack Azure emulator. Your global ~/.azure configuration is left untouched. Requires the `az` CLI and a running LocalStack Azure emulator.",
7071
PreRunE: initConfig(nil),

test/integration/setup_azure_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ func TestSetupAzureNonInteractiveRunsWithoutTerminal(t *testing.T) {
7777
assert.NotContains(t, stderr, "interactive terminal")
7878
}
7979

80+
// `lstk setup az` must resolve to `setup azure`: the Azure tool-proxy command
81+
// is `lstk az` (mirroring the terraform/tf alias), so setup should accept the
82+
// tool name too. Routing is proven by the azure setup logic running and
83+
// reporting its domain error rather than Cobra failing with "unknown command".
84+
func TestSetupAzureAliasAz(t *testing.T) {
85+
t.Parallel()
86+
87+
_, stderr, err := runLstk(t, testContext(t), "",
88+
env.With(env.Home, t.TempDir()),
89+
"setup", "az",
90+
)
91+
require.Error(t, err)
92+
assert.NotContains(t, stderr, "unknown command")
93+
assert.Contains(t, stderr, "no azure emulator configured")
94+
}
95+
8096
// When the az CLI is missing, the error must be reported exactly once —
8197
// not as a warning and then again as the final error.
8298
func TestSetupAzureReportsMissingAzCLIOnce(t *testing.T) {

0 commit comments

Comments
 (0)