Hello @Giovana Claro
Thanks for reaching out to us, based on the information you provided, yes, the az ml computetarget create command is not idempotent, which means that it will fail if the compute instance already exists.
To create a compute instance if it doesn't exist and ignore if it exists, you can use the az ml computetarget show command to check if the compute instance already exists before creating it.
You can refer to this sample - if ! az ml computetarget show --name $(amlcompute.instanceName) --resource-group $(azureml.resourceGroup) --workspace-name $(azureml.workspaceName) &> /dev/null; then az ml computetarget create computeinstance -g $(azureml.resourceGroup) -w $(azureml.workspaceName) -n $(amlcompute.instanceName) -s $(amlcompute.vmSize) fi
Regarding your second question, using a YAML file is generally considered a best practice for defining Azure resources, including compute instances. You can define your compute instance in a YAML file and use the az deployment group create command to deploy the YAML file. Here is an example:
az deployment group create --resource-group $(azureml.resourceGroup) --template-file compute-instance.yml --parameters instanceName=$(amlcompute.instanceName) vmSize=$(amlcompute.vmSize) In this example, compute-instance.yml is the YAML file that defines the compute instance, and instanceName and vmSize are the parameters that are passed to the YAML file.
I hope this helps.