Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Linter rule to enforce consistent API version across codebase #14645

Open
abatishchev opened this issue Jul 23, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request Needs: Upvote This issue requires more votes to be considered story: linter rules

Comments

@abatishchev
Copy link

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

Currently, Bicep requires hard-coding the API version, i.e. specifying it explicitly next to each parent resource. It must be a literal string, it doesn't support a variable, e.g.:

resource cluster 'Microsoft.ServiceFabric/clusters@2021-06-01' existing = {
  // ...
}

This may easily lead to an inconsistency between API versions of the same resource type across different Bicep files. Moreover, nothing prevents using multiple API versions within the same file.

Note, this is not the case in regular ARM template: it supports using a variable/parameter, which may come from a single location:

{
  "name": "Common",
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "[variables('deploymentApiVersion')]",
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "[parameters('template_Common')]",
      "contentVersion": "1.0.0.0"
    }
  }
},
{
  "name": "Resource1",
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "[variables('deploymentApiVersion')]",
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "[parameters('template_Resource1')]",
      "contentVersion": "1.0.0.0"
    },
    "parameters": {
      "apiProfile": {
            "value": "[reference('Common').outputs.apiProfile.value]" // a source of truth for all API versions used across the codebase
          },
  },
  "dependsOn": [
    "[resourceId('Microsoft.Resources/deployments', 'Common')]"
  ]
}

Describe the solution you'd like

In the leu of a solution for #10683 and an improvement towards #622, I propose a linter rule which would:

  1. Either require an API version to be the same in all files in the folder (per resource type)
  2. Or enforce a certain API version to be used (again, per resource type)
@alex-frankel
Copy link
Collaborator

Somewhat related to #622

@stephaniezyen stephaniezyen added story: linter rules Needs: Upvote This issue requires more votes to be considered and removed Needs: Triage 🔍 labels Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Needs: Upvote This issue requires more votes to be considered story: linter rules
Projects
Status: Todo
Development

No branches or pull requests

4 participants