Azure / Azure/azure-cli

Idempotency for `az network vnet create` command

Open
#15,892 5 comments 0 reactions 2 assignees Claimed by @kairu-ms View on GitHub
act-quality-productivity-squad feature-request Network
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

Given the following deployment script:

```
az network vnet create --resource-group "${prefix}-${project}-${postfix}" --location westeurope --name "${project}-vnet-${postfix}" --address-prefixes 10.0.0.0/16
az network vnet subnet create --resource-group "${prefix}-${project}-${postfix}" --vnet-name ${project}-vnet-${postfix} --name SubnetOne --address-prefixes 10.0.1.0/24 --delegations Microsoft.Web/serverFarms
az network vnet subnet create --resource-group "${prefix}-${project}-${postfix}" --vnet-name ${project}-vnet-${postfix} --name SubnetTwo --address-prefixes 10.0.2.0/24 --delegations Microsoft.Web/serverFarms
```

This breaks the 2nd time you run it - I suspect because the call to `az network vnet create` does not provide any subnet information and therefore tries to delete the subnets within the VNET - which it cannot do because of the delegation and VNET integration of some webapp. So therefore, my script is not idempotent.

I notice in my work, that a lot of the people I meet prefer using CLI over ARM templates - influenced by the case made [here](https://pascalnaber.wordpress.com/2018/11/11/stop-using-arm-templates-use-the-azure-cli-instead/) by Pascal where he states that most commands are idempotent. And that checks out in my experience - all the other stuff I do later in the script - storage accounts, function apps, etc. etc. - works fine. It only errors out on this line.

In case you're interested in making the CLI more idempotent - `az network vnet create` perhaps needs to be revisited. Making the parameters like [--subnet-name](https://docs.microsoft.com/en-us/cli/azure/network/vnet?view=azure-cli-latest#az_network_vnet_create) into an array is probably hard, because then you would have to accept arrays for all the other parameters as well. So maybe accepting JSON for the subnet configuration or something?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.