Azure / azure-cli

Azure Command-Line Interface
MIT License
4k stars 2.98k forks source link

Template support (like arm templates) #15852

Open bvduijn opened 3 years ago

bvduijn commented 3 years ago

Is your feature request related to a problem? Please describe. nope

Describe the solution you'd like When creating resources with az you can create each resource manually or via a powershell/bash script. ARM has templates, why not support an option like "az template "

Yaml could be formatted like this: (kinda like Ansible syntax)

---
vars:
  foo: "bar"
  number: 42

var_files:
  - ./vars/myvars.yml

resources:
  group:
    create:
    - name: "MyResourceGroup1"
      location: "westeurope"
    - name: "MyResourceGroup2"
      location: "westeurope"
      resource-type: "Microsoft.web/site"
  vm:
    create:
    - name: MyVm
      resource-group: "MyResourceGroup"
      public-ip-address: "" 
      image: "Win2012R2Datacenter"
      nic:
        - nic_name1 
        - nic_name2
      disk_attach:
        - name: "disk_{{ foo }}"
          new: true
          size-gb: {{ number }}
          sku: "Standard_LRS"

Describe alternatives you've considered You could use az deployment and use ARM templates and this could also be used in terraform or ansible. However when starting with ARM they can look quite daunting I think this yaml is more readable and cleaner.

You can also create a script for deployment. When creating a script you have to choose upfront if you want Bash or Powershell and they are not interoperable in the way variables are defined.

Additional context Other non-platform specific tools like terraform or ansible depend on azure cli or the azure cli python library. When new features are made available through ARM they first need to be incorporated in AZ and python libs. Only then those tools can incorporate those features into their platform before they are available to the users of those tools. This serial development takes time and often not all features are incorporated.

When those tools could offload commands to native tools like azure cli you cut some development time and use the full feature set azure cli offers @ansible-collections

yonzhan commented 3 years ago

ARM

bvduijn commented 3 years ago

@yonzhan . You mean ARM as a tag or in a sense that ARM should be used / provides this function already?

zhoxing-ms commented 3 years ago

@bvduijn Do you want to use yaml file to configure deployed resources instead of ARM template?

bvduijn commented 3 years ago

@zhoxing-ms Yes that's the idea. ARM templates can get quite Big for small things you want to do. You need to define your parameters, dependencies and referencing these is a syntax on its own. Like so :

"storageUri": "[concat('http://',variables('diagStorageAccountName'),'.blob.core.windows.net')]"

Very easy to overlook an ( of ] whereas with yaml with Jinja2 :

"storageUri": "http://"{{ diagStorageAccountName }}.blob.core.windows.net"

And dependencies could be defined just by identation

Az takes a lot of those troubles of working with ARM away and I understand it's implementation as a form of backward compatibility.

zhoxing-ms commented 3 years ago

I suggest that this new feature should be implemented by ARM service:

  1. The parsing and deployment of ARM template is implemented by ARM service, and the parsing and deployment of yaml file should be similar.
  2. If CLI parses yaml file, and then send some separate requests to REST to deploy resources, there will be complex issues of performance and cross RP collaboration. Therefore, it is not suitable to be implemented by CLI.
  3. If ARM service supports this feature, then multiple teminals (PowerShell, Terraform) can use this feature, not only CLI.

So it need the support from ARM service team.

ghost commented 3 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @armleads-azure.


Issue meta data

Issue content: **Is your feature request related to a problem? Please describe.** nope **Describe the solution you'd like** When creating resources with az you can create each resource manually or via a powershell/bash script. ARM has templates, why not support an option like "az template " Yaml could be formatted like this: (kinda like Ansible syntax) ```bash --- vars: foo: "bar" number: 42 var_files: - ./vars/myvars.yml resources: group: create: - name: "MyResourceGroup1" location: "westeurope" - name: "MyResourceGroup2" location: "westeurope" resource-type: "Microsoft.web/site" vm: create: - name: MyVm resource-group: "MyResourceGroup" public-ip-address: "" image: "Win2012R2Datacenter" nic: - nic_name1 - nic_name2 disk_attach: - name: "disk_{{ foo }}" new: true size-gb: {{ number }} sku: "Standard_LRS" ``` **Describe alternatives you've considered** You could use az deployment and use ARM templates and this could also be used in terraform or ansible. However when starting with ARM they can look quite daunting I think this yaml is more readable and cleaner. You can also create a script for deployment. When creating a script you have to choose upfront if you want Bash or Powershell and they are not interoperable in the way variables are defined. **Additional context** Other non-platform specific tools like terraform or ansible depend on azure cli or the azure cli python library. When new features are made available through ARM they first need to be incorporated in AZ and python libs. Only then those tools can incorporate those features into their platform before they are available to the users of those tools. This serial development takes time and often not all features are incorporated. When those tools could offload commands to native tools like azure cli you cut some development time and use the full feature set azure cli offers @ansible-collections
Issue author: bvduijn
Assignees: zhoxing-ms
Milestone: [object Object]