Azure / Azure/azure-cli

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

Open
#30,194 5 comments 0 reactions 0 assignees View on GitHub
act-observability-squad Auto-Assign bug Container Instances ContainerApp customer-reported Service Attention
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### 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
- This results in 1 environment variable on the container app, with all vars in 1 value.
![Image](https://github.com/user-attachments/assets/cbc6fca5-5ec6-42a4-b724-6bfbb2fa57bd)

Approach 2: Wrap just the value of APPLICATION_INSIGHTS_CONNECTION_STRING in double quotes:
- This results in an invalid CLI command (some of the parameters are missing)
![Image](https://github.com/user-attachments/assets/1ce2347b-90b1-43d3-9bb7-b20aa7d8abad)

### 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
- This results in 1 environment variable on the container app, with all vars in 1 value.
![Image](https://github.com/user-attachments/assets/cbc6fca5-5ec6-42a4-b724-6bfbb2fa57bd)

Approach 2: Wrap just the value of APPLICATION_INSIGHTS_CONNECTION_STRING in double quotes:
- This results in an invalid CLI command (some of the parameters are missing)
![Image](https://github.com/user-attachments/assets/1ce2347b-90b1-43d3-9bb7-b20aa7d8abad)

### 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](https://learn.microsoft.com/en-us/azure/azure-monitor/app/migrate-from-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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.