Create Azure Container Instances with dynamic environment variables
This is an example for creating Azure container groups
with enviroment variables using Typescript.
Authentication and creating client
Firstly we use "@azure/ms-rest-nodeauth"
library to do the authentication using service principal.
|
|
After authenticated successfully, we can get the credentials from the response and use it to create Container Instance
client.
|
|
Create container group
We define the specs for the container going to be used in the container group.
Also, we can specify the necessary environment variables
here.
|
|
Then we pass this defined container as a parameter of the container group
|
|
Finally, we use beginCreateOrUpdate
method of the client to create and start the container group.
|
|
Thoughts and conclusion
I was very struggle to find any resouces or example of using Typescript with Container group SDK as well as Azure SDK in general. So I had to investigate the source code of the library and spent a lot of time for searching on the Internet to get the job done, that makes me decided to write this blog with the hope that it will help someone who has the same problem.
A downside of this approach is that, for each request of updating environment variables, we need to create a new container instance group because currently Azure doesn’t support to update the information on the fly (link).
Author nhs000
LastMod 2021-03-03