azurerm
azurerm copied to clipboard
Error generating container instance group with environment variables
Hi,
I am trying to create a container instance group with a single container definition with an environment variable defined.
My container definition is of the form:
container_def = create_container_definition(container_name='my_name', image='my_image', port=8000, cpu=1.0, memgb=1.0, environment=[{'name': 'my_name', 'value': 'my_value'}])
and a group instance created via:
create_contained_instance_group(access_token=my_token, subscription_id=my_id, resource_group=rg, container_group_name=group_name, container_list=[container_def], location='westeurope', ostype='Linux', port=8000, iptype='public')
Which fails and produces the following error:
The request content was invalid and could not be deserialized: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Microsoft.Azure.CloudConsole.Providers.Data.Definition.ContainerEnvironmentVariable[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'properties.containers[0].properties.environmentVariables.name:', line 1, position 278.'.
No error is produced when passing None into the container definition.
Any ideas what the problem is here?
JP
@PlayNiceKids take a look at how the function is called in the unit tests: https://github.com/gbowerman/azurerm/blob/master/test/container_test.py.
I don't see immediately what's wrong, but you could try seeing if the unit tests work for you.
print('Creating container list..')
container1_def = azurerm.create_container_definition(self.container_name, image,
port=container_port)
container2_def = azurerm.create_container_definition(self.container_name2, image,
port=container_port2)
container_list = [container1_def, container2_def]
print('Creating container instance group: ' + self.container_group_name)
response = azurerm.create_container_instance_group(self.access_token, self.subscription_id,
self.rgname, self.container_group_name,
container_list, self.location,
port=container_port, iptype='public')