feat: accept snake_case environment variable names - #298
Open
Abhinesh Jha (Abhineshhh) wants to merge 2 commits into
Open
feat: accept snake_case environment variable names#298Abhinesh Jha (Abhineshhh) wants to merge 2 commits into
Abhinesh Jha (Abhineshhh) wants to merge 2 commits into
Conversation
Support preferred snake_case env vars (e.g. MPF_SUBSCRIPTION_ID) while keeping legacy concatenated names (e.g. MPF_SUBSCRIPTIONID) for backward compatibility. Bind both forms via Viper for all CLI flags, prefer legacy when both are set, and document the dual naming. E2E helpers accept either form so tests stay aligned with the CLI. Fixes Azure#248
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for snake_case environment variables across the azmpf CLI (via Cobra/Viper), while preserving and prioritizing the existing legacy concatenated env var names for backward compatibility (per issue #248).
Changes:
- Implement dual env var binding per flag (legacy + snake_case) with legacy precedence via centralized binding logic in
cmd/envbinding.go. - Add unit coverage for camel→snake conversion, env name derivation, and binding precedence/behavior.
- Align docs and E2E tests to accept either env var form (legacy-first lookup helper).
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates examples to prefer snake_case env vars while noting legacy compatibility. |
| docs/commandline-flags-and-env-variables.md | Documents snake_case vs legacy naming rules and lists both env var forms per flag. |
| cmd/rootCmd.go | Switches config initialization to use the new dual-env binding helper. |
| cmd/envbinding.go | Introduces camel→snake conversion, env name derivation, and dual BindEnv behavior. |
| cmd/envbinding_test.go | Adds unit tests for conversion, env name generation, and precedence (CLI > legacy env > snake_case). |
| e2eTests/env_helpers.go | Adds mpfEnv() helper to read legacy-first, then snake_case env vars in tests. |
| e2eTests/e2eTerraformWithImportAndTargeting_test.go | Updates terraform path env lookup to accept both env var forms. |
| e2eTests/e2eTerraformInvalid_test.go | Updates terraform path env lookup to accept both env var forms. |
| e2eTests/e2eTerraformAuthPermissionMismatch_test.go | Updates terraform path env lookup to accept both env var forms. |
| e2eTests/e2eTerraformAuthorizationRequestDenied_test.go | Updates terraform path env lookup to accept both env var forms. |
| e2eTests/e2eTerraform_test.go | Updates terraform path env lookup to accept both env var forms. |
| e2eTests/e2eBicepInvalid_test.go | Updates bicep exec path env lookup to accept both env var forms. |
| e2eTests/e2eBicep_test.go | Updates bicep exec path env lookup to accept both env var forms. |
| e2eTests/e2eArm_test.go | Updates ARM E2E env var reads to accept both legacy and snake_case forms. |
| AGENTS.md | Updates agent instructions/examples to use snake_case env vars (preferred). |
Contributor
|
Abhinesh Jha (@Abhineshhh) Thanks for the PR. It looks good. Can you look that linting PR check which is failing |
Mani Bindra (maniSbindra)
requested changes
Aug 2, 2026
Mani Bindra (maniSbindra)
left a comment
Contributor
There was a problem hiding this comment.
Abhinesh Jha (@Abhineshhh) Thanks for the PR. It looks good. Can you look that linting PR check which is failing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements support for snake_case environment variable names while fully preserving the existing concatenated names for backward compatibility.
Closes / fixes: #248
Problem
Environment variables used a hard-to-read concatenated form (e.g.
MPF_SUBSCRIPTIONID). Users requested conventional snake_case (e.g.MPF_SUBSCRIPTION_ID) without breaking existing scripts and CI.Solution
MPF_+ upper(flagName) →MPF_SUBSCRIPTIONID(unchanged behavior)MPF_+ upper(camelToSnake(flagName)) →MPF_SUBSCRIPTION_IDBindEnvfor every flag (global, ARM, Bicep, Terraform)mpfEnv()helper (legacy first)Examples
subscriptionIDMPF_SUBSCRIPTION_IDMPF_SUBSCRIPTIONIDspClientIDMPF_SP_CLIENT_IDMPF_SPCLIENTIDtemplateFilePathMPF_TEMPLATE_FILE_PATHMPF_TEMPLATEFILEPATHtfPathMPF_TF_PATHMPF_TFPATHChanges
cmd/envbinding.go,cmd/rootCmd.gocmd/envbinding_test.godocs/commandline-flags-and-env-variables.md,README.md,AGENTS.mde2eTests/env_helpers.go+ e2e test filesBackward compatibility
MPF_SUBSCRIPTIONID,MPF_TFPATH, etc. continue to workpkg/Test plan
go test ./cmd/ -count=1go test ./pkg/... -count=1go test ./e2eTests/ -count=1(compile / unit path; live Azure e2e not run in this environment)go vet ./cmd/ ./e2eTests/gofmtclean on touched Go filesinitializeConfigwith root+arm flagsReferences
docs/commandline-flags-and-env-variables.md