Azure/bicep

Bicep-generated files should include an autogenerated header

snarkywolverine opened this issue · 2 comments

When a resource file is created in visual studio, a programming language-specific file is autogenerated for resource access. At the top is a comment that looks something like this:

//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------

We should have something similar for bicep - a comment that says the file was autogenerated and the bicep version.

This discourages users from modifying the bicep file directly; it also (as @alex-frankel pointed out) allows the service to potentially collect telemetry on the # of deployments using compiled templates.

Discussed it at the team meeting today. The consensus appears to have template code generators use the top-level metadata property to store this information. This is the proposed schema:

"metadata": {
  "_generator": {
    "name": "<name of the code generator>",
    "version": "<version of the code generator>",
    "templateHash": "<template hash>"
  }
}

Considerations:

One thing that would be nice in the case of other generators is a way to add metadata around that generator's use, like a kind of user-agent string — for example with a PowerShell-based generator, the PowerShell version used. That would help us understand where to make investments/who to optimise our generator for.

Whether that is just the _generator.name or some other field(s)/object under _generator is something I'm certainly very flexible on.