Azure / azure-cli

Azure Command-Line Interface
MIT License
4.01k stars 2.98k forks source link

az containerapp up parameter env-vars does not consume the value of APPLICATION_INSIGHTS_CONNECTION_STRING #30194

Open rexwhitten opened 2 hours ago

rexwhitten commented 2 hours ago

Describe the bug

az containerapp up --env-vars does not work with APPLICATION_INSIGHTS_CONNECTION_STRING (or any other var that contains "=" regardless of escaping)

Command in question: az containerapp up Parameter: --env-vars

Example command:

    az containerapp up \
    --resource-group $(ARM_RESOURCE_GROUP) \
    --location $(LOCATION) \
    --name $(APPLICATION_NAME)$(SDLC_ENVIRONMENT) \
    --ingress external \
    --target-port $(PORT) \
--env-vars "AZURE_OPENAI_ENDPOINT=aaaa AZURE_OPENAI_KEY=aaaa ARM_SUBSCRIPTION_ID=fb4dd9d3-f90f-411b-aa7f-beb1ae2b892d LOCATION=eastus2 APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus2-3.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus2.livediagnostics.monitor.azure.com/;ApplicationId=00000000-0000-0000-0000-000000000000" \
    --logs-workspace-id $(LOG_WORKSPACE_ID) \
    --logs-workspace-key $(LOG_WORKSPACE_KEY) \
    --workload-profile-name "Consumption" \
    --source .

Approach 1: Wrap the value of "env-vars" in double quotes

Approach 2: Wrap just the value of APPLICATION_INSIGHTS_CONNECTION_STRING in double quotes:

Related command

    az containerapp up \
    --resource-group $(ARM_RESOURCE_GROUP) \
    --location $(LOCATION) \
    --name $(APPLICATION_NAME)$(SDLC_ENVIRONMENT) \
    --ingress external \
    --target-port $(PORT) \
--env-vars "AZURE_OPENAI_ENDPOINT=aaaa AZURE_OPENAI_KEY=aaaa ARM_SUBSCRIPTION_ID=SomeSubscriptionID LOCATION=eastus2 APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus2-3.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus2.livediagnostics.monitor.azure.com/;ApplicationId=00000000-0000-0000-0000-000000000000" \
    --logs-workspace-id $(LOG_WORKSPACE_ID) \
    --logs-workspace-key $(LOG_WORKSPACE_KEY) \
    --workload-profile-name "Consumption" \
    --source .

Errors

Approach 1: Wrap the value of "env-vars" in double quotes

Approach 2: Wrap just the value of APPLICATION_INSIGHTS_CONNECTION_STRING in double quotes:

Issue script & Debug output

az containerapp up \
--resource-group rg-bothub-toolapi-dev1 \
--location eastus2 \
--name toolapidev1 \
--ingress external \
--target-port 3100 \
--env-vars AZURE_OPENAI_ENDPOINT=aaaa AZURE_OPENAI_KEY=aaaa ARM_SUBSCRIPTION_ID=0000000-0000-0000-0000-00000000000 LOCATION=eastus2 APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=0000000-0000-0000-0000-0000000000;IngestionEndpoint=https://eastus2-3.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus2.livediagnostics.monitor.azure.com/;ApplicationId=00000000 \
--logs-workspace-id SomeId \
--logs-workspace-key SomeKey \
--workload-profile-name "Consumption" \
--source . \
--debug
You must specify either --source, --repo, or --image
/bin/sh: 8: --logs-workspace-id: not found

Expected behavior

The parameter --env-vars should handle environment variable values with "=" in them.

From Docs on Application Insights:

Application Insights is changing from global ingestion endpoints to regional endpoints that use connection strings, which provide [additional capabilities](https://learn.microsoft.com/en-us/azure/azure-monitor/app/connection-strings#connection-string-capabilities). 

Azure Monitor Source : Migrate from Application Insights instrumentation keys to connection strings

Environment Summary

azure-cli 2.65.0

core 2.65.0 telemetry 1.1.0

Dependencies: msal 1.31.0 azure-mgmt-resource 23.1.1

Python location '/opt/az/bin/python3' Extensions directory '/home/vscode/.azure/cliextensions'

Python (Linux) 3.11.8 (main, Sep 25 2024, 11:34:44) [GCC 12.2.0]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

yonzhan commented 2 hours ago

Thank you for opening this issue, we will look into it.