problem creating AKS cluster using template in Python

AJG 436 Reputation points
2020-09-17T16:10:51.41+00:00

I have a template for creating an AKS cluster - which works when deployed via the portal - next step to run this process in code.

So, I have been looking at this azure python sample code:

https://github.com/Azure-Samples/resource-manager-python-template-deployment

The first problem is that the ServicePrincipal seems to need to have 'Owner' level to work via Python (but not via portal).

however, then it looks like the signature of the function:

ResourceManagementClient.deployments.create_or_update()

has changed subtly - if you pass in a dict for the deployment properties - as per the example code, then it produces the error message:

Exception has occurred: ValidationError
Parameter 'Deployment.properties' can not be None.

digging a bit - it looks like deployment properties now needs to be provided as an object, so I tried the following:

dprops = DeploymentProperties(mode=DeploymentMode.complete,template=aks_template,parameters=parameters)
deployment_async_operation = self.client.deployments.create_or_update(self.resource_group,'azure-sample',dprops)

this then produces the error:

Exception has occurred: CloudError
Azure Error: InvalidRequestContent
Message: The request content was invalid and could not be deserialized: 'Could not find member 'template' on object of type 'DeploymentDefinition'. Path 'template', line 1, position 12.'.

which is odd - since passing a template is really the purpose of the exercise.

when I googled this - it came up with a few hits - but relating to extensions that I am not using - as far as I know.

is there an up to date / working example of how to do this ?

A

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,994 questions
0 comments No comments
{count} votes

Accepted answer
  1. AJG 436 Reputation points
    2020-09-18T11:58:50.453+00:00

    If anyone else has the same problem - I finally got to the bottom of this.

    it also looks like another release of the azure-mgmt-resource package came out yesterday, so I have updated to work with that.

    A few changes needed:

    imports:
    from azure.identity import ClientSecretCredential
    from azure.mgmt.resource import ResourceManagementClient
    from azure.mgmt.resource.resources.models import Deployment, DeploymentProperties, DeploymentMode

    credentials:
    credentials = ClientSecretCredential(client_id=xxx,client_secret=yyy,tenant_id=zzz])

    executing deployment template:
    dprops = DeploymentProperties(mode=DeploymentMode.complete,template=aks_template,parameters=parameters)
    deployment = Deployment(properties=dprops)
    deployment_async = client.deployments.begin_create_or_update(resourcegroup,'azure-sample',deployment)

    where aks_template is the aks deployment template, parameters are the template parameters,

    A


0 additional answers

Sort by: Most helpful