Hi @Umesh Edirisingha Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.
Azure Container Apps also provides couple of different options through Azure CLI or Powershell to Add/Update
environment variables.
While creating a Container App you can use the following Azure CLI command to pass multiple environment variables by a space-separated values in the 'key=value' format.
az containerapp create -n my-containerapp -g MyResourceGroup \
--image my-app:v1.0 --environment MyContainerappEnv \
--secrets mysecret=secretvalue1 anothersecret="secret value 2" \
--env-vars GREETING="Hello, world" ANOTHERENV=anotherenv
If you are trying to provide environment variables to an existing Container App, you may az containerapp update
command and achieve the same. Please refer the document link to get more information on how to Configure the environment variables through Azure CLI
Here is another option to Configure the environment variables through Powershell
You can iterate the contents of your .env
file through the following script and automate the addition of entries.
Get-Content .env | ForEach-Object {
# Split the line into the variable name and value
$varName, $varValue = $_.Split('=')
# Do something with the variable name and value
Write-Host "Variable name: $varName, Value: $varValue"
# Put in the commands from configuring through PowerShell option
# Wait for 5 second
Start-Sleep -Seconds 5
}
Please note that I have put a five second delay in the above loop as the script iterates through the file contents and call Update-AzContainerApp -TemplateContainer $containerTemplate
command. This is just a caution to allow the command execution to be done processing adding an environment value. Please test this script on a test app and adjust the wait time as needed.
Hope this helps! Please let us know if you need any additional assistance or have further questions in the comments below.
If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.