3

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?

user2776801
  • 131
  • 8

1 Answers1

2

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
Iqan Shaikh
  • 257
  • 1
  • 2
  • Thanks. That's what I'm actually doing. But it seemed a dirty solution, so I was trying to find out if I was missing something. – user2776801 Jul 14 '20 at 07:03