0
votes

I am using the code below to try and deploy an Azure Data Factory via ARM template but I get the error:

msrest.exceptions.ValidationError: Parameter 'Deployment.properties' can not be None.

Code:

from haikunator import Haikunator
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.resource.resources.models import DeploymentMode

parameters = {
    'factoryName': 'TestADF',
    'dataFactory_location': 'uksouth'
}
parameters = {k: {'value': v} for k, v in parameters.items()}

deployment_properties = {
    'mode': DeploymentMode.incremental,
    'template': template,
    'parameters': parameters
}

deployment_async_operation = self.client.deployments.begin_create_or_update(
    self.resource_group, 'azure-sample',   deployment_properties
)
deployment_async_operation.wait()

I am using azure-mgmt-resource version: 16.0.0

EDITED: Added the two json files exported as ARM templates:

Template file:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "factoryName": {
            "type": "string",
            "metadata": "Data Factory name",
            "defaultValue": "TestADF"
        },
        "dataFactory_location": {
            "type": "string",
            "defaultValue": "uksouth"
        }
    },
    "variables": {
        "factoryId": "[concat('Microsoft.DataFactory/factories/', parameters('factoryName'))]"
    },
    "resources": [
        {
            "name": "[parameters('factoryName')]",
            "type": "Microsoft.DataFactory/factories",
            "apiVersion": "2018-06-01",
            "properties": {},
            "dependsOn": [],
            "location": "[parameters('dataFactory_location')]"
        }
    ]
}

Template Parameter file:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "factoryName": {
            "value": "TestADF"
        },
        "dataFactory_location": {
            "value": "uksouth"
        }
    }
}

EDIT: Based on @Jim Xu's answer:

class Deployer(object):

    def __init__(self):

        client_id = ''
        client_secret = ''
        tenant_id = ''
        
        self.subscription_id = ''
        self.resource_group = ''       
        self.creds = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
        self.client = ResourceManagementClient( self.creds, '')
    
    def deploy(self):
        parameters = {
            'factoryName': 'TestAdfPipeline',
            'dataFactory_location': 'uksouth'
        }
        parameters = {k: {'value': v} for k, v in parameters.items()}
        with open(r'ArmTemplateDeployer\templates\TestAdftemplate.json', 'r') as template_file_fd:
            template = json.load(template_file_fd)
        deployment_properties = {
            'mode': DeploymentMode.incremental,
            'template': template,
            'parameters': parameters
        }
        deployment_async_operation = self.client.deployments.begin_create_or_update(
            self.resource_group, 'azure-sample', {'properties': deployment_properties, 'tags': []})
        deployment_async_operation.wait()

Thanks for your help.

1
Could you please provide your template?Jim Xu
@JimXu I have edited and added the 2 ARM template export json files. Thanks for your help.ibexy

1 Answers

1
votes

When we use the method ResourceManagementClient.deployments.begin_create_or_update() in package azure-mgmt-resource to deploy azure arm template. We need to provide resource_group_name, deployment_name and object Deployment. For more details, please refer to here enter image description here

So, we need to update code deployment_async_operation = self.client.deployments.begin_create_or_update(self.resource_group, 'azure-sample',deployment_properties) as deployment_async_operation = client.deployments.begin_create_or_update('testdata','azure-sample',{'properties': deployment_properties,'tags': []}).

For example

from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.resource.resources.models import DeploymentMode
from azure.identity import ClientSecretCredential
import json


CLIENT_ID = ''
CLIENT_SECRET = ''
TENANT_ID = ''

creds = ClientSecretCredential(tenant_id=TENANT_ID,
                               client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
client = ResourceManagementClient(
    creds, '')

parameters = {
    'factoryName': 'TestADFderg',
    'dataFactory_location': 'uksouth'
}
parameters = {k: {'value': v} for k, v in parameters.items()}
with open('./template.json', 'r') as template_file_fd:
    template = json.load(template_file_fd)
deployment_properties = {
    'mode': DeploymentMode.incremental,
    'template': template,
    'parameters': parameters
}
deployment_async_operation = client.deployments.begin_create_or_update(
    'testdata', 'azure-sample', {'properties': deployment_properties, 'tags': []})
deployment_async_operation.wait()

enter image description here