Fix JSON array/object handling in environment variables for Bicep parameters#6603
Fix JSON array/object handling in environment variables for Bicep parameters#6603
Conversation
There was a problem hiding this comment.
Pull request overview
Updates ARM parameter value conversion in the Bicep provider to better support values coming from environment variables, specifically enabling JSON-encoded arrays/objects to be used with standard "${ENV_VAR}" substitution.
Changes:
- Extend
armParameterFileValueto parse JSON strings intoarray/objecttypes when the target parameter type requires it. - Add unit tests covering JSON-string array/object parsing, including invalid JSON cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go |
Adds JSON unmarshalling for array and object parameter types when the input is a string. |
cli/azd/pkg/infra/provisioning/bicep/bicep_provider_test.go |
Adds test coverage for array/object parsing from JSON strings and invalid JSON behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Implement extractValueFromMalformedJSON to handle environment variables containing JSON arrays/objects that get substituted into parameter templates, resulting in invalid JSON. The function properly balances brackets/braces to extract the complete JSON value. Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
- Add comprehensive documentation for extractValueFromMalformedJSON function - Improve test comments to focus on behavior rather than implementation details Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
…ameters Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
* Clarify extension list latest version column * Add update availability JSON property and show asterisk besides outdated extensions * Add upgrade hints to extension list output * Fix cooldown logic and shallow copy * Update AGENTS.md --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
* fix security issue with playwright/test 1.49.1 (#6592) * Checkpoint from VS Code for cloud agent session * Fix bicep CLI initialization by restoring EnsureInstalled calls - Restore public EnsureInstalled() method in bicep.go - Remove automatic installation from Build() and BuildBicepParam() - Add explicit EnsureInstalled() calls in service_target_containerapp.go and bicep_provider.go - Update all test files to use public EnsureInstalled() method - Reverts incorrect changes from previous checkpoint commit This fix follows the same pattern as PR #6593 for GitHub CLI. Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> * Checkpoint from VS Code for cloud agent session --------- Co-authored-by: Victor Vazquez <vhvb1989@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
* Initial plan * Release 1.23.2 Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
…al file systems (#6601) * Initial plan * Add defensive checks for undefined fsPath in VS Code extension commands This fixes the issue where provision and other commands would fail with "The 'path' argument must be of type string. Received undefined" when used with virtual file systems or certain VS Code contexts. Changes: - Added validation for selectedFile.fsPath before calling getWorkingFolder - Provides clear error messages that include URI scheme and selectedItem type - Suppresses automatic issue reporting since this is a user error - Applied fix to all affected commands: provision, deploy, up, down, restore, monitor, packageCli, and pipelineConfig - Added unit tests for the new validation logic Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> * Simplify provision.test.ts based on code review feedback Removed unused stub functions that weren't actually being used. Simplified tests to focus on the core validation logic. Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> * Refactor validation logic into shared utility function Based on code review feedback: - Extracted duplicated validation logic to validateFileSystemUri() in cmdUtil.ts - Updated all 8 command files to use the shared function - Simplified test assertions - Improved code maintainability by reducing duplication Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> * Fix validation to use strict equality check for undefined Changed condition from `!selectedFile.fsPath` to `selectedFile.fsPath === undefined` to avoid incorrectly rejecting empty string paths which are valid for root directories. Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> * Fix l10n.t() to use single string literal instead of concatenation The first argument to vscode.l10n.t() should be a single string literal for proper localization tooling compatibility. Removed string concatenation and used a single multi-line string literal instead. Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
* Add missing config options --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
* adding project-endpoint to init command * adding 12 preview release * fixig default customization method & adding training type * correct version
* adding project-endpoint to init command * adding 12 preview release * fixig default customization method & adding training type * correct version * adding grader to cloning code * adding missing grader functionality * merging master
* Add a naive attempt at downloading * Address PR comments Signed-off-by: trangevi <trangevi@microsoft.com> * Update download directory as well Signed-off-by: trangevi <trangevi@microsoft.com> * Use net/url parsing in parseGitHubUrlNaive to handle fragments and query params (#6634) * Initial plan * Use net/url parsing to handle query params and fragments in parseGitHubUrlNaive Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * Final review completed Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * Revert unintended changes to other extensions Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * Address PR comments Signed-off-by: trangevi <trangevi@microsoft.com> * Update download directory as well Signed-off-by: trangevi <trangevi@microsoft.com> * Initial plan * Rebased on latest base branch --------- Signed-off-by: trangevi <trangevi@microsoft.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> Co-authored-by: trangevi <trangevi@microsoft.com> --------- Signed-off-by: trangevi <trangevi@microsoft.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
* Add extensions option to the azd devcontainer feature to allow specifying extensions to install * Review updates * Revert whitespace changes * Address feedback on shell script. Add multiple extensions to the test config to validate
#6620) * Fix indentation * Add metadata capability checks and improve error handling * Support dynamic suggestions for `azd config` commands * Exclude global persistent flags --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
) * Initial plan * Update devcontainer feature version to 0.2.0 and add extensions example to README Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> * Use real extension examples in README documentation Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
…t/investigate-env-variable-handling
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
There was a problem hiding this comment.
@vhvb1989 I understand the changes, but I would like to have a discussion before we move forward.
After reading through the issue (thanks for helping set up the context there), I'm currently much in favor of something along the lines of:
- Store JSON as quoted-strings within
.env. - During ARM parameter expansion though, look up the type of parameter before deciding how to expand the substituiion. For object/array types, we should do string → JSON decode → type-check → value.
Do you feel strongly enough about the current approach? There's too much JSON-string sniffing for my personal liking.
If I understand the current proposed changes, the expected results we previously captured in cli/azd/test/functional/testdata/expected-output-types/typed-values.env should now be invalidated.
No strong opinion from me here @weikanglim . Can you show an example on how would you run |
|
@vhvb1989 Thanks for the quick response!
Agreed -- I care for this and would like this as well.
It would be the same as the current example, i.e. I'll take a quick pass on this to provide an alternative implementation to see if that resonates. |
|
closing in preference of #6694 |
Fix Environment Variable Array and JSON Handling
Problem
When setting environment variables with JSON array or object values using
azd env set, the values were not properly handled in Bicep parameter substitution. For example:Would fail because:
MY_ARRAY="[\"val1\",\"val2\"]"{"value":"["val1","val2"]"}(invalid JSON)Solution
Part 1: Environment Marshalling (✅ Complete)
fixupUnquotedDotenv()to detect JSON arrays/objects and store them unquotedisJSON()helper to validate JSON formatMY_ARRAY=["val1","val2"](unquoted) vsMY_STRING="hello"(quoted)Part 2: Bicep Parameter Resolution (✅ Complete)
extractValueFromMalformedJSON()to handle invalid JSON from envsubstarmParameterFileValue()for type conversionTesting
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.