Azure / magic-module-specs

The magic module resource definitions for Azure.
MIT License
3 stars 9 forks source link

How to define custom "actions"? #21

Open zikalino opened 5 years ago

zikalino commented 5 years ago

Should api.yaml allow defining custom actions? They could be for example "start", "stop", "generalize", etc. They have different URL in REST API, for instance "…../virtualMachines/myVm/stop", and they have separate method in SDK as well. We should have schema for that so autorest.devops can generate api.yaml correctly.

JunyiYi commented 5 years ago

My design would be (considering this is Ansible-only and not a common pattern across all resources):

  1. do not define any custom operations here (user provides their customized API call in Python code in ansible.yaml).
  2. But in api.yaml, we need to define the status property of string enum containing something like Started, Stopped, etc. User would also provide their customized code snippet in ansible.yaml to link the enum value with the actual api call. (And for terraform.yaml, just ignore this property)

How do you think about that?

zikalino commented 5 years ago

If we do (1) it won't be automatic code generation, we will have to include the same custom code again and again for different azure resources. I think we should have proper operations defined, then we should have default handling for these, and if it doesn't work as we want we should create custom code.

JunyiYi commented 5 years ago

@zikalino Yes you are right. I do not plan to make it automatic for the following reasons:

  1. Terraform does not have this requirements.
  2. Not many resources need this behavior.

So why not for now let's using manual customization code snippet. If in the future we found there are so many similar patterns, we can generate those customization code snippets, instead of putting everything into api.yaml since terraform does not need it.

zikalino commented 5 years ago

@JunyiYi So we should resolve some basics, here are several unknowns:

I think this feature can be postponed a bit, maybe hurrying to do it now will result in something we will have to undo in the future.

@yungezz what do you think?

JunyiYi commented 5 years ago

@zikalino I agree we should carefully design the feature. My two cents are, if a feature is only supported in one specific product (no matter Terraform or Ansible), then it should not be put in api.yaml.

For now, maybe customization is the standard work-around to unblock the scenario? I think you can just make azure_sdk_references: [] an empty array, I will fix magic-modules to support that.