I have a simple bash script which creates a container and runs a task in it:
api=${1}
az container create \
--resource-group "my_resource_group" \
--file container.yaml \
--environment-variables "APIKEY"="${api}"
But the variable APIKEY never gets the value from this call, but always from the "default" value in container.yaml.
How do I create a container instance with the whole definition in .yaml and pass environment variables in the command az container create?
When input is given as file, environment variables are not considered.
Looking at cli sources, when File is used, it will simply return creating container based on file. https://github.com/Azure/azure-cli/blob/713061e3e4a0fc969b0797ec06bd0e3db49ad4a8/src/azure-cli/azure/cli/command_modules/container/custom.py#L112
What you could do is, use sed in bash script to change APIKey value in your container.yaml file and then deploy it as you are.
sed -i 's/PLACEHOLDER_FOR_APIKEY_HERE/$api/g' container.yaml
PLACEHOLDER_FOR_APIKEY_HERE will be replaced with commandline argument and container.yaml file will be updated.
So the script will look similar to below one.
api=${1}
sed -i 's/PLACEHOLDER_FOR_APIKEY_HERE/$api/g' container.yaml
az container create \
--resource-group "my_resource_group" \
--file container.yaml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With